#include #include #include #include "map.hpp" TEST(BasicTests, GTestItSelf) { // Expect two strings not to be equal. EXPECT_STRNE("hello", "world"); // Expect equality. EXPECT_EQ(7 * 6, 42); } TEST(BasicTests, ConstructorAndEmptySize) { sjtu::map map; EXPECT_EQ(map.empty(), true); EXPECT_EQ(map.size(), 0); } TEST(BasicTests, BasicOperatorInsert) { sjtu::map map1; map1[1] = 2; EXPECT_EQ(map1.empty(), false); EXPECT_EQ(map1.size(), 1); EXPECT_EQ(map1[1], 2); auto it = map1.find(1); EXPECT_EQ(it->second, 2); sjtu::map map2; auto ret = map2.insert(sjtu::pair(1, 2)); EXPECT_EQ(ret.second, true); EXPECT_EQ(ret.first->first, 1); EXPECT_EQ(ret.first->second, 2); } TEST(BasicTests, MassiveOperatorInsert) { std::mt19937 rnd(2333); sjtu::map map; std::map standard_map; int nodes = 1000; for (int i = 0; i < nodes; ++i) { int key = rnd() % 10000; int value = rnd() % 10000; // std::cerr << "writing " << key << " " << value << "\n"; map[key] = value; #ifndef NDEBUG EXPECT_TRUE(map.RedBlackTreeStructureCheck()); #endif standard_map[key] = value; } auto mp_it = map.begin(); auto st_it = standard_map.begin(); EXPECT_EQ(map.size(), standard_map.size()); for (; mp_it != map.end(); mp_it++, st_it++) { EXPECT_EQ(mp_it->first, st_it->first); EXPECT_EQ(mp_it->second, st_it->second); } mp_it = map.end(); st_it = standard_map.end(); for (int i = 0; i < map.size(); ++i) { mp_it--; st_it--; EXPECT_EQ(mp_it->first, st_it->first); EXPECT_EQ(mp_it->second, st_it->second); } }