Completed
Pull Request — master (#77)
by
unknown
33s
created

OrderingComparisonTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testComparesObjectsForLessThan() 0 3 1
A testComparesObjectsForGreaterThanOrEqualTo() 0 4 1
A testMismatchDescription() 0 7 1
A testComparesObjectsForLessThanOrEqualTo() 0 4 1
A testSupportsDifferentTypesOfComparableObjects() 0 3 1
A testDescribeMismatch() 0 6 1
A testHasAReadableDescription() 0 7 1
A testComparesObjectsForGreaterThan() 0 3 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 0 5 1
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