private void BitVectorsOperationsTest32() { const int k_bit_count = Bits.kInt32BitCount; var lhs_bits = 0x4; // 0100b var lhs_bs = new BitVector32(lhs_bits); var rhs_bits = 0xA; // 1010b var rhs_bs = new BitVector32(rhs_bits); lhs_bs = lhs_bs.Or(rhs_bs); Assert.AreEqual(3, lhs_bs.Cardinality); Assert.AreEqual(k_bit_count - lhs_bs.Cardinality, lhs_bs.CardinalityZeros); Assert.AreEqual(lhs_bs[0], false); Assert.AreEqual(lhs_bs[1], true); Assert.AreEqual(lhs_bs[2], true); Assert.AreEqual(lhs_bs[3], true); // also undoes the OR operation lhs_bs = lhs_bs.AndNot(rhs_bs); Assert.AreEqual(1, lhs_bs.Cardinality); Assert.AreEqual(k_bit_count - lhs_bs.Cardinality, lhs_bs.CardinalityZeros); Assert.AreEqual(lhs_bs[0], false); Assert.AreEqual(lhs_bs[1], false); Assert.AreEqual(lhs_bs[2], true); Assert.AreEqual(lhs_bs[3], false); lhs_bs = lhs_bs.And(rhs_bs); Assert.AreEqual(0, lhs_bs.Cardinality); Assert.AreEqual(k_bit_count - lhs_bs.Cardinality, lhs_bs.CardinalityZeros); Assert.AreEqual(lhs_bs[0], false); Assert.AreEqual(lhs_bs[1], false); Assert.AreEqual(lhs_bs[2], false); Assert.AreEqual(lhs_bs[3], false); // at this point lhs is zero, and the only bit in rhs which is on (relative to lhs's bit-space) is the 2nd lhs_bs = lhs_bs.Xor(rhs_bs); Assert.AreEqual(2, lhs_bs.Cardinality); Assert.AreEqual(k_bit_count - lhs_bs.Cardinality, lhs_bs.CardinalityZeros); Assert.AreEqual(lhs_bs[0], false); Assert.AreEqual(lhs_bs[1], true); Assert.AreEqual(lhs_bs[2], false); Assert.AreEqual(lhs_bs[3], true); lhs_bs = lhs_bs.Not(); Assert.AreEqual(k_bit_count - 2, lhs_bs.Cardinality); Assert.AreEqual(k_bit_count - lhs_bs.Cardinality, lhs_bs.CardinalityZeros); Assert.AreEqual(lhs_bs[0], true); Assert.AreEqual(lhs_bs[1], false); Assert.AreEqual(lhs_bs[2], true); Assert.AreEqual(lhs_bs[3], false); }