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