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:test/test.dart' show test, group; |
| 9 |
| 10 import 'test_utils.dart'; |
| 11 |
| 12 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', () { |
| 91 shouldPass(0, closeTo(0, 1)); |
| 92 shouldPass(-1, closeTo(0, 1)); |
| 93 shouldPass(1, closeTo(0, 1)); |
| 94 shouldFail(1.001, closeTo(0, 1), |
| 95 "Expected: a numeric value within <1> of <0> " |
| 96 "Actual: <1.001> " |
| 97 "Which: differs by <1.001>"); |
| 98 shouldFail(-1.001, closeTo(0, 1), |
| 99 "Expected: a numeric value within <1> of <0> " |
| 100 "Actual: <-1.001> " |
| 101 "Which: differs by <1.001>"); |
| 102 }); |
| 103 |
| 104 test('inInclusiveRange', () { |
| 105 shouldFail(-1, inInclusiveRange(0, 2), |
| 106 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 107 "Actual: <-1>"); |
| 108 shouldPass(0, inInclusiveRange(0, 2)); |
| 109 shouldPass(1, inInclusiveRange(0, 2)); |
| 110 shouldPass(2, inInclusiveRange(0, 2)); |
| 111 shouldFail(3, inInclusiveRange(0, 2), |
| 112 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
| 113 "Actual: <3>"); |
| 114 }); |
| 115 |
| 116 test('inExclusiveRange', () { |
| 117 shouldFail(0, inExclusiveRange(0, 2), |
| 118 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 119 "Actual: <0>"); |
| 120 shouldPass(1, inExclusiveRange(0, 2)); |
| 121 shouldFail(2, inExclusiveRange(0, 2), |
| 122 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
| 123 "Actual: <2>"); |
| 124 }); |
| 125 |
| 126 test('inOpenClosedRange', () { |
| 127 shouldFail(0, inOpenClosedRange(0, 2), |
| 128 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " |
| 129 "Actual: <0>"); |
| 130 shouldPass(1, inOpenClosedRange(0, 2)); |
| 131 shouldPass(2, inOpenClosedRange(0, 2)); |
| 132 }); |
| 133 |
| 134 test('inClosedOpenRange', () { |
| 135 shouldPass(0, inClosedOpenRange(0, 2)); |
| 136 shouldPass(1, inClosedOpenRange(0, 2)); |
| 137 shouldFail(2, inClosedOpenRange(0, 2), |
| 138 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " |
| 139 "Actual: <2>"); |
| 140 }); |
| 141 } |
OLD | NEW |