forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distinct_test.dart
91 lines (80 loc) · 1.98 KB
/
distinct_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
main() {
var o1 = new Object();
var o2 = new Object();
var o3 = new Object();
var c1 = new C(0);
var c2 = new C(0);
// Successful checks.
Expect.notIdentical(o1, o2, "msg");
Expect.equals(c1, c2);
Expect.notIdentical(c1, c2, "msg");
Expect.notIdentical([1], [1], "msg");
Expect.allDistinct([], "msg");
Expect.allDistinct([o1], "msg");
Expect.allDistinct([
o1,
o2,
c1,
c2,
[1]
], "msg");
Expect.allDistinct(new List.generate(100, (_) => new Object()));
fails((msg) {
Expect.notIdentical(o1, o1, msg);
});
fails((msg) {
var list = [1];
Expect.notIdentical(list, list, msg);
});
fails((msg) {
Expect.allDistinct([o1, o1], msg);
});
fails((msg) {
Expect.allDistinct([o1, o1, o1, o1], msg);
});
fails((msg) {
Expect.allDistinct([o1, o1, o2, o3], msg);
});
fails((msg) {
Expect.allDistinct([o1, o2, o1, o3], msg);
});
fails((msg) {
Expect.allDistinct([o1, o2, o3, o1], msg);
});
fails((msg) {
Expect.allDistinct([o1, o2, o2, o3], msg);
});
fails((msg) {
Expect.allDistinct([o1, o2, o3, o2], msg);
});
fails((msg) {
Expect.allDistinct([o1, o2, o3, o3], msg);
});
fails((msg) {
var list = new List.generate(100, (_) => new Object());
list.add(list[0]);
Expect.allDistinct(list, msg);
});
}
class C {
final x;
const C(this.x);
int get hashCode => x.hashCode;
bool operator ==(Object other) => other is C && x == other.x;
}
int _ctr = 0;
fails(test(msg)) {
var msg = "__#${_ctr++}#__"; // "Unique" name.
try {
test(msg);
throw "Did not throw!";
} on ExpectException catch (e) {
if (e.message.indexOf(msg) < 0) {
throw "Failure did not contain message: \"$msg\" not in ${e.message}";
}
}
}