|
1
|
|
|
if __name__ == '__main__': |
|
2
|
|
|
import sys |
|
3
|
|
|
sys.path.insert(0, '..') |
|
4
|
|
|
sys.path.insert(0, '../..') |
|
5
|
|
|
|
|
6
|
|
|
from hamcrest.library.number.ordering_comparison import * |
|
7
|
|
|
|
|
8
|
|
|
from datetime import date |
|
9
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
|
10
|
|
|
import unittest |
|
11
|
|
|
|
|
12
|
|
|
__author__ = "Jon Reid" |
|
13
|
|
|
__copyright__ = "Copyright 2011 hamcrest.org" |
|
14
|
|
|
__license__ = "BSD, see License.txt" |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class OrderingComparisonTest(MatcherTest): |
|
18
|
|
|
|
|
19
|
|
|
def testComparesObjectsForGreaterThan(self): |
|
20
|
|
|
self.assert_matches('match', greater_than(1), 2) |
|
21
|
|
|
self.assert_does_not_match('no match', greater_than(1), 1) |
|
22
|
|
|
|
|
23
|
|
|
def testComparesObjectsForLessThan(self): |
|
24
|
|
|
self.assert_matches('match', less_than(1), 0) |
|
25
|
|
|
self.assert_does_not_match('no match', less_than(1), 1) |
|
26
|
|
|
|
|
27
|
|
|
def testComparesObjectsForGreaterThanOrEqualTo(self): |
|
28
|
|
|
self.assert_matches('match', greater_than_or_equal_to(1), 2) |
|
29
|
|
|
self.assert_matches('match', greater_than_or_equal_to(1), 1) |
|
30
|
|
|
self.assert_does_not_match('no match', greater_than_or_equal_to(1), 0) |
|
31
|
|
|
|
|
32
|
|
|
def testComparesObjectsForLessThanOrEqualTo(self): |
|
33
|
|
|
self.assert_matches('match', less_than_or_equal_to(1), 0) |
|
34
|
|
|
self.assert_matches('match', less_than_or_equal_to(1), 1) |
|
35
|
|
|
self.assert_does_not_match('no match', less_than_or_equal_to(1), 2) |
|
36
|
|
|
|
|
37
|
|
|
def testSupportsDifferentTypesOfComparableObjects(self): |
|
38
|
|
|
self.assert_matches('strings', greater_than('bb'), 'cc') |
|
39
|
|
|
self.assert_matches('dates', less_than(date.today()), date.min) |
|
40
|
|
|
|
|
41
|
|
|
def testHasAReadableDescription(self): |
|
42
|
|
|
self.assert_description('a value greater than <1>', greater_than(1)) |
|
43
|
|
|
self.assert_description('a value greater than or equal to <1>', |
|
44
|
|
|
greater_than_or_equal_to(1)) |
|
45
|
|
|
self.assert_description('a value less than <1>', less_than(1)) |
|
46
|
|
|
self.assert_description('a value less than or equal to <1>', |
|
47
|
|
|
less_than_or_equal_to(1)) |
|
48
|
|
|
|
|
49
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
|
50
|
|
|
self.assert_no_mismatch_description(greater_than(1), 2) |
|
51
|
|
|
self.assert_no_mismatch_description(less_than(1), 0) |
|
52
|
|
|
self.assert_no_mismatch_description(greater_than_or_equal_to(1), 1) |
|
53
|
|
|
self.assert_no_mismatch_description(less_than_or_equal_to(1), 1) |
|
54
|
|
|
|
|
55
|
|
|
def testMismatchDescription(self): |
|
56
|
|
|
self.assert_mismatch_description("was <0>", greater_than(1), 0) |
|
57
|
|
|
self.assert_mismatch_description("was <2>", less_than(1), 2) |
|
58
|
|
|
self.assert_mismatch_description("was <0>", |
|
59
|
|
|
greater_than_or_equal_to(1), 0) |
|
60
|
|
|
self.assert_mismatch_description("was <2>", |
|
61
|
|
|
less_than_or_equal_to(1), 2) |
|
62
|
|
|
|
|
63
|
|
|
def testDescribeMismatch(self): |
|
64
|
|
|
self.assert_describe_mismatch("was <0>", greater_than(1), 0) |
|
65
|
|
|
self.assert_describe_mismatch("was <2>", less_than(1), 2) |
|
66
|
|
|
self.assert_describe_mismatch("was <0>", |
|
67
|
|
|
greater_than_or_equal_to(1), 0) |
|
68
|
|
|
self.assert_describe_mismatch("was <2>", less_than_or_equal_to(1), 2) |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
if __name__ == '__main__': |
|
72
|
|
|
unittest.main() |
|
73
|
|
|
|