blob: dd0877dad4abf1651846e0cf15cbb12d35a044d0 [file] [log] [blame]
Ben Clayton01ac3dd2021-03-29 15:13:55 +00001// 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
21namespace tint {
22namespace utils {
23namespace {
24
25TEST(HashTests, Basic) {
Ben Claytonb478f972021-07-15 20:34:21 +000026 EXPECT_EQ(Hash(123), Hash(123));
Ben Clayton01ac3dd2021-03-29 15:13:55 +000027 EXPECT_NE(Hash(123), Hash(321));
Ben Claytonb478f972021-07-15 20:34:21 +000028 EXPECT_EQ(Hash(123, 456), Hash(123, 456));
29 EXPECT_NE(Hash(123, 456), Hash(456, 123));
Ben Clayton01ac3dd2021-03-29 15:13:55 +000030 EXPECT_NE(Hash(123, 456), Hash(123));
Ben Claytonb478f972021-07-15 20:34:21 +000031 EXPECT_EQ(Hash(123, 456, false), Hash(123, 456, false));
Ben Clayton01ac3dd2021-03-29 15:13:55 +000032 EXPECT_NE(Hash(123, 456, false), Hash(123, 456));
Ben Claytonb478f972021-07-15 20:34:21 +000033 EXPECT_EQ(Hash(std::string("hello")), Hash(std::string("hello")));
Ben Clayton01ac3dd2021-03-29 15:13:55 +000034 EXPECT_NE(Hash(std::string("hello")), Hash(std::string("world")));
35}
36
Ben Claytonb478f972021-07-15 20:34:21 +000037TEST(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 Clayton01ac3dd2021-03-29 15:13:55 +000045}
46
47} // namespace
48} // namespace utils
49} // namespace tint