1if __name__ == "__main__": 2 import sys 3 4 sys.path.insert(0, "..") 5 sys.path.insert(0, "../..") 6 7import unittest 8from datetime import date 9 10from hamcrest.library.number.ordering_comparison import * 11from hamcrest_unit_test.matcher_test import MatcherTest 12 13__author__ = "Jon Reid" 14__copyright__ = "Copyright 2011 hamcrest.org" 15__license__ = "BSD, see License.txt" 16 17 18class OrderingComparisonTest(MatcherTest): 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>", greater_than_or_equal_to(1)) 44 self.assert_description("a value less than <1>", less_than(1)) 45 self.assert_description("a value less than or equal to <1>", less_than_or_equal_to(1)) 46 47 def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): 48 self.assert_no_mismatch_description(greater_than(1), 2) 49 self.assert_no_mismatch_description(less_than(1), 0) 50 self.assert_no_mismatch_description(greater_than_or_equal_to(1), 1) 51 self.assert_no_mismatch_description(less_than_or_equal_to(1), 1) 52 53 def testMismatchDescription(self): 54 self.assert_mismatch_description("was <0>", greater_than(1), 0) 55 self.assert_mismatch_description("was <2>", less_than(1), 2) 56 self.assert_mismatch_description("was <0>", greater_than_or_equal_to(1), 0) 57 self.assert_mismatch_description("was <2>", less_than_or_equal_to(1), 2) 58 59 def testDescribeMismatch(self): 60 self.assert_describe_mismatch("was <0>", greater_than(1), 0) 61 self.assert_describe_mismatch("was <2>", less_than(1), 2) 62 self.assert_describe_mismatch("was <0>", greater_than_or_equal_to(1), 0) 63 self.assert_describe_mismatch("was <2>", less_than_or_equal_to(1), 2) 64 65 66if __name__ == "__main__": 67 unittest.main() 68