turbonss/cxxmph/mph_bits_test.cc

62 lines
1.7 KiB
C++
Raw Normal View History

2012-03-14 21:44:16 +02:00
#include <cstdio>
#include <cstdlib>
#include "mph_bits.h"
using cxxmph::dynamic_2bitset;
2012-04-15 06:03:00 +03:00
using cxxmph::nextpoweroftwo;
2012-03-21 15:20:30 +02:00
2012-03-14 21:44:16 +02:00
int main(int argc, char** argv) {
2012-03-14 23:26:26 +02:00
dynamic_2bitset small(256, true);
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < small.size(); ++i) small.set(i, i % 4);
for (uint32_t i = 0; i < small.size(); ++i) {
2012-03-14 23:26:26 +02:00
if (small[i] != i % 4) {
fprintf(stderr, "wrong bits %d at %d expected %d\n", small[i], i, i % 4);
exit(-1);
}
}
2012-04-15 06:03:00 +03:00
uint32_t size = 256;
2012-03-14 21:44:16 +02:00
dynamic_2bitset bits(size, true /* fill with ones */);
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < size; ++i) {
2012-03-14 21:44:16 +02:00
if (bits[i] != 3) {
fprintf(stderr, "wrong bits %d at %d expected %d\n", bits[i], i, 3);
exit(-1);
}
}
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < size; ++i) bits.set(i, 0);
for (uint32_t i = 0; i < size; ++i) {
2012-03-14 21:44:16 +02:00
if (bits[i] != 0) {
fprintf(stderr, "wrong bits %d at %d expected %d\n", bits[i], i, 0);
exit(-1);
}
}
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < size; ++i) bits.set(i, i % 4);
for (uint32_t i = 0; i < size; ++i) {
2012-03-14 21:44:16 +02:00
if (bits[i] != i % 4) {
fprintf(stderr, "wrong bits %d at %d expected %d\n", bits[i], i, i % 4);
exit(-1);
}
}
2012-03-14 23:26:26 +02:00
dynamic_2bitset size_corner1(1);
if (size_corner1.size() != 1) exit(-1);
dynamic_2bitset size_corner2(2);
if (size_corner2.size() != 2) exit(-1);
(dynamic_2bitset(4, true)).swap(size_corner2);
2012-03-14 23:26:26 +02:00
if (size_corner2.size() != 4) exit(-1);
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < size_corner2.size(); ++i) {
if (size_corner2[i] != 3) exit(-1);
}
size_corner2.clear();
if (size_corner2.size() != 0) exit(-1);
2012-03-14 23:26:26 +02:00
dynamic_2bitset empty;
empty.clear();
dynamic_2bitset large(1000, true);
empty.swap(large);
2012-04-15 06:03:00 +03:00
if (nextpoweroftwo(3) != 4) exit(-1);
2012-03-14 21:44:16 +02:00
}