You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. #include "gtest/gtest.h"
  2. #include <cstdint>
  3. #include "src/storage/BitVector.h"
  4. #include "src/storage/BitVectorHashMap.h"
  5. TEST(BitVectorHashMapTest, FindOrAdd) {
  6. storm::storage::BitVectorHashMap<uint64_t> map(64, 3);
  7. storm::storage::BitVector first(64);
  8. first.set(4);
  9. first.set(47);
  10. ASSERT_NO_THROW(map.findOrAdd(first, 1));
  11. storm::storage::BitVector second(64);
  12. second.set(8);
  13. second.set(18);
  14. ASSERT_NO_THROW(map.findOrAdd(second, 2));
  15. EXPECT_EQ(1ul, map.findOrAdd(first, 3));
  16. EXPECT_EQ(2ul, map.findOrAdd(second, 3));
  17. storm::storage::BitVector third(64);
  18. third.set(10);
  19. third.set(63);
  20. ASSERT_NO_THROW(map.findOrAdd(third, 3));
  21. EXPECT_EQ(1ul, map.findOrAdd(first, 2));
  22. EXPECT_EQ(2ul, map.findOrAdd(second, 1));
  23. EXPECT_EQ(3ul, map.findOrAdd(third, 1));
  24. storm::storage::BitVector fourth(64);
  25. fourth.set(12);
  26. fourth.set(14);
  27. ASSERT_NO_THROW(map.findOrAdd(fourth, 4));
  28. EXPECT_EQ(1ul, map.findOrAdd(first, 2));
  29. EXPECT_EQ(2ul, map.findOrAdd(second, 1));
  30. EXPECT_EQ(3ul, map.findOrAdd(third, 1));
  31. EXPECT_EQ(4ul, map.findOrAdd(fourth, 1));
  32. storm::storage::BitVector fifth(64);
  33. fifth.set(44);
  34. fifth.set(55);
  35. ASSERT_NO_THROW(map.findOrAdd(fifth, 5));
  36. EXPECT_EQ(1ul, map.findOrAdd(first, 2));
  37. EXPECT_EQ(2ul, map.findOrAdd(second, 1));
  38. EXPECT_EQ(3ul, map.findOrAdd(third, 1));
  39. EXPECT_EQ(4ul, map.findOrAdd(fourth, 1));
  40. EXPECT_EQ(5ul, map.findOrAdd(fifth, 1));
  41. storm::storage::BitVector sixth(64);
  42. sixth.set(45);
  43. sixth.set(55);
  44. ASSERT_NO_THROW(map.findOrAdd(sixth, 6));
  45. EXPECT_EQ(1ul, map.findOrAdd(first, 0));
  46. EXPECT_EQ(2ul, map.findOrAdd(second, 0));
  47. EXPECT_EQ(3ul, map.findOrAdd(third, 0));
  48. EXPECT_EQ(4ul, map.findOrAdd(fourth, 0));
  49. EXPECT_EQ(5ul, map.findOrAdd(fifth, 0));
  50. EXPECT_EQ(6ul, map.findOrAdd(sixth, 0));
  51. }