sequence_ut.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "sequence.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/generic/map.h>
  4. #include <util/generic/vector.h>
  5. class TRangeHashTest: public TTestBase {
  6. UNIT_TEST_SUITE(TRangeHashTest);
  7. UNIT_TEST(TestStrokaInt)
  8. UNIT_TEST(TestIntVector)
  9. UNIT_TEST(TestOneElement)
  10. UNIT_TEST(TestMap);
  11. UNIT_TEST(TestCollectionIndependancy);
  12. UNIT_TEST_SUITE_END();
  13. private:
  14. inline void TestStrokaInt() {
  15. const size_t canonicalHash = static_cast<size_t>(ULL(12727184940294366172));
  16. UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(TString("12345")));
  17. }
  18. inline void TestIntVector() {
  19. const size_t canonicalHash = static_cast<size_t>(ULL(1351128487744230578));
  20. TVector<int> testVec = {1, 2, 4, 3};
  21. UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testVec));
  22. }
  23. inline void TestOneElement() {
  24. const int testVal = 42;
  25. TVector<int> testVec = {testVal};
  26. UNIT_ASSERT_UNEQUAL(THash<int>()(testVal), TRangeHash<>()(testVec));
  27. }
  28. inline void TestMap() {
  29. const size_t canonicalHash = static_cast<size_t>(ULL(4415387926488545605));
  30. TMap<TString, int> testMap{{"foo", 123}, {"bar", 456}};
  31. UNIT_ASSERT_EQUAL(canonicalHash, TRangeHash<>()(testMap));
  32. }
  33. inline void TestCollectionIndependancy() {
  34. TVector<char> testVec = {'a', 'b', 'c'};
  35. TString testStroka = "abc";
  36. UNIT_ASSERT_EQUAL(TRangeHash<>()(testVec), TRangeHash<>()(testStroka));
  37. }
  38. };
  39. class TSequenceHashTest: public TTestBase {
  40. UNIT_TEST_SUITE(TSequenceHashTest);
  41. UNIT_TEST(TestSimpleBuffer)
  42. UNIT_TEST_SUITE_END();
  43. private:
  44. inline void TestSimpleBuffer() {
  45. int arr[] = {1, 2, 3};
  46. const size_t canonicalHash = static_cast<size_t>(ULL(3903918011533391876));
  47. TContiguousHash<TSimpleRangeHash> hasher;
  48. UNIT_ASSERT_EQUAL(canonicalHash, hasher(TArrayRef<int>(arr, arr + 3)));
  49. }
  50. };
  51. UNIT_TEST_SUITE_REGISTRATION(TRangeHashTest);
  52. UNIT_TEST_SUITE_REGISTRATION(TSequenceHashTest);