diff options
author | Aina Niemetz <aina.niemetz@gmail.com> | 2020-09-30 17:26:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 17:26:46 -0700 |
commit | d7f92f70bb8ff221dc3d7cb086e5e2e237dadc67 (patch) | |
tree | 26916ced6f98142dd9dc04c454ff6d0c8161a8d6 /test/unit/util/bitvector_black.h | |
parent | aa65c60968d0b8c0a7cd47adb2e9e1a684c0332a (diff) |
BitVector: Extend interface of setBit to set it to a specific value. (#5173)
Previously, BitVector::setBit only allowed to set the bit at the given
index to 1. This changes its behavior to be also able to set it to 0.
Diffstat (limited to 'test/unit/util/bitvector_black.h')
-rw-r--r-- | test/unit/util/bitvector_black.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/test/unit/util/bitvector_black.h b/test/unit/util/bitvector_black.h index 7fba53adc..5b6eecc5f 100644 --- a/test/unit/util/bitvector_black.h +++ b/test/unit/util/bitvector_black.h @@ -29,9 +29,10 @@ public: void setUp() override { zero = BitVector(4); - one = zero.setBit(0); + one = zero.setBit(0, true); two = BitVector("0010", 2); negOne = BitVector(4, Integer(-1)); + ones = BitVector::mkOnes(4); } void testStringConstructor() @@ -76,16 +77,22 @@ public: void testSetGetBit() { - TS_ASSERT_EQUALS(one.setBit(1).setBit(2).setBit(3), negOne); - - TS_ASSERT(negOne.isBitSet(3)); + TS_ASSERT_EQUALS(one.setBit(1, true).setBit(2, true).setBit(3, true), ones); + TS_ASSERT_EQUALS( + ones.setBit(0, false).setBit(1, false).setBit(2, false).setBit(3, + false), + zero); + TS_ASSERT_EQUALS(ones.setBit(0, false).setBit(0, true), ones); + TS_ASSERT_EQUALS(ones.setBit(0, false), ~BitVector::mkOne(one.getSize())); + + TS_ASSERT(ones.isBitSet(3)); TS_ASSERT(!two.isBitSet(3)); TS_ASSERT_EQUALS(one.getValue(), Integer(1)); TS_ASSERT_EQUALS(zero.isPow2(), 0); TS_ASSERT_EQUALS(one.isPow2(), 1); TS_ASSERT_EQUALS(two.isPow2(), 2); - TS_ASSERT_EQUALS(negOne.isPow2(), 0); + TS_ASSERT_EQUALS(ones.isPow2(), 0); } void testConcatExtract() @@ -177,6 +184,8 @@ public: void testStaticHelpers() { + TS_ASSERT_EQUALS(BitVector::mkZero(4), zero); + TS_ASSERT_EQUALS(BitVector::mkOne(4), one); TS_ASSERT_EQUALS(BitVector::mkOnes(4), negOne); TS_ASSERT_EQUALS(BitVector::mkMinSigned(4).toSignedInteger(), Integer(-8)); TS_ASSERT_EQUALS(BitVector::mkMaxSigned(4).toSignedInteger(), Integer(7)); @@ -187,4 +196,5 @@ public: BitVector one; BitVector two; BitVector negOne; + BitVector ones; }; |