OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Tests for the contains methods on lists. | 5 // Tests for the contains methods on lists. |
6 | 6 |
7 test(list, notInList) { | 7 test(list, notInList) { |
8 testList(list) { | 8 testList(list) { |
9 for (int i = 0; i < list.length; i++) { | 9 for (int i = 0; i < list.length; i++) { |
10 var elem = list[i]; | 10 var elem = list[i]; |
11 Expect.isTrue(list.contains(list[i]), "$list.contains($elem)"); | 11 Expect.isTrue(list.contains(list[i]), "$list.contains($elem)"); |
12 } | 12 } |
13 Expect.isFalse(list.contains(notInList), "!$list.contains($notInList)"); | 13 Expect.isFalse(list.contains(notInList), "!$list.contains($notInList)"); |
14 } | 14 } |
15 List fixedList = new List(list.length); | 15 List fixedList = new List.fixedLength(list.length); |
16 List growList = new List(); | 16 List growList = new List(); |
17 for (int i = 0; i < list.length; i++) { | 17 for (int i = 0; i < list.length; i++) { |
18 fixedList[i] = list[i]; | 18 fixedList[i] = list[i]; |
19 growList.add(list[i]); | 19 growList.add(list[i]); |
20 } | 20 } |
21 testList(list); | 21 testList(list); |
22 testList(fixedList); | 22 testList(fixedList); |
23 testList(growList); | 23 testList(growList); |
24 } | 24 } |
25 | 25 |
(...skipping 10 matching lines...) Expand all Loading... |
36 test(const <int>[1, 2, 3, null], 0); | 36 test(const <int>[1, 2, 3, null], 0); |
37 test(const <bool>[true, false], null); | 37 test(const <bool>[true, false], null); |
38 test(const <C>[const C(), const C(), null], new C()); | 38 test(const <C>[const C(), const C(), null], new C()); |
39 test(<C>[new C(), new C(), new C(), null], new C()); | 39 test(<C>[new C(), new C(), new C(), null], new C()); |
40 test(const <double>[ 0.0, 1.0, 5e-324, 1e+308, double.INFINITY ], 2.0); | 40 test(const <double>[ 0.0, 1.0, 5e-324, 1e+308, double.INFINITY ], 2.0); |
41 Expect.isTrue(const <double>[-0.0].contains(0.0)); | 41 Expect.isTrue(const <double>[-0.0].contains(0.0)); |
42 Expect.isFalse(const <double>[double.NAN].contains(double.NAN)); | 42 Expect.isFalse(const <double>[double.NAN].contains(double.NAN)); |
43 var niet = new Niet(); | 43 var niet = new Niet(); |
44 Expect.isFalse([niet].contains(niet)); | 44 Expect.isFalse([niet].contains(niet)); |
45 } | 45 } |
OLD | NEW |