multi_map_test.hxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef MULTI_MAP_TEST_HXX
  2. #define MULTI_MAP_TEST_HXX
  3. #include "tester.hxx"
  4. #include "libbinom/include/variables/multi_map.hxx"
  5. #include "print_variable.hxx"
  6. template <class IteratorType>
  7. struct IteratorRange : public std::pair<IteratorType, IteratorType> {
  8. IteratorType begin() {return self.first;}
  9. IteratorType end() {return self.second;}
  10. };
  11. void testMultiMap() {
  12. using namespace binom::literals;
  13. using namespace binom;
  14. RAIIPerfomanceTest test_perf("MultiMap test: ");
  15. SEPARATOR
  16. TEST_ANNOUNCE(MultiMap test)
  17. GRP_PUSH
  18. LOG("(bug in [r]): binom::Map _map = map{{2, 1},{2, 2},{2, 3},{1, 1},{1, 2},{1, 3}, {\"Hello\", \"World\"}, {\"Hello\", \"Someone\"}};");
  19. binom::MultiMap _map = multimap{{2, 1},{2, 2},{2, 3},{1, 1},{1, 2},{1, 3}, {"Hello", "World"}, {"Hello", "Someone"}};
  20. utils::printVariable(_map);
  21. SEPARATOR
  22. utils::printVariable(_map.move());
  23. PRINT_RUN(_map.insert(0, 1);)
  24. PRINT_RUN(_map.insert(0, 2);)
  25. PRINT_RUN(_map.insert(0, 3);)
  26. utils::printVariable(_map.move());
  27. IteratorRange<MultiMap::Iterator> range{_map.getRange(2)};
  28. PRINT_RUN(_map.removeAll(1);)
  29. utils::printVariable(_map.move());
  30. LOG("2 Key values iterating:");
  31. for(auto named_variable : IteratorRange<MultiMap::Iterator>{_map.getRange(2)}) {
  32. LOG("Key:" << i32(named_variable.getKey().toNumber()) << "; Value:" << i32(named_variable.getValue().toNumber()));
  33. }
  34. LOG("0 Key values iterating:");
  35. for(auto named_variable : IteratorRange<MultiMap::Iterator>{_map.getRange(0)}) {
  36. LOG("Key:" << i32(named_variable.getKey().toNumber()) << "; Value:" << i32(named_variable.getValue().toNumber()));
  37. }
  38. LOG("1 Key values iterating:");
  39. for(auto named_variable : IteratorRange<MultiMap::Iterator>{_map.getRange(1)}) {
  40. LOG("Key:" << i32(named_variable.getKey().toNumber()) << "; Value:" << i32(named_variable.getValue().toNumber()));
  41. }
  42. TEST(_map[1] == _map.cend())
  43. PRINT_RUN(_map.remove(++_map[2]);)
  44. utils::printVariable(_map.move());
  45. PRINT_RUN(_map.clear();)
  46. utils::printVariable(_map.move());
  47. GRP_POP
  48. }
  49. #endif // MULTI_MAP_TEST_HXX