Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: base/containers/flat_tree_unittest.cc

Issue 2859593002: base: Add bulk insert to flat_tree. (Closed)
Patch Set: update Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/containers/flat_tree.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/containers/flat_tree.h" 5 #include "base/containers/flat_tree.h"
6 6
7 // Following tests are ported and extended tests from libcpp for std::set. 7 // Following tests are ported and extended tests from libcpp for std::set.
8 // They can be found here: 8 // They can be found here:
9 // https://github.com/llvm-mirror/libcxx/tree/master/test/std/containers/associa tive/set 9 // https://github.com/llvm-mirror/libcxx/tree/master/test/std/containers/associa tive/set
10 // 10 //
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 EXPECT_EQ(3, *result); 707 EXPECT_EQ(3, *result);
708 708
709 result = cont.insert(cont.cend(), 3); 709 result = cont.insert(cont.cend(), 3);
710 EXPECT_EQ(std::prev(cont.end()), result); 710 EXPECT_EQ(std::prev(cont.end()), result);
711 EXPECT_EQ(3U, cont.size()); 711 EXPECT_EQ(3U, cont.size());
712 EXPECT_EQ(3, *result); 712 EXPECT_EQ(3, *result);
713 } 713 }
714 714
715 // iterator insert(const_iterator position_hint, value_type&& val) 715 // iterator insert(const_iterator position_hint, value_type&& val)
716 716
717 TEST(FlatTree, BulkInsertLValueIntoEmpty) {
718 IntPairTree cont;
719 IntPair inputs[] = {{1, 1}, {4, 1}, {3, 1}, {0, 1}, {2, 1}, {5, 1}};
720 cont.insert(MakeInputIterator(std::begin(inputs)),
721 MakeInputIterator(std::end(inputs)));
722
723 EXPECT_THAT(cont, ElementsAre(IntPair(0, 1), IntPair(1, 1), IntPair(2, 1),
724 IntPair(3, 1), IntPair(4, 1), IntPair(5, 1)));
725 }
726
727 TEST(FlatTree, BulkInsertLValueIntoNonEmpty) {
728 IntPair initial_inputs[] = {{1, 0}, {3, 0}, {4, 0}, {6, 0}};
729 IntPairTree cont(MakeInputIterator(std::begin(initial_inputs)),
730 MakeInputIterator(std::end(initial_inputs)),
731 KEEP_FIRST_OF_DUPES);
732
733 IntPair new_inputs[] = {{1, 1}, {0, 1}, {4, 1}, {3, 1},
734 {0, 2}, {2, 1}, {2, 2}, {5, 1}};
735 cont.insert(MakeInputIterator(std::begin(new_inputs)),
736 MakeInputIterator(std::end(new_inputs)));
737
738 EXPECT_THAT(cont, ElementsAre(IntPair(0, 1), IntPair(1, 0), IntPair(2, 1),
739 IntPair(3, 0), IntPair(4, 0), IntPair(5, 1),
740 IntPair(6, 0)));
741 }
742
743 TEST(FlatTree, BulkInsertRValue) {
744 int initial_inputs[] = {1, 3, 4, 6};
745 MoveOnlyTree cont(std::begin(initial_inputs), std::end(initial_inputs),
746 KEEP_FIRST_OF_DUPES);
747 MoveOnlyInt new_inputs[] = {MoveOnlyInt(0), MoveOnlyInt(1), MoveOnlyInt(5),
748 MoveOnlyInt(4), MoveOnlyInt(3), MoveOnlyInt(2)};
749 cont.insert(std::make_move_iterator(std::begin(new_inputs)),
750 std::make_move_iterator(std::end(new_inputs)));
751 EXPECT_EQ(1U, cont.count(MoveOnlyInt(0)));
752 EXPECT_EQ(1U, cont.count(MoveOnlyInt(1)));
753 EXPECT_EQ(1U, cont.count(MoveOnlyInt(2)));
754 EXPECT_EQ(1U, cont.count(MoveOnlyInt(3)));
755 EXPECT_EQ(1U, cont.count(MoveOnlyInt(4)));
756 EXPECT_EQ(1U, cont.count(MoveOnlyInt(5)));
757 EXPECT_EQ(1U, cont.count(MoveOnlyInt(6)));
758 }
759
717 TEST(FlatTree, InsertPositionRValue) { 760 TEST(FlatTree, InsertPositionRValue) {
718 MoveOnlyTree cont; 761 MoveOnlyTree cont;
719 762
720 MoveOnlyTree::iterator result = cont.insert(cont.cend(), MoveOnlyInt(2)); 763 MoveOnlyTree::iterator result = cont.insert(cont.cend(), MoveOnlyInt(2));
721 EXPECT_EQ(cont.begin(), result); 764 EXPECT_EQ(cont.begin(), result);
722 EXPECT_EQ(1U, cont.size()); 765 EXPECT_EQ(1U, cont.size());
723 EXPECT_EQ(2, result->data()); 766 EXPECT_EQ(2, result->data());
724 767
725 result = cont.insert(cont.cend(), MoveOnlyInt(1)); 768 result = cont.insert(cont.cend(), MoveOnlyInt(1));
726 EXPECT_EQ(cont.begin(), result); 769 EXPECT_EQ(cont.begin(), result);
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 EraseIf(x, [](int elem) { return !(elem & 1); }); 1419 EraseIf(x, [](int elem) { return !(elem & 1); });
1377 EXPECT_THAT(x, ElementsAre(1, 3)); 1420 EXPECT_THAT(x, ElementsAre(1, 3));
1378 1421
1379 x = {1, 2, 3, 4}; 1422 x = {1, 2, 3, 4};
1380 EraseIf(x, [](int elem) { return elem & 1; }); 1423 EraseIf(x, [](int elem) { return elem & 1; });
1381 EXPECT_THAT(x, ElementsAre(2, 4)); 1424 EXPECT_THAT(x, ElementsAre(2, 4));
1382 } 1425 }
1383 1426
1384 } // namespace internal 1427 } // namespace internal
1385 } // namespace base 1428 } // namespace base
OLDNEW
« no previous file with comments | « base/containers/flat_tree.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698