bits_test.hxx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef BITS_TEST_H
  2. #define BITS_TEST_H
  3. #include "tester.hxx"
  4. #include "libbinom/include/variables/bit_array.hxx"
  5. #include <assert.h>
  6. #include <array>
  7. void printBist(const binom::BitArray& bit_array) {
  8. LOG("Print bits:");
  9. size_t counter = 0;
  10. for(auto bit : bit_array)
  11. LOG(counter++ << " - " << bit);
  12. }
  13. void testBits() {
  14. RAIIPerfomanceTest test_perf("Bits test: ");
  15. SEPARATOR
  16. using namespace binom;
  17. using namespace binom::priv;
  18. TEST_ANNOUNCE(Test Bits & Bits value);
  19. GRP(
  20. PRINT_RUN(Bits bits;);
  21. PRINT_RUN(Bits::ValueRef bit_first = bits[0];);
  22. PRINT_RUN(Bits::ValueRef bit_last = bits[7];);
  23. LOG("bit_first: " << bit_first << "; bit_last: " << bit_last);
  24. LOG("bit_first == bit_last: " << (bit_first == bit_last));
  25. PRINT_RUN(bit_first = true;);
  26. LOG("bit_first: " << bit_first << "; bit_last: " << bit_last);
  27. LOG("bit_first == bit_last: " << (bit_first == bit_last));
  28. PRINT_RUN(bit_last = bit_first;);
  29. LOG("bit_first: " << bit_first << "; bit_last: " << bit_last);
  30. LOG("bit_first == bit_last: " << (bit_first == bit_last));
  31. );
  32. TEST_ANNOUNCE(Test BitArray);
  33. GRP(
  34. PRINT_RUN(BitArray test);
  35. printBist(test);
  36. PRINT_RUN(test.pushBack({1,0,1}));
  37. printBist(test);
  38. PRINT_RUN(test.pushFront({1,0,1}));
  39. printBist(test);
  40. PRINT_RUN(test.insert(3, {0,1,0}));
  41. printBist(test);
  42. PRINT_RUN(test.insert(3, {1,0,0,1,1,0,0,1,1,0,0,1,1,0}));
  43. printBist(test);
  44. PRINT_RUN(test.remove(3, 14));
  45. printBist(test);
  46. PRINT_RUN(test.remove(3, 3));
  47. printBist(test);
  48. PRINT_RUN(test.popFront(3));
  49. printBist(test);
  50. PRINT_RUN(test.popBack(3));
  51. printBist(test);
  52. );
  53. }
  54. #endif // BITS_TEST_H