Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 // Churn the tree's contents. | 169 // Churn the tree's contents. |
| 170 // First remove half of the elements in random order. | 170 // First remove half of the elements in random order. |
| 171 for (int i = 0; i < tree_size / 2; i++) { | 171 for (int i = 0; i < tree_size / 2; i++) { |
| 172 int idx = NextRandom(added_elements.size()); | 172 int idx = NextRandom(added_elements.size()); |
| 173 tree.Insert(added_elements[idx]); | 173 tree.Insert(added_elements[idx]); |
| 174 EXPECT_TRUE(tree.Verify()) << "Test failed for seed " << seed; | 174 EXPECT_TRUE(tree.Verify()) << "Test failed for seed " << seed; |
| 175 added_elements.erase(added_elements.begin() + idx); | 175 added_elements.erase(added_elements.begin() + idx); |
| 176 } | 176 } |
| 177 // Now randomly add or remove elements. | 177 // Now randomly add or remove elements. |
| 178 for (int i = 0; i < 2 * tree_size; i++) { | 178 for (int i = 0; i < 2 * tree_size; i++) { |
| 179 bool add = false; | 179 bool add = false; |
|
Peter Kasting
2011/03/02 00:02:42
Nit: Eliminate |add| and condense to:
if (add
| |
| 180 if (added_elements.size() == 0) { | 180 if (added_elements.empty()) { |
| 181 add = true; | 181 add = true; |
| 182 } else if (removed_elements.size() == 0) { | 182 } else if (removed_elements.empty()) { |
| 183 add = false; | 183 add = false; |
| 184 } else { | 184 } else { |
| 185 add = (NextRandom(2) == 1); | 185 add = (NextRandom(2) == 1); |
| 186 } | 186 } |
| 187 if (add) { | 187 if (add) { |
| 188 int idx = NextRandom(removed_elements.size()); | 188 int idx = NextRandom(removed_elements.size()); |
| 189 tree.Insert(removed_elements[idx]); | 189 tree.Insert(removed_elements[idx]); |
| 190 added_elements.push_back(removed_elements[idx]); | 190 added_elements.push_back(removed_elements[idx]); |
| 191 removed_elements.erase(removed_elements.begin() + idx); | 191 removed_elements.erase(removed_elements.begin() + idx); |
| 192 } else { | 192 } else { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 206 InsertionAndDeletionTest((unsigned) 13972, 100); | 206 InsertionAndDeletionTest((unsigned) 13972, 100); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST(IntervalTreeTest, TestRandomDeletionAndInsertion) { | 209 TEST(IntervalTreeTest, TestRandomDeletionAndInsertion) { |
| 210 InsertionAndDeletionTest((unsigned) GenerateSeed(), 1000); | 210 InsertionAndDeletionTest((unsigned) GenerateSeed(), 1000); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace gpu2d | 213 } // namespace gpu2d |
| 214 } // namespace o3d | 214 } // namespace o3d |
| 215 | 215 |
| OLD | NEW |