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