Chromium Code Reviews| Index: tests/DynamicHashTest.cpp |
| diff --git a/tests/DynamicHashTest.cpp b/tests/DynamicHashTest.cpp |
| index f502dbae70287142449b8c1cd8ae5a438f6f354a..84da1aee9c81913a13554606cdc0c785d13796fd 100644 |
| --- a/tests/DynamicHashTest.cpp |
| +++ b/tests/DynamicHashTest.cpp |
| @@ -7,6 +7,7 @@ |
| #include "Test.h" |
| #include "SkTDynamicHash.h" |
| +#include "SkRandom.h" |
| namespace { |
| @@ -139,11 +140,67 @@ static void test_remove(skiatest::Reporter* reporter) { |
| ASSERT(hash.find(5)->value == 3.0); |
| } |
| +static void test_validate(skiatest::Reporter* reporter) { |
| + // Test validate after construction for different initial capacitys. |
| + { |
| + Entry a = { 1, 2.0 }; |
| + Entry b = { 2, 3.0 }; |
| + Entry c = { 9, 4.0 }; |
| + |
| + for (int i = 0; i < 77; ++i) { |
| + Hash hash(i); |
| + hash.validate(); |
| + |
| + hash.add(&a); |
| + hash.validate(); |
| + hash.add(&b); |
| + hash.validate(); |
| + hash.add(&c); |
| + hash.validate(); |
| + |
| + ASSERT(hash.find(1) != NULL); |
| + ASSERT(hash.find(9) != NULL); |
| + hash.remove(1); |
| + hash.validate(); |
| + ASSERT(hash.find(2) == &b); |
| + hash.remove(2); |
| + hash.validate(); |
| + hash.add(&a); |
| + hash.validate(); |
| + ASSERT(hash.find(1) == &a); |
| + hash.remove(1); |
| + hash.remove(9); |
| + hash.validate(); |
| + } |
| + } |
| + |
| + { |
| + SkRandom rand; |
| + Entry entries[3333]; |
|
mtklein
2013/12/03 19:02:02
Can you just mark 3333 and 237 as arbitrary someho
|
| + Hash hash; |
| + |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(entries); ++i) { |
| + entries[i].key = rand.nextU(); |
|
mtklein
2013/12/03 19:02:02
It's unlikely, but this could trigger a uniqueness
|
| + entries[i].value = rand.nextF(); |
| + hash.add(&entries[i]); |
| + } |
| + |
| + hash.validate(); |
| + |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(entries); i += 237) { |
| + ASSERT(hash.find(entries[i].key) != NULL); |
| + hash.remove(entries[i].key); |
| + hash.validate(); |
| + } |
| + } |
| +} |
| + |
| static void test_dynamic_hash(skiatest::Reporter* reporter) { |
| test_growth(reporter); |
| test_add(reporter); |
| test_lookup(reporter); |
| test_remove(reporter); |
| + test_validate(reporter); |
| } |
| #include "TestClassDef.h" |