| 150 | } |
| 151 | |
| 152 | void bitset_test::test_operations() |
| 153 | { |
| 154 | std::bitset<8> b1{}; |
| 155 | |
| 156 | b1.set(3); |
| 157 | test_eq("set", b1[3], true); |
| 158 | |
| 159 | b1.reset(3); |
| 160 | test_eq("reset", b1[3], false); |
| 161 | |
| 162 | b1.flip(3); |
| 163 | test_eq("flip", b1[3], true); |
| 164 | |
| 165 | b1 >>= 1; |
| 166 | test_eq("lshift new", b1[2], true); |
| 167 | test_eq("lshift old", b1[3], false); |
| 168 | |
| 169 | b1 <<= 1; |
| 170 | test_eq("rshift new", b1[2], false); |
| 171 | test_eq("rshift old", b1[3], true); |
| 172 | |
| 173 | test_eq("any1", b1.any(), true); |
| 174 | test_eq("none1", b1.none(), false); |
| 175 | test_eq("all1", b1.all(), false); |
| 176 | |
| 177 | /* b1 <<= 7; */ |
| 178 | /* test_eq("any2", b1.any(), false); */ |
| 179 | /* test_eq("none2", b1.none(), true); */ |
| 180 | /* test_eq("all2", b1.all(), false); */ |
| 181 | |
| 182 | b1.set(); |
| 183 | test_eq("set + all", b1.all(), true); |
| 184 | |
| 185 | b1.reset(); |
| 186 | test_eq("reset + none", b1.none(), true); |
| 187 | |
| 188 | std::bitset<8> b2{0b0101'0101}; |
| 189 | std::bitset<8> b3{0b1010'1010}; |
| 190 | b2.flip(); |
| 191 | test_eq("flip all", b2, b3); |
| 192 | |
| 193 | std::bitset<8> b4{0b0011'0101}; |
| 194 | std::bitset<8> b5{0b1010'1100}; |
| 195 | test_eq("and", (b4 & b5), std::bitset<8>{0b0010'0100}); |
| 196 | test_eq("or", (b4 | b5), std::bitset<8>{0b1011'1101}); |
| 197 | test_eq("count", b4.count(), 4U); |
| 198 | } |
| 199 | } |