Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: pkg/collection_helpers/test/equality_test.dart

Issue 23567044: Add collection-helpers library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changing ~/ 2 to >> 1. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Tests equality utilities.
6
7 import "dart:collection";
8 import "package:collection_helpers/all.dart";
9 import "package:unittest/unittest.dart";
10
11 main() {
12 test("IterableEquality - List", () {
13 var l1 = [1, 2, 3, 4, 5];
14 var l2 = [1.0, 2.0, 3.0, 4.0, 5.0];
15 expect(const IterableEquality().equals(l1, l2),
16 isTrue);
17 expect(const IterableEquality(const IdentityEquality()).equals(l1, l2),
18 isFalse);
floitsch 2013/10/17 12:17:53 This won't work for dart2js. Here and in all other
Lasse Reichstein Nielsen 2013/10/23 11:42:40 Ack. Will mark as failing.
19 });
20
21 test("IterableEquality - LinkedSet", () {
22 var l1 = new LinkedHashSet.from([1, 2, 3, 4, 5]);
23 var l2 = new LinkedHashSet.from([1.0, 2.0, 3.0, 4.0, 5.0]);
24 expect(const IterableEquality().equals(l1, l2),
25 isTrue);
26 expect(const IterableEquality(const IdentityEquality()).equals(l1, l2),
27 isFalse);
28 });
29
30 test("ListEquality", () {
31 var l1 = [1, 2, 3, 4, 5];
32 var l2 = [1.0, 2.0, 3.0, 4.0, 5.0];
33 expect(const ListEquality().equals(l1, l2),
34 isTrue);
35 expect(const ListEquality(const IdentityEquality()).equals(l1, l2),
36 isFalse);
37 });
38
39 test("ListInequality length", () {
40 var l1 = [1, 2, 3, 4, 5];
41 var l2 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
42 expect(const ListEquality().equals(l1, l2),
43 isFalse);
44 expect(const ListEquality(const IdentityEquality()).equals(l1, l2),
45 isFalse);
46 });
47
48 test("ListInequality value", () {
49 var l1 = [1, 2, 3, 4, 5];
50 var l2 = [1.0, 2.0, 3.0, 4.0, 6.0];
51 expect(const ListEquality().equals(l1, l2),
52 isFalse);
53 expect(const ListEquality(const IdentityEquality()).equals(l1, l2),
54 isFalse);
55 });
56
57 test("UnorderedIterableEquality", () {
58 var l1 = [1, 2, 3, 4, 5];
59 var l2 = [1.0, 3.0, 5.0, 4.0, 2.0];
60 expect(const UnorderedIterableEquality().equals(l1, l2),
61 isTrue);
62 expect(const UnorderedIterableEquality(const IdentityEquality())
63 .equals(l1, l2),
64 isFalse);
65 });
66
67 test("UnorderedIterableInequality length", () {
68 var l1 = [1, 2, 3, 4, 5];
69 var l2 = [1.0, 3.0, 5.0, 4.0, 2.0, 1.0];
70 expect(const UnorderedIterableEquality().equals(l1, l2),
71 isFalse);
72 expect(const UnorderedIterableEquality(const IdentityEquality())
73 .equals(l1, l2),
74 isFalse);
75 });
76
77 test("UnorderedIterableInequality values", () {
78 var l1 = [1, 2, 3, 4, 5];
79 var l2 = [1.0, 3.0, 5.0, 4.0, 6.0];
80 expect(const UnorderedIterableEquality().equals(l1, l2),
81 isFalse);
82 expect(const UnorderedIterableEquality(const IdentityEquality())
83 .equals(l1, l2),
84 isFalse);
85 });
86
87 test("SetEquality", () {
88 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
89 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 2.0]);
90 expect(const SetEquality().equals(l1, l2),
91 isTrue);
92 expect(const SetEquality(const IdentityEquality()).equals(l1, l2),
93 isFalse);
94 });
95
96 test("SetInequality length", () {
97 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
98 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 2.0, 6.0]);
99 expect(const SetEquality().equals(l1, l2),
100 isFalse);
101 expect(const SetEquality(const IdentityEquality()).equals(l1, l2),
102 isFalse);
103 });
104
105 test("SetInequality value", () {
106 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
107 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 6.0]);
108 expect(const SetEquality().equals(l1, l2),
109 isFalse);
110 expect(const SetEquality(const IdentityEquality()).equals(l1, l2),
111 isFalse);
112 });
113
114 var map1a = {"x": [1, 2, 3], "y": [true, false, null]};
115 var map1b = {"x": [4.0, 5.0, 6.0], "y": [false, true, null]};
116 var map2a = {"x": [3.0, 2.0, 1.0], "y": [false, true, null]};
117 var map2b = {"x": [6, 5, 4], "y": [null, false, true]};
118 var l1 = [map1a, map1b];
119 var l2 = [map2a, map2b];
120 var s1 = new Set.from(l1);
121 var s2 = new Set.from([map2b, map2a]);
122
123 test("RecursiveEquality", () {
124 const unordered = const UnorderedIterableEquality();
125 expect(unordered.equals(map1a["x"], map2a["x"]),
126 isTrue);
127 expect(unordered.equals(map1a["y"], map2a["y"]),
128 isTrue);
129 expect(unordered.equals(map1b["x"], map2b["x"]),
130 isTrue);
131 expect(unordered.equals(map1b["y"], map2b["y"]),
132 isTrue);
133 const mapval = const MapEquality(values: unordered);
134 expect(
135 mapval.equals(map1a, map2a),
136 isTrue);
137 expect(mapval.equals(map1b, map2b),
138 isTrue);
139 const listmapval = const ListEquality(mapval);
140 expect(listmapval.equals(l1, l2),
141 isTrue);
142 const setmapval = const SetEquality(mapval);
143 expect(setmapval.equals(s1, s2),
144 isTrue);
145 });
146
147 test("DeepEquality", () {
148 var colleq = const DeepCollectionEquality.unordered();
149 expect(colleq.equals(map1a["x"], map2a["x"]),
150 isTrue);
151 expect(colleq.equals(map1a["y"], map2a["y"]),
152 isTrue);
153 expect(colleq.equals(map1b["x"], map2b["x"]),
154 isTrue);
155 expect(colleq.equals(map1b["y"], map2b["y"]),
156 isTrue);
157 expect(colleq.equals(map1a, map2a),
158 isTrue);
159 expect(colleq.equals(map1b, map2b),
160 isTrue);
161 expect(colleq.equals(l1, l2),
162 isTrue);
163 expect(colleq.equals(s1, s2),
164 isTrue);
165 });
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698