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