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

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

Issue 113883002: Create associated packages for the dart:collection and dart:async libs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update SDK dependency to 1.0.0 Created 7 years 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), isTrue);
16 Equality iterId = const IterableEquality(const IdentityEquality());
17 expect(iterId.equals(l1, l2), isFalse); /// 01: ok
18 });
19
20 test("IterableEquality - LinkedSet", () {
21 var l1 = new LinkedHashSet.from([1, 2, 3, 4, 5]);
22 var l2 = new LinkedHashSet.from([1.0, 2.0, 3.0, 4.0, 5.0]);
23 expect(const IterableEquality().equals(l1, l2), isTrue);
24 Equality iterId = const IterableEquality(const IdentityEquality());
25 expect(iterId.equals(l1, l2), isFalse); /// 02: ok
26 });
27
28 test("ListEquality", () {
29 var l1 = [1, 2, 3, 4, 5];
30 var l2 = [1.0, 2.0, 3.0, 4.0, 5.0];
31 expect(const ListEquality().equals(l1, l2),
32 isTrue);
33 Equality listId = const ListEquality(const IdentityEquality());
34 expect(listId.equals(l1, l2), isFalse); /// 03: ok
35 });
36
37 test("ListInequality length", () {
38 var l1 = [1, 2, 3, 4, 5];
39 var l2 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
40 expect(const ListEquality().equals(l1, l2),
41 isFalse);
42 expect(const ListEquality(const IdentityEquality()).equals(l1, l2),
43 isFalse);
44 });
45
46 test("ListInequality value", () {
47 var l1 = [1, 2, 3, 4, 5];
48 var l2 = [1.0, 2.0, 3.0, 4.0, 6.0];
49 expect(const ListEquality().equals(l1, l2),
50 isFalse);
51 expect(const ListEquality(const IdentityEquality()).equals(l1, l2),
52 isFalse);
53 });
54
55 test("UnorderedIterableEquality", () {
56 var l1 = [1, 2, 3, 4, 5];
57 var l2 = [1.0, 3.0, 5.0, 4.0, 2.0];
58 expect(const UnorderedIterableEquality().equals(l1, l2),
59 isTrue);
60 Equality uniterId =
61 const UnorderedIterableEquality(const IdentityEquality());
62 expect(uniterId.equals(l1, l2), isFalse); /// 04: ok
63 });
64
65 test("UnorderedIterableInequality length", () {
66 var l1 = [1, 2, 3, 4, 5];
67 var l2 = [1.0, 3.0, 5.0, 4.0, 2.0, 1.0];
68 expect(const UnorderedIterableEquality().equals(l1, l2),
69 isFalse);
70 expect(const UnorderedIterableEquality(const IdentityEquality())
71 .equals(l1, l2),
72 isFalse);
73 });
74
75 test("UnorderedIterableInequality values", () {
76 var l1 = [1, 2, 3, 4, 5];
77 var l2 = [1.0, 3.0, 5.0, 4.0, 6.0];
78 expect(const UnorderedIterableEquality().equals(l1, l2),
79 isFalse);
80 expect(const UnorderedIterableEquality(const IdentityEquality())
81 .equals(l1, l2),
82 isFalse);
83 });
84
85 test("SetEquality", () {
86 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
87 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 2.0]);
88 expect(const SetEquality().equals(l1, l2),
89 isTrue);
90 Equality setId = const SetEquality(const IdentityEquality());
91 expect(setId.equals(l1, l2), isFalse); /// 05: ok
92 });
93
94 test("SetInequality length", () {
95 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
96 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 2.0, 6.0]);
97 expect(const SetEquality().equals(l1, l2),
98 isFalse);
99 expect(const SetEquality(const IdentityEquality()).equals(l1, l2),
100 isFalse);
101 });
102
103 test("SetInequality value", () {
104 var l1 = new HashSet.from([1, 2, 3, 4, 5]);
105 var l2 = new LinkedHashSet.from([1.0, 3.0, 5.0, 4.0, 6.0]);
106 expect(const SetEquality().equals(l1, l2),
107 isFalse);
108 expect(const SetEquality(const IdentityEquality()).equals(l1, l2),
109 isFalse);
110 });
111
112 var map1a = {"x": [1, 2, 3], "y": [true, false, null]};
113 var map1b = {"x": [4.0, 5.0, 6.0], "y": [false, true, null]};
114 var map2a = {"x": [3.0, 2.0, 1.0], "y": [false, true, null]};
115 var map2b = {"x": [6, 5, 4], "y": [null, false, true]};
116 var l1 = [map1a, map1b];
117 var l2 = [map2a, map2b];
118 var s1 = new Set.from(l1);
119 var s2 = new Set.from([map2b, map2a]);
120
121 test("RecursiveEquality", () {
122 const unordered = const UnorderedIterableEquality();
123 expect(unordered.equals(map1a["x"], map2a["x"]),
124 isTrue);
125 expect(unordered.equals(map1a["y"], map2a["y"]),
126 isTrue);
127 expect(unordered.equals(map1b["x"], map2b["x"]),
128 isTrue);
129 expect(unordered.equals(map1b["y"], map2b["y"]),
130 isTrue);
131 const mapval = const MapEquality(values: unordered);
132 expect(
133 mapval.equals(map1a, map2a),
134 isTrue);
135 expect(mapval.equals(map1b, map2b),
136 isTrue);
137 const listmapval = const ListEquality(mapval);
138 expect(listmapval.equals(l1, l2),
139 isTrue);
140 const setmapval = const SetEquality(mapval);
141 expect(setmapval.equals(s1, s2),
142 isTrue);
143 });
144
145 test("DeepEquality", () {
146 var colleq = const DeepCollectionEquality.unordered();
147 expect(colleq.equals(map1a["x"], map2a["x"]),
148 isTrue);
149 expect(colleq.equals(map1a["y"], map2a["y"]),
150 isTrue);
151 expect(colleq.equals(map1b["x"], map2b["x"]),
152 isTrue);
153 expect(colleq.equals(map1b["y"], map2b["y"]),
154 isTrue);
155 expect(colleq.equals(map1a, map2a),
156 isTrue);
157 expect(colleq.equals(map1b, map2b),
158 isTrue);
159 expect(colleq.equals(l1, l2),
160 isTrue);
161 expect(colleq.equals(s1, s2),
162 isTrue);
163 });
164 }
OLDNEW
« no previous file with comments | « pkg/collection_helpers/test/algorithms_test.dart ('k') | pkg/collection_helpers/test/typed_buffers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698