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

Side by Side Diff: Source/wtf/ListHashSetTest.cpp

Issue 474943002: Fix for LinkedHashSet::swap. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: templated test Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/LinkedHashSet.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 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 ownPtr2 = set.take(ptr2); 649 ownPtr2 = set.take(ptr2);
650 EXPECT_TRUE(set.isEmpty()); 650 EXPECT_TRUE(set.isEmpty());
651 } 651 }
652 EXPECT_FALSE(deleted1); 652 EXPECT_FALSE(deleted1);
653 EXPECT_FALSE(deleted2); 653 EXPECT_FALSE(deleted2);
654 654
655 EXPECT_EQ(ptr1, ownPtr1); 655 EXPECT_EQ(ptr1, ownPtr1);
656 EXPECT_EQ(ptr2, ownPtr2); 656 EXPECT_EQ(ptr2, ownPtr2);
657 } 657 }
658 658
659 template<typename Set>
660 void swapTestHelper()
661 {
662 int num = 10;
663 Set set0;
664 Set set1;
665 Set set2;
666 for (int i = 0; i < num; ++i) {
667 set1.add(i + 1);
668 set2.add(num - i);
669 }
670
671 typename Set::iterator it1 = set1.begin();
672 typename Set::iterator it2 = set2.begin();
673 for (int i = 0; i < num; ++i, ++it1, ++it2) {
674 EXPECT_EQ(*it1, i + 1);
675 EXPECT_EQ(*it2, num - i);
676 }
677 EXPECT_EQ(set0.begin(), set0.end());
678 EXPECT_EQ(it1, set1.end());
679 EXPECT_EQ(it2, set2.end());
680
681 // Shift sets: 2->1, 1->0, 0->2
682 set1.swap(set2); // Swap with non-empty sets.
683 set0.swap(set2); // Swap with an empty set.
684
685 it1 = set0.begin();
686 it2 = set1.begin();
687 for (int i = 0; i < num; ++i, ++it1, ++it2) {
688 EXPECT_EQ(*it1, i + 1);
689 EXPECT_EQ(*it2, num - i);
690 }
691 EXPECT_EQ(it1, set0.end());
692 EXPECT_EQ(it2, set1.end());
693 EXPECT_EQ(set2.begin(), set2.end());
694
695 int removedIndex = num >> 1;
696 set0.remove(removedIndex + 1);
697 set1.remove(num - removedIndex);
698
699 it1 = set0.begin();
700 it2 = set1.begin();
701 for (int i = 0; i < num; ++i, ++it1, ++it2) {
702 if (i == removedIndex)
703 ++i;
704 EXPECT_EQ(*it1, i + 1);
705 EXPECT_EQ(*it2, num - i);
706 }
707 EXPECT_EQ(it1, set0.end());
708 EXPECT_EQ(it2, set1.end());
709 }
710
711 TEST(ListHashSetTest, Swap)
712 {
713 swapTestHelper<ListHashSet<int> >();
714 }
715
716 TEST(LinkedHashSetTest, Swap)
717 {
718 swapTestHelper<LinkedHashSet<int> >();
719 }
720
659 } // namespace 721 } // namespace
OLDNEW
« no previous file with comments | « Source/wtf/LinkedHashSet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698