OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart test using an identity hash. | 4 // Dart test using an identity hash. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 abstract class BigGame { | 8 abstract class BigGame { |
9 String get name; | 9 String get name; |
10 } | 10 } |
(...skipping 18 matching lines...) Expand all Loading... |
29 return nextId_++; | 29 return nextId_++; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 // Zebra relies on the system provided identity hash. | 33 // Zebra relies on the system provided identity hash. |
34 class Zebra implements BigGame { | 34 class Zebra implements BigGame { |
35 final String name; | 35 final String name; |
36 Zebra(this.name) {} | 36 Zebra(this.name) {} |
37 } | 37 } |
38 | 38 |
39 | |
40 class SavannahTest { | 39 class SavannahTest { |
41 | |
42 static void testMain() { | 40 static void testMain() { |
43 Map<BigGame, String> savannah = new Map<BigGame, String>(); | 41 Map<BigGame, String> savannah = new Map<BigGame, String>(); |
44 | 42 |
45 Giraffe giraffe1 = new Giraffe("Tony"); | 43 Giraffe giraffe1 = new Giraffe("Tony"); |
46 Giraffe giraffe2 = new Giraffe("Rose"); | 44 Giraffe giraffe2 = new Giraffe("Rose"); |
47 savannah[giraffe1] = giraffe1.name; | 45 savannah[giraffe1] = giraffe1.name; |
48 savannah[giraffe2] = giraffe2.name; | 46 savannah[giraffe2] = giraffe2.name; |
49 print("giraffe1 hash: ${giraffe1.hashCode}"); | 47 print("giraffe1 hash: ${giraffe1.hashCode}"); |
50 print("giraffe2 hash: ${giraffe2.hashCode}"); | 48 print("giraffe2 hash: ${giraffe2.hashCode}"); |
51 | 49 |
(...skipping 15 matching lines...) Expand all Loading... |
67 | 65 |
68 count = savannah.length; | 66 count = savannah.length; |
69 print("getCount is $count"); | 67 print("getCount is $count"); |
70 Expect.equals(4, count); | 68 Expect.equals(4, count); |
71 | 69 |
72 print("zebra1: ${savannah[zebra1]}"); | 70 print("zebra1: ${savannah[zebra1]}"); |
73 print("zebra2: ${savannah[zebra2]}"); | 71 print("zebra2: ${savannah[zebra2]}"); |
74 Expect.equals("Paolo", savannah[zebra1]); | 72 Expect.equals("Paolo", savannah[zebra1]); |
75 Expect.equals("Zeeta", savannah[zebra2]); | 73 Expect.equals("Zeeta", savannah[zebra2]); |
76 } | 74 } |
77 | |
78 } | 75 } |
79 | 76 |
80 main() { | 77 main() { |
81 SavannahTest.testMain(); | 78 SavannahTest.testMain(); |
82 } | 79 } |
OLD | NEW |