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 library matcher.numeric_matchers_test; | 5 library matcher.numeric_matchers_test; |
6 | 6 |
7 import 'package:matcher/matcher.dart'; | 7 import 'package:matcher/matcher.dart'; |
8 import 'package:unittest/unittest.dart' show test, group; | 8 import 'package:unittest/unittest.dart' show test, group; |
9 | 9 |
10 import 'test_utils.dart'; | 10 import 'test_utils.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 initUtils(); | 13 initUtils(); |
14 | 14 |
15 test('greaterThan', () { | 15 test('greaterThan', () { |
16 shouldPass(10, greaterThan(9)); | 16 shouldPass(10, greaterThan(9)); |
17 shouldFail(9, greaterThan(10), | 17 shouldFail(9, greaterThan(10), "Expected: a value greater than <10> " |
18 "Expected: a value greater than <10> " | 18 "Actual: <9> " |
19 "Actual: <9> " | 19 "Which: is not a value greater than <10>"); |
20 "Which: is not a value greater than <10>"); | |
21 }); | 20 }); |
22 | 21 |
23 test('greaterThanOrEqualTo', () { | 22 test('greaterThanOrEqualTo', () { |
24 shouldPass(10, greaterThanOrEqualTo(10)); | 23 shouldPass(10, greaterThanOrEqualTo(10)); |
25 shouldFail(9, greaterThanOrEqualTo(10), | 24 shouldFail(9, greaterThanOrEqualTo(10), |
26 "Expected: a value greater than or equal to <10> " | 25 "Expected: a value greater than or equal to <10> " |
27 "Actual: <9> " | 26 "Actual: <9> " |
28 "Which: is not a value greater than or equal to <10>"); | 27 "Which: is not a value greater than or equal to <10>"); |
29 }); | 28 }); |
30 | 29 |
31 test('lessThan', () { | 30 test('lessThan', () { |
32 shouldFail(10, lessThan(9), | 31 shouldFail(10, lessThan(9), "Expected: a value less than <9> " |
33 "Expected: a value less than <9> " | |
34 "Actual: <10> " | 32 "Actual: <10> " |
35 "Which: is not a value less than <9>"); | 33 "Which: is not a value less than <9>"); |
36 shouldPass(9, lessThan(10)); | 34 shouldPass(9, lessThan(10)); |
37 }); | 35 }); |
38 | 36 |
39 test('lessThanOrEqualTo', () { | 37 test('lessThanOrEqualTo', () { |
40 shouldPass(10, lessThanOrEqualTo(10)); | 38 shouldPass(10, lessThanOrEqualTo(10)); |
41 shouldFail(11, lessThanOrEqualTo(10), | 39 shouldFail(11, lessThanOrEqualTo(10), |
42 "Expected: a value less than or equal to <10> " | 40 "Expected: a value less than or equal to <10> " |
43 "Actual: <11> " | 41 "Actual: <11> " |
44 "Which: is not a value less than or equal to <10>"); | 42 "Which: is not a value less than or equal to <10>"); |
45 }); | 43 }); |
46 | 44 |
47 test('isZero', () { | 45 test('isZero', () { |
48 shouldPass(0, isZero); | 46 shouldPass(0, isZero); |
49 shouldFail(1, isZero, | 47 shouldFail(1, isZero, "Expected: a value equal to <0> " |
50 "Expected: a value equal to <0> " | |
51 "Actual: <1> " | 48 "Actual: <1> " |
52 "Which: is not a value equal to <0>"); | 49 "Which: is not a value equal to <0>"); |
53 }); | 50 }); |
54 | 51 |
55 test('isNonZero', () { | 52 test('isNonZero', () { |
56 shouldFail(0, isNonZero, | 53 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " |
57 "Expected: a value not equal to <0> " | |
58 "Actual: <0> " | 54 "Actual: <0> " |
59 "Which: is not a value not equal to <0>"); | 55 "Which: is not a value not equal to <0>"); |
60 shouldPass(1, isNonZero); | 56 shouldPass(1, isNonZero); |
61 }); | 57 }); |
62 | 58 |
63 test('isPositive', () { | 59 test('isPositive', () { |
64 shouldFail(-1, isPositive, | 60 shouldFail(-1, isPositive, "Expected: a positive value " |
65 "Expected: a positive value " | |
66 "Actual: <-1> " | 61 "Actual: <-1> " |
67 "Which: is not a positive value"); | 62 "Which: is not a positive value"); |
68 shouldFail(0, isPositive, | 63 shouldFail(0, isPositive, "Expected: a positive value " |
69 "Expected: a positive value " | |
70 "Actual: <0> " | 64 "Actual: <0> " |
71 "Which: is not a positive value"); | 65 "Which: is not a positive value"); |
72 shouldPass(1, isPositive); | 66 shouldPass(1, isPositive); |
73 }); | 67 }); |
74 | 68 |
75 test('isNegative', () { | 69 test('isNegative', () { |
76 shouldPass(-1, isNegative); | 70 shouldPass(-1, isNegative); |
77 shouldFail(0, isNegative, | 71 shouldFail(0, isNegative, "Expected: a negative value " |
78 "Expected: a negative value " | |
79 "Actual: <0> " | 72 "Actual: <0> " |
80 "Which: is not a negative value"); | 73 "Which: is not a negative value"); |
81 }); | 74 }); |
82 | 75 |
83 test('isNonPositive', () { | 76 test('isNonPositive', () { |
84 shouldPass(-1, isNonPositive); | 77 shouldPass(-1, isNonPositive); |
85 shouldPass(0, isNonPositive); | 78 shouldPass(0, isNonPositive); |
86 shouldFail(1, isNonPositive, | 79 shouldFail(1, isNonPositive, "Expected: a non-positive value " |
87 "Expected: a non-positive value " | |
88 "Actual: <1> " | 80 "Actual: <1> " |
89 "Which: is not a non-positive value"); | 81 "Which: is not a non-positive value"); |
90 }); | 82 }); |
91 | 83 |
92 test('isNonNegative', () { | 84 test('isNonNegative', () { |
93 shouldPass(1, isNonNegative); | 85 shouldPass(1, isNonNegative); |
94 shouldPass(0, isNonNegative); | 86 shouldPass(0, isNonNegative); |
95 shouldFail(-1, isNonNegative, | 87 shouldFail(-1, isNonNegative, "Expected: a non-negative value " |
96 "Expected: a non-negative value " | 88 "Actual: <-1> " |
97 "Actual: <-1> " | 89 "Which: is not a non-negative value"); |
98 "Which: is not a non-negative value"); | |
99 }); | 90 }); |
100 | 91 |
101 test('closeTo', () { | 92 test('closeTo', () { |
102 shouldPass(0, closeTo(0, 1)); | 93 shouldPass(0, closeTo(0, 1)); |
103 shouldPass(-1, closeTo(0, 1)); | 94 shouldPass(-1, closeTo(0, 1)); |
104 shouldPass(1, closeTo(0, 1)); | 95 shouldPass(1, closeTo(0, 1)); |
105 shouldFail(1.001, closeTo(0, 1), | 96 shouldFail(1.001, closeTo(0, 1), |
106 "Expected: a numeric value within <1> of <0> " | 97 "Expected: a numeric value within <1> of <0> " |
107 "Actual: <1.001> " | 98 "Actual: <1.001> " |
108 "Which: differs by <1.001>"); | 99 "Which: differs by <1.001>"); |
109 shouldFail(-1.001, closeTo(0, 1), | 100 shouldFail(-1.001, closeTo(0, 1), |
110 "Expected: a numeric value within <1> of <0> " | 101 "Expected: a numeric value within <1> of <0> " |
111 "Actual: <-1.001> " | 102 "Actual: <-1.001> " |
112 "Which: differs by <1.001>"); | 103 "Which: differs by <1.001>"); |
113 }); | 104 }); |
114 | 105 |
115 test('inInclusiveRange', () { | 106 test('inInclusiveRange', () { |
116 shouldFail(-1, inInclusiveRange(0,2), | 107 shouldFail(-1, inInclusiveRange(0, 2), |
117 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 108 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
118 "Actual: <-1>"); | 109 "Actual: <-1>"); |
119 shouldPass(0, inInclusiveRange(0,2)); | 110 shouldPass(0, inInclusiveRange(0, 2)); |
120 shouldPass(1, inInclusiveRange(0,2)); | 111 shouldPass(1, inInclusiveRange(0, 2)); |
121 shouldPass(2, inInclusiveRange(0,2)); | 112 shouldPass(2, inInclusiveRange(0, 2)); |
122 shouldFail(3, inInclusiveRange(0,2), | 113 shouldFail(3, inInclusiveRange(0, 2), |
123 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 114 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
124 "Actual: <3>"); | 115 "Actual: <3>"); |
125 }); | 116 }); |
126 | 117 |
127 test('inExclusiveRange', () { | 118 test('inExclusiveRange', () { |
128 shouldFail(0, inExclusiveRange(0,2), | 119 shouldFail(0, inExclusiveRange(0, 2), |
129 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 120 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
130 "Actual: <0>"); | 121 "Actual: <0>"); |
131 shouldPass(1, inExclusiveRange(0,2)); | 122 shouldPass(1, inExclusiveRange(0, 2)); |
132 shouldFail(2, inExclusiveRange(0,2), | 123 shouldFail(2, inExclusiveRange(0, 2), |
133 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 124 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
134 "Actual: <2>"); | 125 "Actual: <2>"); |
135 }); | 126 }); |
136 | 127 |
137 test('inOpenClosedRange', () { | 128 test('inOpenClosedRange', () { |
138 shouldFail(0, inOpenClosedRange(0,2), | 129 shouldFail(0, inOpenClosedRange(0, 2), |
139 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 130 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " |
140 "Actual: <0>"); | 131 "Actual: <0>"); |
141 shouldPass(1, inOpenClosedRange(0,2)); | 132 shouldPass(1, inOpenClosedRange(0, 2)); |
142 shouldPass(2, inOpenClosedRange(0,2)); | 133 shouldPass(2, inOpenClosedRange(0, 2)); |
143 }); | 134 }); |
144 | 135 |
145 test('inClosedOpenRange', () { | 136 test('inClosedOpenRange', () { |
146 shouldPass(0, inClosedOpenRange(0,2)); | 137 shouldPass(0, inClosedOpenRange(0, 2)); |
147 shouldPass(1, inClosedOpenRange(0,2)); | 138 shouldPass(1, inClosedOpenRange(0, 2)); |
148 shouldFail(2, inClosedOpenRange(0,2), | 139 shouldFail(2, inClosedOpenRange(0, 2), |
149 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 140 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " |
150 "Actual: <2>"); | 141 "Actual: <2>"); |
151 }); | 142 }); |
152 } | 143 } |
OLD | NEW |