mirror of
https://github.com/dart-lang/sdk
synced 2024-09-22 09:32:59 +00:00
55c9c6c444
For example: var list = new List(n); for (var i = 0; i < n; i++) list[i]; R=fschneider@google.com BUG= Review URL: https://codereview.chromium.org//11273111 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14293 260f80e4-7a28-3924-810f-c04153c831b5
40 lines
1 KiB
C++
40 lines
1 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "platform/assert.h"
|
|
#include "vm/unit_test.h"
|
|
#include "vm/hash_map.h"
|
|
|
|
namespace dart {
|
|
|
|
class TestValue {
|
|
public:
|
|
explicit TestValue(intptr_t x) : x_(x) { }
|
|
intptr_t Hashcode() const { return x_ & 1; }
|
|
bool Equals(TestValue* other) { return x_ == other->x_; }
|
|
private:
|
|
intptr_t x_;
|
|
};
|
|
|
|
|
|
TEST_CASE(DirectChainedHashMap) {
|
|
DirectChainedHashMap<PointerKeyValueTrait<TestValue> > map;
|
|
EXPECT(map.IsEmpty());
|
|
TestValue v1(0);
|
|
TestValue v2(1);
|
|
TestValue v3(0);
|
|
map.Insert(&v1);
|
|
EXPECT(map.Lookup(&v1) == &v1);
|
|
map.Insert(&v2);
|
|
EXPECT(map.Lookup(&v1) == &v1);
|
|
EXPECT(map.Lookup(&v2) == &v2);
|
|
EXPECT(map.Lookup(&v3) == &v1);
|
|
DirectChainedHashMap<PointerKeyValueTrait<TestValue> > map2(map);
|
|
EXPECT(map2.Lookup(&v1) == &v1);
|
|
EXPECT(map2.Lookup(&v2) == &v2);
|
|
EXPECT(map2.Lookup(&v3) == &v1);
|
|
}
|
|
|
|
} // namespace dart
|