comparison unittests/ADT/DenseSetTest.cpp @ 147:c2174574ed3a

LLVM 10
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 16:55:33 +0900
parents 3a76565eade5
children
comparison
equal deleted inserted replaced
134:3a76565eade5 147:c2174574ed3a
1 //===- llvm/unittest/ADT/DenseSetTest.cpp - DenseSet unit tests --*- C++ -*-===// 1 //===- llvm/unittest/ADT/DenseSetTest.cpp - DenseSet unit tests --*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 8
10 #include "llvm/ADT/DenseSet.h" 9 #include "llvm/ADT/DenseSet.h"
11 #include "gtest/gtest.h" 10 #include "gtest/gtest.h"
12 #include <type_traits> 11 #include <type_traits>
13 12
14 using namespace llvm; 13 using namespace llvm;
15 14
16 namespace { 15 namespace {
16
17 static_assert(std::is_const<std::remove_pointer<
18 DenseSet<int>::const_iterator::pointer>::type>::value,
19 "Iterator pointer type should be const");
20 static_assert(std::is_const<std::remove_reference<
21 DenseSet<int>::const_iterator::reference>::type>::value,
22 "Iterator reference type should be const");
17 23
18 // Test hashing with a set of only two entries. 24 // Test hashing with a set of only two entries.
19 TEST(DenseSetTest, DoubleEntrySetTest) { 25 TEST(DenseSetTest, DoubleEntrySetTest) {
20 llvm::DenseSet<unsigned> set(2); 26 llvm::DenseSet<unsigned> set(2);
21 set.insert(0); 27 set.insert(0);
71 EXPECT_EQ(1u, set.count(2)); 77 EXPECT_EQ(1u, set.count(2));
72 EXPECT_EQ(1u, set.count(4)); 78 EXPECT_EQ(1u, set.count(4));
73 EXPECT_EQ(0u, set.count(3)); 79 EXPECT_EQ(0u, set.count(3));
74 } 80 }
75 81
82 TYPED_TEST(DenseSetTest, InitializerListWithNonPowerOfTwoLength) {
83 TypeParam set({1, 2, 3});
84 EXPECT_EQ(3u, set.size());
85 EXPECT_EQ(1u, set.count(1));
86 EXPECT_EQ(1u, set.count(2));
87 EXPECT_EQ(1u, set.count(3));
88 }
89
76 TYPED_TEST(DenseSetTest, ConstIteratorComparison) { 90 TYPED_TEST(DenseSetTest, ConstIteratorComparison) {
77 TypeParam set({1}); 91 TypeParam set({1});
78 const TypeParam &cset = set; 92 const TypeParam &cset = set;
79 EXPECT_EQ(set.begin(), cset.begin()); 93 EXPECT_EQ(set.begin(), cset.begin());
80 EXPECT_EQ(set.end(), cset.end()); 94 EXPECT_EQ(set.end(), cset.end());
110 // find_as() tests 124 // find_as() tests
111 EXPECT_EQ(0u, *set.find_as("a")); 125 EXPECT_EQ(0u, *set.find_as("a"));
112 EXPECT_EQ(1u, *set.find_as("b")); 126 EXPECT_EQ(1u, *set.find_as("b"));
113 EXPECT_EQ(2u, *set.find_as("c")); 127 EXPECT_EQ(2u, *set.find_as("c"));
114 EXPECT_TRUE(set.find_as("d") == set.end()); 128 EXPECT_TRUE(set.find_as("d") == set.end());
129 }
130
131 TYPED_TEST(DenseSetTest, EqualityComparisonTest) {
132 TypeParam set1({1, 2, 3, 4});
133 TypeParam set2({4, 3, 2, 1});
134 TypeParam set3({2, 3, 4, 5});
135
136 EXPECT_EQ(set1, set2);
137 EXPECT_NE(set1, set3);
115 } 138 }
116 139
117 // Simple class that counts how many moves and copy happens when growing a map 140 // Simple class that counts how many moves and copy happens when growing a map
118 struct CountCopyAndMove { 141 struct CountCopyAndMove {
119 static int Move; 142 static int Move;