| Index: runtime/vm/hash_map_test.cc
|
| diff --git a/runtime/vm/hash_map_test.cc b/runtime/vm/hash_map_test.cc
|
| index 522ff7c57ddc18d740f9dc733197631ba127b5d2..7830b85bcb6aa28c6b9346bceb8799cfb04e9e24 100644
|
| --- a/runtime/vm/hash_map_test.cc
|
| +++ b/runtime/vm/hash_map_test.cc
|
| @@ -25,15 +25,94 @@ TEST_CASE(DirectChainedHashMap) {
|
| TestValue v2(1);
|
| TestValue v3(0);
|
| map.Insert(&v1);
|
| - EXPECT(map.Lookup(&v1) == &v1);
|
| + EXPECT(map.LookupValue(&v1) == &v1);
|
| map.Insert(&v2);
|
| - EXPECT(map.Lookup(&v1) == &v1);
|
| - EXPECT(map.Lookup(&v2) == &v2);
|
| - EXPECT(map.Lookup(&v3) == &v1);
|
| + EXPECT(map.LookupValue(&v1) == &v1);
|
| + EXPECT(map.LookupValue(&v2) == &v2);
|
| + EXPECT(map.LookupValue(&v3) == &v1);
|
| DirectChainedHashMap<PointerKeyValueTrait<TestValue> > map2(map);
|
| - EXPECT(map2.Lookup(&v1) == &v1);
|
| - EXPECT(map2.Lookup(&v2) == &v2);
|
| - EXPECT(map2.Lookup(&v3) == &v1);
|
| + EXPECT(map2.LookupValue(&v1) == &v1);
|
| + EXPECT(map2.LookupValue(&v2) == &v2);
|
| + EXPECT(map2.LookupValue(&v3) == &v1);
|
| +}
|
| +
|
| +
|
| +TEST_CASE(MallocDirectChainedHashMap) {
|
| + MallocDirectChainedHashMap<PointerKeyValueTrait<TestValue> > map;
|
| + EXPECT(map.IsEmpty());
|
| + TestValue v1(0);
|
| + TestValue v2(1);
|
| + TestValue v3(0);
|
| + map.Insert(&v1);
|
| + EXPECT(map.LookupValue(&v1) == &v1);
|
| + map.Insert(&v2);
|
| + EXPECT(map.LookupValue(&v1) == &v1);
|
| + EXPECT(map.LookupValue(&v2) == &v2);
|
| + EXPECT(map.LookupValue(&v3) == &v1);
|
| + MallocDirectChainedHashMap<PointerKeyValueTrait<TestValue> > map2(map);
|
| + EXPECT(map2.LookupValue(&v1) == &v1);
|
| + EXPECT(map2.LookupValue(&v2) == &v2);
|
| + EXPECT(map2.LookupValue(&v3) == &v1);
|
| +}
|
| +
|
| +
|
| +class IntptrPair {
|
| + public:
|
| + IntptrPair() : first_(-1), second_(-1) {}
|
| + IntptrPair(intptr_t first, intptr_t second)
|
| + : first_(first), second_(second) {}
|
| +
|
| + intptr_t first() const { return first_; }
|
| + intptr_t second() const { return second_; }
|
| +
|
| + bool operator==(const IntptrPair& other) {
|
| + return (first_ == other.first_) && (second_ == other.second_);
|
| + }
|
| +
|
| + bool operator!=(const IntptrPair& other) {
|
| + return (first_ != other.first_) || (second_ != other.second_);
|
| + }
|
| +
|
| + private:
|
| + intptr_t first_;
|
| + intptr_t second_;
|
| +};
|
| +
|
| +
|
| +TEST_CASE(DirectChainedHashMapIterator) {
|
| + IntptrPair p1(1, 1);
|
| + IntptrPair p2(2, 2);
|
| + IntptrPair p3(3, 3);
|
| + IntptrPair p4(4, 4);
|
| + IntptrPair p5(5, 5);
|
| + DirectChainedHashMap<NumbersKeyValueTrait<IntptrPair> > map;
|
| + EXPECT(map.IsEmpty());
|
| + DirectChainedHashMap<NumbersKeyValueTrait<IntptrPair> >::Iterator it =
|
| + map.GetIterator();
|
| + EXPECT(it.Next() == NULL);
|
| + it.Reset();
|
| +
|
| + map.Insert(p1);
|
| + EXPECT(*it.Next() == p1);
|
| + it.Reset();
|
| +
|
| + map.Insert(p2);
|
| + map.Insert(p3);
|
| + map.Insert(p4);
|
| + map.Insert(p5);
|
| + intptr_t count = 0;
|
| + intptr_t sum = 0;
|
| + while (true) {
|
| + IntptrPair* p = it.Next();
|
| + if (p == NULL) {
|
| + break;
|
| + }
|
| + count++;
|
| + sum += p->second();
|
| + }
|
| +
|
| + EXPECT(count == 5);
|
| + EXPECT(sum == 15);
|
| }
|
|
|
| } // namespace dart
|
|
|