multi_ut.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "multi.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/stream/output.h>
  4. class TMultiHashTest: public TTestBase {
  5. UNIT_TEST_SUITE(TMultiHashTest);
  6. UNIT_TEST(TestStrInt)
  7. UNIT_TEST(TestIntStr)
  8. UNIT_TEST(TestSimpleCollision)
  9. UNIT_TEST(TestTypes)
  10. UNIT_TEST_SUITE_END();
  11. private:
  12. inline void TestStrInt() {
  13. UNIT_ASSERT_EQUAL(MultiHash(TString("1234567"), static_cast<int>(123)), static_cast<size_t>(ULL(17038203285960021630)));
  14. }
  15. inline void TestIntStr() {
  16. UNIT_ASSERT_EQUAL(MultiHash(static_cast<int>(123), TString("1234567")), static_cast<size_t>(ULL(9973288649881090712)));
  17. }
  18. inline void TestSimpleCollision() {
  19. UNIT_ASSERT_UNEQUAL(MultiHash(1, 1, 0), MultiHash(2, 2, 0));
  20. }
  21. inline void TestTypes() {
  22. UNIT_ASSERT_EQUAL(MultiHash("aaa", (ui64)123), MultiHash("aaa", 123));
  23. UNIT_ASSERT_EQUAL(MultiHash("aaa", (i64)123), MultiHash("aaa", 123));
  24. UNIT_ASSERT_EQUAL(MultiHash("aaa", (i32)123), MultiHash("aaa", 123));
  25. UNIT_ASSERT_EQUAL(MultiHash("aaa", (ui32)123), MultiHash("aaa", 123));
  26. UNIT_ASSERT_EQUAL(MultiHash("aaa", (i64)-123), MultiHash("aaa", -123));
  27. UNIT_ASSERT_EQUAL(MultiHash("aaa", (i32)-123), MultiHash("aaa", -123));
  28. }
  29. };
  30. UNIT_TEST_SUITE_REGISTRATION(TMultiHashTest);