[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / unittests / ADT / ImmutableMapTest.cpp
blob1217718826f7750e6ecf381d0725cf013d31a37b
1 //===----------- ImmutableMapTest.cpp - ImmutableMap unit tests ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/ImmutableMap.h"
10 #include "gtest/gtest.h"
12 using namespace llvm;
14 namespace {
16 TEST(ImmutableMapTest, EmptyIntMapTest) {
17 ImmutableMap<int, int>::Factory f;
19 EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap());
20 EXPECT_FALSE(f.getEmptyMap() != f.getEmptyMap());
21 EXPECT_TRUE(f.getEmptyMap().isEmpty());
23 ImmutableMap<int, int> S = f.getEmptyMap();
24 EXPECT_EQ(0u, S.getHeight());
25 EXPECT_TRUE(S.begin() == S.end());
26 EXPECT_FALSE(S.begin() != S.end());
29 TEST(ImmutableMapTest, MultiElemIntMapTest) {
30 ImmutableMap<int, int>::Factory f;
31 ImmutableMap<int, int> S = f.getEmptyMap();
33 ImmutableMap<int, int> S2 = f.add(f.add(f.add(S, 3, 10), 4, 11), 5, 12);
35 EXPECT_TRUE(S.isEmpty());
36 EXPECT_FALSE(S2.isEmpty());
38 EXPECT_EQ(nullptr, S.lookup(3));
39 EXPECT_EQ(nullptr, S.lookup(9));
41 EXPECT_EQ(10, *S2.lookup(3));
42 EXPECT_EQ(11, *S2.lookup(4));
43 EXPECT_EQ(12, *S2.lookup(5));
45 EXPECT_EQ(5, S2.getMaxElement()->first);
46 EXPECT_EQ(3U, S2.getHeight());
49 TEST(ImmutableMapTest, EmptyIntMapRefTest) {
50 using int_int_map = ImmutableMapRef<int, int>;
51 ImmutableMapRef<int, int>::FactoryTy f;
53 EXPECT_TRUE(int_int_map::getEmptyMap(&f) == int_int_map::getEmptyMap(&f));
54 EXPECT_FALSE(int_int_map::getEmptyMap(&f) != int_int_map::getEmptyMap(&f));
55 EXPECT_TRUE(int_int_map::getEmptyMap(&f).isEmpty());
57 int_int_map S = int_int_map::getEmptyMap(&f);
58 EXPECT_EQ(0u, S.getHeight());
59 EXPECT_TRUE(S.begin() == S.end());
60 EXPECT_FALSE(S.begin() != S.end());
63 TEST(ImmutableMapTest, MultiElemIntMapRefTest) {
64 ImmutableMapRef<int, int>::FactoryTy f;
66 ImmutableMapRef<int, int> S = ImmutableMapRef<int, int>::getEmptyMap(&f);
68 ImmutableMapRef<int, int> S2 = S.add(3, 10).add(4, 11).add(5, 12);
70 EXPECT_TRUE(S.isEmpty());
71 EXPECT_FALSE(S2.isEmpty());
73 EXPECT_EQ(nullptr, S.lookup(3));
74 EXPECT_EQ(nullptr, S.lookup(9));
76 EXPECT_EQ(10, *S2.lookup(3));
77 EXPECT_EQ(11, *S2.lookup(4));
78 EXPECT_EQ(12, *S2.lookup(5));
80 EXPECT_EQ(5, S2.getMaxElement()->first);
81 EXPECT_EQ(3U, S2.getHeight());
84 TEST(ImmutableMapTest, MapOfMapRefsTest) {
85 ImmutableMap<int, ImmutableMapRef<int, int>>::Factory f;
87 EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap());