legacy_hash_unittest.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/hash/legacy_hash.h"
  5. #include <stdint.h>
  6. #include "base/strings/string_piece.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. namespace base {
  9. namespace legacy {
  10. TEST(LegacyHashTest, CityHashV103) {
  11. constexpr struct {
  12. StringPiece input;
  13. uint64_t output;
  14. uint64_t output_with_seed;
  15. } kTestCases[] = {
  16. {"", 11160318154034397263ull, 14404538258149959151ull},
  17. {"0123456789", 12631666426400459317ull, 12757304017804637665ull},
  18. {"hello world", 12386028635079221413ull, 4144044770257928618ull},
  19. };
  20. for (const auto& test_case : kTestCases) {
  21. SCOPED_TRACE(test_case.input);
  22. auto bytes = as_bytes(make_span(test_case.input));
  23. EXPECT_EQ(test_case.output, CityHash64(bytes));
  24. }
  25. for (const auto& test_case : kTestCases) {
  26. SCOPED_TRACE(test_case.input);
  27. auto bytes = as_bytes(make_span(test_case.input));
  28. EXPECT_EQ(test_case.output_with_seed, CityHash64WithSeed(bytes, 112358));
  29. }
  30. }
  31. } // namespace legacy
  32. } // namespace base