From 8327390ccc27853c5bee794029a9ab2cc54df335 Mon Sep 17 00:00:00 2001 From: Gil Date: Tue, 24 Apr 2018 08:59:38 -0700 Subject: Implement erase in C++ immutable maps (#1158) * Add SortedMap::min * Add SortedMap::erase --- .../firestore/immutable/array_sorted_map_test.cc | 95 ---------------------- 1 file changed, 95 deletions(-) (limited to 'Firestore/core/test/firebase/firestore/immutable/array_sorted_map_test.cc') diff --git a/Firestore/core/test/firebase/firestore/immutable/array_sorted_map_test.cc b/Firestore/core/test/firebase/firestore/immutable/array_sorted_map_test.cc index ea8ae6e..9a23df5 100644 --- a/Firestore/core/test/firebase/firestore/immutable/array_sorted_map_test.cc +++ b/Firestore/core/test/firebase/firestore/immutable/array_sorted_map_test.cc @@ -32,66 +32,6 @@ namespace impl { using IntMap = ArraySortedMap; constexpr IntMap::size_type kFixedSize = IntMap::kFixedSize; -TEST(ArraySortedMap, RemoveKeyValuePair) { - IntMap map{{1, 3}, {2, 4}}; - - IntMap new_map = map.erase(1); - ASSERT_TRUE(Found(new_map, 2, 4)); - ASSERT_TRUE(NotFound(new_map, 1)); - - // Make sure the original one is not mutated - ASSERT_TRUE(Found(map, 1, 3)); - ASSERT_TRUE(Found(map, 2, 4)); -} - -TEST(ArraySortedMap, MoreRemovals) { - IntMap map = IntMap{} - .insert(1, 1) - .insert(50, 50) - .insert(3, 3) - .insert(4, 4) - .insert(7, 7) - .insert(9, 9) - .insert(1, 20) - .insert(18, 18) - .insert(3, 2) - .insert(4, 71) - .insert(7, 42) - .insert(9, 88); - - ASSERT_TRUE(Found(map, 7, 42)); - ASSERT_TRUE(Found(map, 3, 2)); - ASSERT_TRUE(Found(map, 1, 20)); - - IntMap s1 = map.erase(7); - IntMap s2 = map.erase(3); - IntMap s3 = map.erase(1); - - ASSERT_TRUE(NotFound(s1, 7)); - ASSERT_TRUE(Found(s1, 3, 2)); - ASSERT_TRUE(Found(s1, 1, 20)); - - ASSERT_TRUE(Found(s2, 7, 42)); - ASSERT_TRUE(NotFound(s2, 3)); - ASSERT_TRUE(Found(s2, 1, 20)); - - ASSERT_TRUE(Found(s3, 7, 42)); - ASSERT_TRUE(Found(s3, 3, 2)); - ASSERT_TRUE(NotFound(s3, 1)); -} - -TEST(ArraySortedMap, RemovesMiddle) { - IntMap map{{1, 1}, {2, 2}, {3, 3}}; - ASSERT_TRUE(Found(map, 1, 1)); - ASSERT_TRUE(Found(map, 2, 2)); - ASSERT_TRUE(Found(map, 3, 3)); - - IntMap s1 = map.erase(2); - ASSERT_TRUE(Found(s1, 1, 1)); - ASSERT_TRUE(NotFound(s1, 2)); - ASSERT_TRUE(Found(s1, 3, 3)); -} - TEST(ArraySortedMap, ChecksSize) { std::vector to_insert = Sequence(kFixedSize); IntMap map = ToMap(to_insert); @@ -103,41 +43,6 @@ TEST(ArraySortedMap, ChecksSize) { ASSERT_ANY_THROW(map.insert(next, next)); } -TEST(ArraySortedMap, EmptyRemoval) { - IntMap map; - IntMap new_map = map.erase(1); - EXPECT_TRUE(new_map.empty()); - EXPECT_EQ(0u, new_map.size()); - EXPECT_TRUE(NotFound(new_map, 1)); -} - -TEST(ArraySortedMap, InsertionAndRemovalOfMaxItems) { - auto expected_size = kFixedSize; - auto n = static_cast(expected_size); - std::vector to_insert = Shuffled(Sequence(n)); - std::vector to_remove = Shuffled(to_insert); - - // Add them to the map - IntMap map = ToMap(to_insert); - ASSERT_EQ(expected_size, map.size()) - << "Check if all N objects are in the map"; - - // check the order is correct - ASSERT_SEQ_EQ(Pairs(Sorted(to_insert)), map); - - for (int i : to_remove) { - map = map.erase(i); - } - ASSERT_EQ(0u, map.size()) << "Check we removed all of the items"; -} - -TEST(ArraySortedMap, BalanceProblem) { - std::vector to_insert{1, 7, 8, 5, 2, 6, 4, 0, 3}; - - IntMap map = ToMap(to_insert); - ASSERT_SEQ_EQ(Pairs(Sorted(to_insert)), map); -} - } // namespace impl } // namespace immutable } // namespace firestore -- cgit v1.2.3