1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/utils/hash.h"
16
17 #include <string>
18
19 #include "gtest/gtest.h"
20
21 namespace tint {
22 namespace utils {
23 namespace {
24
TEST(HashTests,Basic)25 TEST(HashTests, Basic) {
26 EXPECT_EQ(Hash(123), Hash(123));
27 EXPECT_NE(Hash(123), Hash(321));
28 EXPECT_EQ(Hash(123, 456), Hash(123, 456));
29 EXPECT_NE(Hash(123, 456), Hash(456, 123));
30 EXPECT_NE(Hash(123, 456), Hash(123));
31 EXPECT_EQ(Hash(123, 456, false), Hash(123, 456, false));
32 EXPECT_NE(Hash(123, 456, false), Hash(123, 456));
33 EXPECT_EQ(Hash(std::string("hello")), Hash(std::string("hello")));
34 EXPECT_NE(Hash(std::string("hello")), Hash(std::string("world")));
35 }
36
TEST(HashTests,Vector)37 TEST(HashTests, Vector) {
38 EXPECT_EQ(Hash(std::vector<int>({})), Hash(std::vector<int>({})));
39 EXPECT_EQ(Hash(std::vector<int>({1, 2, 3})),
40 Hash(std::vector<int>({1, 2, 3})));
41 EXPECT_NE(Hash(std::vector<int>({1, 2, 3})),
42 Hash(std::vector<int>({1, 2, 4})));
43 EXPECT_NE(Hash(std::vector<int>({1, 2, 3})),
44 Hash(std::vector<int>({1, 2, 3, 4})));
45 }
46
47 } // namespace
48 } // namespace utils
49 } // namespace tint
50