1 //===----------- ImmutableMapTest.cpp - ImmutableMap unit tests ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "gtest/gtest.h"
11 #include "llvm/ADT/ImmutableMap.h"
17 TEST(ImmutableMapTest, EmptyIntMapTest) {
18 ImmutableMap<int, int>::Factory f;
20 EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap());
21 EXPECT_FALSE(f.getEmptyMap() != f.getEmptyMap());
22 EXPECT_TRUE(f.getEmptyMap().isEmpty());
24 ImmutableMap<int, int> S = f.getEmptyMap();
25 EXPECT_EQ(0u, S.getHeight());
26 EXPECT_TRUE(S.begin() == S.end());
27 EXPECT_FALSE(S.begin() != S.end());
30 TEST(ImmutableMapTest, MultiElemIntMapTest) {
31 ImmutableMap<int, int>::Factory f;
32 ImmutableMap<int, int> S = f.getEmptyMap();
34 ImmutableMap<int, int> S2 = f.add(f.add(f.add(S, 3, 10), 4, 11), 5, 12);
36 EXPECT_TRUE(S.isEmpty());
37 EXPECT_FALSE(S2.isEmpty());
39 EXPECT_EQ(nullptr, S.lookup(3));
40 EXPECT_EQ(nullptr, S.lookup(9));
42 EXPECT_EQ(10, *S2.lookup(3));
43 EXPECT_EQ(11, *S2.lookup(4));
44 EXPECT_EQ(12, *S2.lookup(5));
46 EXPECT_EQ(5, S2.getMaxElement()->first);
47 EXPECT_EQ(3U, S2.getHeight());