llvm.org GIT mirror llvm / 658c628
Fix a typo that made ImmutableMap::getMaxElement() useless. Add a basic unit test for ImmutableMap. Found by inspection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165907 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
2 changed file(s) with 51 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
8888 ImutAVLTree* getMaxElement() {
8989 ImutAVLTree *T = this;
9090 ImutAVLTree *Right = T->getRight();
91 while (Right) { T = right; right = T->getRight(); }
91 while (Right) { T = Right; Right = T->getRight(); }
9292 return T;
9393 }
9494
0 //===----------- ImmutableMapTest.cpp - ImmutableMap unit tests ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "gtest/gtest.h"
10 #include "llvm/ADT/ImmutableMap.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 TEST(ImmutableMapTest, EmptyIntMapTest) {
17 ImmutableMap::Factory f;
18
19 EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap());
20 EXPECT_FALSE(f.getEmptyMap() != f.getEmptyMap());
21 EXPECT_TRUE(f.getEmptyMap().isEmpty());
22
23 ImmutableMap S = f.getEmptyMap();
24 EXPECT_EQ(0u, S.getHeight());
25 EXPECT_TRUE(S.begin() == S.end());
26 EXPECT_FALSE(S.begin() != S.end());
27 }
28
29 TEST(ImmutableMapTest, MultiElemIntMapTest) {
30 ImmutableMap::Factory f;
31 ImmutableMap S = f.getEmptyMap();
32
33 ImmutableMap S2 = f.add(f.add(f.add(S, 3, 10), 4, 11), 5, 12);
34
35 EXPECT_TRUE(S.isEmpty());
36 EXPECT_FALSE(S2.isEmpty());
37
38 EXPECT_EQ(0, S.lookup(3));
39 EXPECT_EQ(0, S.lookup(9));
40
41 EXPECT_EQ(10, *S2.lookup(3));
42 EXPECT_EQ(11, *S2.lookup(4));
43 EXPECT_EQ(12, *S2.lookup(5));
44
45 EXPECT_EQ(5, S2.getMaxElement()->first);
46 EXPECT_EQ(3U, S2.getHeight());
47 }
48
49 }