blob: e86c8a858661b36a2afb1de5b3bea183308086f4 [file] [log] [blame]
Victor Boivie553fd322021-04-26 15:25:06 +02001/*
2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#include "rtc_base/hash.h"
11
12#include <string>
13#include <unordered_map>
14#include <unordered_set>
15
16#include "test/gmock.h"
17
18namespace webrtc {
19namespace {
20
21TEST(PairHashTest, CanInsertIntoSet) {
22 using MyPair = std::pair<int, int>;
23
24 std::unordered_set<MyPair, PairHash> pairs;
25
26 pairs.insert({1, 2});
27 pairs.insert({3, 4});
28
29 EXPECT_NE(pairs.find({1, 2}), pairs.end());
30 EXPECT_NE(pairs.find({3, 4}), pairs.end());
31 EXPECT_EQ(pairs.find({1, 3}), pairs.end());
32 EXPECT_EQ(pairs.find({3, 3}), pairs.end());
33}
34
35TEST(PairHashTest, CanInsertIntoMap) {
36 using MyPair = std::pair<std::string, int>;
37
38 std::unordered_map<MyPair, int, PairHash> pairs;
39
40 pairs[{"1", 2}] = 99;
41 pairs[{"3", 4}] = 100;
42
43 EXPECT_EQ((pairs[{"1", 2}]), 99);
44 EXPECT_EQ((pairs[{"3", 4}]), 100);
45 EXPECT_EQ(pairs.find({"1", 3}), pairs.end());
46 EXPECT_EQ(pairs.find({"3", 3}), pairs.end());
47}
48} // namespace
49} // namespace webrtc