Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 import 'dart:collection'; | |
| 7 | |
| 8 main() { | |
| 9 defaultFunctionValuesTest(); | |
| 10 defaultKeyFunctionTest(); | |
| 11 defaultValueFunctionTest(); | |
| 12 noDefaultValuesTest(); | |
| 13 emptyIterableTest(); | |
| 14 identicalElementsTest(); | |
| 15 } | |
| 16 | |
| 17 void defaultFunctionValuesTest() { | |
| 18 var map = new Map.fromIterable([1, 2, 3]); | |
| 19 | |
| 20 Expect.isTrue(map is Map); | |
| 21 Expect.isTrue(map is HashMap); | |
| 22 | |
| 23 Expect.equals(3, map.length); | |
| 24 Expect.equals(3, map.keys.length); | |
| 25 Expect.equals(3, map.values.length); | |
| 26 | |
| 27 Expect.equals(1, map[1]); | |
| 28 Expect.equals(2, map[2]); | |
| 29 Expect.equals(3, map[3]); | |
| 30 } | |
| 31 | |
| 32 void defaultKeyFunctionTest() { | |
| 33 var map = new Map.fromIterable([1, 2, 3], value: (x) => x + 1); | |
| 34 | |
| 35 Expect.isTrue(map is Map); | |
| 36 Expect.isTrue(map is HashMap); | |
| 37 | |
| 38 Expect.equals(3, map.length); | |
| 39 Expect.equals(3, map.keys.length); | |
| 40 Expect.equals(3, map.values.length); | |
| 41 | |
| 42 Expect.equals(2, map[1]); | |
| 43 Expect.equals(3, map[2]); | |
| 44 Expect.equals(4, map[3]); | |
| 45 } | |
| 46 | |
| 47 void defaultValueFunctionTest() { | |
| 48 var map = new Map.fromIterable([1, 2, 3], key: (x) => x + 1); | |
| 49 | |
| 50 Expect.isTrue(map is Map); | |
| 51 Expect.isTrue(map is HashMap); | |
| 52 print(map.length); | |
|
floitsch
2013/06/27 11:45:04
debug print.
zarah
2013/06/27 13:02:43
Done.
| |
| 53 | |
| 54 Expect.equals(3, map.length); | |
| 55 Expect.equals(3, map.keys.length); | |
| 56 Expect.equals(3, map.values.length); | |
| 57 | |
| 58 Expect.equals(1, map[2]); | |
| 59 Expect.equals(2, map[3]); | |
| 60 Expect.equals(3, map[4]); | |
| 61 } | |
| 62 | |
| 63 void noDefaultValuesTest() { | |
| 64 var map = new Map.fromIterable([1, 2, 3], | |
| 65 key: (x) => x + 1, value: (x) => x - 1); | |
| 66 | |
| 67 | |
| 68 Expect.isTrue(map is Map); | |
| 69 Expect.isTrue(map is HashMap); | |
| 70 | |
| 71 Expect.equals(3, map.length); | |
| 72 Expect.equals(3, map.keys.length); | |
| 73 Expect.equals(3, map.values.length); | |
| 74 | |
| 75 Expect.equals(0, map[2]); | |
| 76 Expect.equals(1, map[3]); | |
| 77 Expect.equals(2, map[4]); | |
| 78 } | |
| 79 | |
| 80 void emptyIterableTest() { | |
| 81 var map = new Map.fromIterable([]); | |
| 82 Expect.isTrue(map is Map); | |
| 83 Expect.isTrue(map is HashMap); | |
| 84 | |
| 85 Expect.equals(0, map.length); | |
| 86 Expect.equals(0, map.keys.length); | |
| 87 Expect.equals(0, map.values.length); | |
| 88 } | |
| 89 | |
| 90 void identicalElementsTest() { | |
| 91 var map = new Map.fromIterable([1, 2, 2], key: (x) => x + 1); | |
| 92 | |
| 93 Expect.isTrue(map is Map); | |
| 94 Expect.isTrue(map is HashMap); | |
| 95 print(map.length); | |
| 96 | |
| 97 Expect.equals(2, map.length); | |
| 98 Expect.equals(2, map.keys.length); | |
| 99 Expect.equals(2, map.values.length); | |
| 100 | |
| 101 Expect.equals(1, map[2]); | |
| 102 Expect.equals(2, map[3]); | |
| 103 } | |
|
floitsch
2013/06/27 11:45:04
Add test that the returned map is of the right gen
zarah
2013/06/27 13:02:43
Done.
| |
| 104 | |
| OLD | NEW |