Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 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 | |
| 25 | TEST(HashTests, Basic) { |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 26 | EXPECT_EQ(Hash(123), Hash(123)); |
Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 27 | EXPECT_NE(Hash(123), Hash(321)); |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 28 | EXPECT_EQ(Hash(123, 456), Hash(123, 456)); |
| 29 | EXPECT_NE(Hash(123, 456), Hash(456, 123)); |
Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 30 | EXPECT_NE(Hash(123, 456), Hash(123)); |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 31 | EXPECT_EQ(Hash(123, 456, false), Hash(123, 456, false)); |
Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 32 | EXPECT_NE(Hash(123, 456, false), Hash(123, 456)); |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 33 | EXPECT_EQ(Hash(std::string("hello")), Hash(std::string("hello"))); |
Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 34 | EXPECT_NE(Hash(std::string("hello")), Hash(std::string("world"))); |
| 35 | } |
| 36 | |
Ben Clayton | b478f97 | 2021-07-15 20:34:21 +0000 | [diff] [blame] | 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}))); |
Ben Clayton | 01ac3dd | 2021-03-29 15:13:55 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } // namespace |
| 48 | } // namespace utils |
| 49 | } // namespace tint |