OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class A { | 7 class A { |
8 const A(); | 8 const A(); |
9 foo() => 42; | 9 foo() => 42; |
10 } | 10 } |
11 | 11 |
12 class B { | 12 class B { |
13 foo() => 42; | 13 foo() => 42; |
14 } | 14 } |
15 | 15 |
16 main() { | 16 main() { |
17 // Use an array to defeat type inferencing. | 17 // Use an array to defeat type inferencing. |
18 var array = [new A(), new A(), new B(), new B()]; | 18 var array = <dynamic>[new A(), new A(), new B(), new B()]; |
19 var set = new Set.from(array.map((a) => a.foo)); | 19 var set = new Set.from(array.map((a) => a.foo)); |
20 Expect.equals(array.length, set.length); | 20 Expect.equals(array.length, set.length); |
21 set.addAll(array.map((a) => a.foo)); | 21 set.addAll(array.map((a) => a.foo)); |
22 Expect.equals(array.length, set.length); | 22 Expect.equals(array.length, set.length); |
23 | 23 |
24 for (int i = 0; i < array.length; i += 2) { | 24 for (int i = 0; i < array.length; i += 2) { |
25 Expect.isTrue(set.contains(array[i].foo)); | 25 Expect.isTrue(set.contains(array[i].foo)); |
26 Expect.equals(array[i], array[i]); | 26 Expect.equals(array[i], array[i]); |
27 Expect.equals(array[i].foo, array[i].foo); | 27 Expect.equals(array[i].foo, array[i].foo); |
28 Expect.equals(array[i].foo.hashCode, array[i].foo.hashCode); | 28 Expect.equals(array[i].foo.hashCode, array[i].foo.hashCode); |
29 for (int j = 0; j < array.length; j++) { | 29 for (int j = 0; j < array.length; j++) { |
30 if (i == j) continue; | 30 if (i == j) continue; |
31 Expect.notEquals(array[i].foo, array[j].foo); | 31 Expect.notEquals(array[i].foo, array[j].foo); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 // Try with dart2js intercepted types. | 35 // Try with dart2js intercepted types. |
36 array = ['foo', 'bar', [], [], const []]; | 36 array = <dynamic>['foo', 'bar', [], [], const []]; |
37 set = new Set.from(array.map((a) => a.indexOf)); | 37 set = new Set.from(array.map((a) => a.indexOf)); |
38 Expect.equals(array.length, set.length); | 38 Expect.equals(array.length, set.length); |
39 set.addAll(array.map((a) => a.indexOf)); | 39 set.addAll(array.map((a) => a.indexOf)); |
40 Expect.equals(array.length, set.length); | 40 Expect.equals(array.length, set.length); |
41 | 41 |
42 for (int i = 0; i < array.length; i += 2) { | 42 for (int i = 0; i < array.length; i += 2) { |
43 Expect.isTrue(set.contains(array[i].indexOf)); | 43 Expect.isTrue(set.contains(array[i].indexOf)); |
44 Expect.equals(array[i], array[i]); | 44 Expect.equals(array[i], array[i]); |
45 Expect.equals(array[i].indexOf, array[i].indexOf); | 45 Expect.equals(array[i].indexOf, array[i].indexOf); |
46 Expect.equals(array[i].indexOf.hashCode, array[i].indexOf.hashCode); | 46 Expect.equals(array[i].indexOf.hashCode, array[i].indexOf.hashCode); |
47 for (int j = 0; j < array.length; j++) { | 47 for (int j = 0; j < array.length; j++) { |
48 if (i == j) continue; | 48 if (i == j) continue; |
49 Expect.notEquals(array[i].indexOf, array[j].indexOf); | 49 Expect.notEquals(array[i].indexOf, array[j].indexOf); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 array = [const A(), const A()]; | 53 array = <dynamic>[const A(), const A()]; |
54 set = new Set.from(array.map((a) => a.foo)); | 54 set = new Set.from(array.map((a) => a.foo)); |
55 Expect.equals(1, set.length); | 55 Expect.equals(1, set.length); |
56 set.addAll(array.map((a) => a.foo)); | 56 set.addAll(array.map((a) => a.foo)); |
57 Expect.equals(1, set.length); | 57 Expect.equals(1, set.length); |
58 | 58 |
59 Expect.isTrue(set.contains(array[0].foo)); | 59 Expect.isTrue(set.contains(array[0].foo)); |
60 Expect.equals(array[0].foo, array[0].foo); | 60 Expect.equals(array[0].foo, array[0].foo); |
61 Expect.equals(array[0].foo.hashCode, array[0].foo.hashCode); | 61 Expect.equals(array[0].foo.hashCode, array[0].foo.hashCode); |
62 Expect.equals(array[0].foo, array[1].foo); | 62 Expect.equals(array[0].foo, array[1].foo); |
63 Expect.equals(array[0].foo.hashCode, array[1].foo.hashCode); | 63 Expect.equals(array[0].foo.hashCode, array[1].foo.hashCode); |
64 | 64 |
65 array = [const [], const []]; | 65 array = <dynamic>[const [], const []]; |
66 set = new Set.from(array.map((a) => a.indexOf)); | 66 set = new Set.from(array.map((a) => a.indexOf)); |
67 Expect.equals(1, set.length); | 67 Expect.equals(1, set.length); |
68 set.addAll(array.map((a) => a.indexOf)); | 68 set.addAll(array.map((a) => a.indexOf)); |
69 Expect.equals(1, set.length); | 69 Expect.equals(1, set.length); |
70 | 70 |
71 Expect.isTrue(set.contains(array[0].indexOf)); | 71 Expect.isTrue(set.contains(array[0].indexOf)); |
72 Expect.equals(array[0].indexOf, array[0].indexOf); | 72 Expect.equals(array[0].indexOf, array[0].indexOf); |
73 Expect.equals(array[0].indexOf.hashCode, array[0].indexOf.hashCode); | 73 Expect.equals(array[0].indexOf.hashCode, array[0].indexOf.hashCode); |
74 Expect.equals(array[0].indexOf, array[1].indexOf); | 74 Expect.equals(array[0].indexOf, array[1].indexOf); |
75 Expect.equals(array[0].indexOf.hashCode, array[1].indexOf.hashCode); | 75 Expect.equals(array[0].indexOf.hashCode, array[1].indexOf.hashCode); |
76 } | 76 } |
OLD | NEW |