OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "platform/assert.h" |
| 6 #include "vm/unit_test.h" |
| 7 #include "vm/hash_map.h" |
| 8 |
| 9 namespace dart { |
| 10 |
| 11 class TestValue { |
| 12 public: |
| 13 explicit TestValue(intptr_t x) : x_(x) { } |
| 14 intptr_t Hashcode() const { return x_ & 1; } |
| 15 bool Equals(TestValue* other) { return x_ == other->x_; } |
| 16 private: |
| 17 intptr_t x_; |
| 18 }; |
| 19 |
| 20 |
| 21 TEST_CASE(DirectChainedHashMap) { |
| 22 DirectChainedHashMap<TestValue*> map; |
| 23 EXPECT(map.IsEmpty()); |
| 24 TestValue v1(0); |
| 25 TestValue v2(1); |
| 26 TestValue v3(0); |
| 27 map.Insert(&v1); |
| 28 EXPECT(map.Lookup(&v1) == &v1); |
| 29 map.Insert(&v2); |
| 30 EXPECT(map.Lookup(&v1) == &v1); |
| 31 EXPECT(map.Lookup(&v2) == &v2); |
| 32 EXPECT(map.Lookup(&v3) == &v1); |
| 33 } |
| 34 |
| 35 } // namespace dart |
OLD | NEW |