OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestBiMap.cpp
Go to the documentation of this file.
1
42#include <gtest/gtest.h>
43#include <string>
44#include "Utilities/BiMap.h"
45
46class BiMapTest : public ::testing::Test {
47protected:
48 void SetUp() override {
49 // Test setup if needed
50 }
51};
52
53TEST_F(BiMapTest, BasicInsertion) {
55 bimap.insert(1, "one");
56 bimap.insert(2, "two");
57 bimap.insert(3, "three");
58
59 EXPECT_EQ(bimap.left_at(1), "one");
60 EXPECT_EQ(bimap.left_at(2), "two");
61 EXPECT_EQ(bimap.left_at(3), "three");
62
63 EXPECT_EQ(bimap.right_at("one"), 1);
64 EXPECT_EQ(bimap.right_at("two"), 2);
65 EXPECT_EQ(bimap.right_at("three"), 3);
66}
67
68TEST_F(BiMapTest, LeftViewAccess) {
70 bimap.insert(1, "one");
71 bimap.insert(2, "two");
72
73 auto it = bimap.left.find(1);
74 EXPECT_NE(it, bimap.left.end());
75 EXPECT_EQ(it->second, "one");
76
77 it = bimap.left.find(3);
78 EXPECT_EQ(it, bimap.left.end());
79}
80
81TEST_F(BiMapTest, RightViewAccess) {
83 bimap.insert(1, "one");
84 bimap.insert(2, "two");
85
86 auto it = bimap.right.find("one");
87 EXPECT_NE(it, bimap.right.end());
88 EXPECT_EQ(it->second, 1);
89
90 it = bimap.right.find("three");
91 EXPECT_EQ(it, bimap.right.end());
92}
93
94TEST_F(BiMapTest, OutOfRangeException) {
96 bimap.insert(1, "one");
97
98 EXPECT_THROW(bimap.left_at(2), std::out_of_range);
99 EXPECT_THROW(bimap.right_at("two"), std::out_of_range);
100}
101
102TEST_F(BiMapTest, MakeBiMapHelper) {
103 auto bimap = make_bimap<int, std::string>({{1, "one"}, {2, "two"}, {3, "three"}});
104
105 EXPECT_EQ(bimap.left_at(1), "one");
106 EXPECT_EQ(bimap.left_at(2), "two");
107 EXPECT_EQ(bimap.left_at(3), "three");
108
109 EXPECT_EQ(bimap.right_at("one"), 1);
110 EXPECT_EQ(bimap.right_at("two"), 2);
111 EXPECT_EQ(bimap.right_at("three"), 3);
112}
113
114TEST_F(BiMapTest, FindMethods) {
116 bimap.insert(1, "one");
117 bimap.insert(2, "two");
118
119 auto left_it = bimap.left_find(1);
120 EXPECT_NE(left_it, bimap.left_end());
121 EXPECT_EQ(left_it->second, "one");
122
123 auto right_it = bimap.right_find("two");
124 EXPECT_NE(right_it, bimap.right_end());
125 EXPECT_EQ(right_it->second, 2);
126
127 left_it = bimap.left_find(99);
128 EXPECT_EQ(left_it, bimap.left_end());
129
130 right_it = bimap.right_find("ninety-nine");
131 EXPECT_EQ(right_it, bimap.right_end());
132}
133
134TEST_F(BiMapTest, StringToString) {
136 bimap.insert("key1", "value1");
137 bimap.insert("key2", "value2");
138
139 EXPECT_EQ(bimap.left_at("key1"), "value1");
140 EXPECT_EQ(bimap.right_at("value2"), "key2");
141}
TEST_F(BiMapTest, BasicInsertion)
Definition TestBiMap.cpp:53
void SetUp() override
Definition TestBiMap.cpp:48
Simple bidirectional map with lookup in both directions.
Definition BiMap.h:28
void insert(const Left &left, const Right &right)
Insert or overwrite a left/right association.
Definition BiMap.h:99
right_map::iterator right_find(const Right &key)
Find an entry by right key.
Definition BiMap.h:112
right_view right
Right view accessor.
Definition BiMap.h:94
const Left & right_at(const Right &key) const
Get mapped left value by right key (throws if missing).
Definition BiMap.h:135
left_view left
Left view accessor.
Definition BiMap.h:92
const Right & left_at(const Left &key) const
Get mapped right value by left key (throws if missing).
Definition BiMap.h:124
right_map::iterator right_end()
End iterator for right map.
Definition BiMap.h:119
left_map::iterator left_find(const Left &key)
Find an entry by left key.
Definition BiMap.h:107
left_map::iterator left_end()
End iterator for left map.
Definition BiMap.h:116
left_map::iterator end() const
End iterator for the left map.
Definition BiMap.h:62
left_map::iterator find(const Left &key) const
Find iterator for key in the left map.
Definition BiMap.h:59
right_map::iterator find(const Right &key) const
Find iterator for key in the right map.
Definition BiMap.h:78
right_map::iterator end() const
End iterator for the right map.
Definition BiMap.h:81