BitSet.cpp 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <tests/framework/Framework.h>
  6. #include <anki/util/BitSet.h>
  7. ANKI_TEST(Util, BitSet)
  8. {
  9. {
  10. BitSet<4, U8> a = {false};
  11. ANKI_TEST_EXPECT_EQ(a.get(3), false);
  12. a.set(3);
  13. ANKI_TEST_EXPECT_EQ(a.get(3), true);
  14. }
  15. {
  16. BitSet<9, U8> a = {true};
  17. ANKI_TEST_EXPECT_EQ(a.get(8), true);
  18. a.set(8, false);
  19. ANKI_TEST_EXPECT_EQ(a.get(8), false);
  20. }
  21. {
  22. BitSet<4, U64> a = {true};
  23. ANKI_TEST_EXPECT_EQ(a.get(3), true);
  24. a.set(3, false);
  25. ANKI_TEST_EXPECT_EQ(a.get(3), false);
  26. }
  27. {
  28. const U N = 120;
  29. BitSet<N, U64> a = {false};
  30. for(U i = 0; i < 1000; ++i)
  31. {
  32. U r = rand() % N;
  33. ANKI_TEST_EXPECT_EQ(a.get(r), false);
  34. a.set(r, true);
  35. ANKI_TEST_EXPECT_EQ(a.get(r), true);
  36. for(U n = 0; n < N; ++n)
  37. {
  38. if(n != r)
  39. {
  40. ANKI_TEST_EXPECT_EQ(a.get(n), false);
  41. }
  42. }
  43. a.set(r, false);
  44. }
  45. }
  46. }