def test_number_matcher_less_than(self): '''Test NumberMatcher class for less than, ie <0''' nm = NumberMatcher('<0', False) self.assertTrue(nm.match('-1')) self.assertFalse(nm.match('0')) self.assertFalse(nm.match('1')) nm = NumberMatcher('<-20', True) self.assertTrue(nm.match('-21')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1'))
def test_number_matcher_not_equal(self): '''Test NumberMatcher class for contrived not equal, ie !=0''' nm = NumberMatcher('!=0', False) self.assertFalse(nm.match('0')) self.assertTrue(nm.match('1')) self.assertTrue(nm.match('-1')) nm = NumberMatcher('!=-20', False) self.assertFalse(nm.match('-20')) self.assertTrue(nm.match('1')) self.assertTrue(nm.match('-1'))
def test_number_matcher_equal(self): '''Test NumberMatcher class for equality, ie ==0''' nm = NumberMatcher('==0', False) self.assertTrue(nm.match('0')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1')) nm = NumberMatcher('==-20', False) self.assertTrue(nm.match('-20')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1'))
def test_number_matcher_contrived_equal(self): '''Test NumberMatcher class for contrived equality, ie 0 instead of ==0''' nm = NumberMatcher('0', False) self.assertTrue(nm.match('0')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1')) nm = NumberMatcher('-20', False) self.assertTrue(nm.match('-20')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1'))
def test_number_matcher_greater_than(self): '''Test NumberMatcher class for greater than, ie >0''' nm = NumberMatcher('>0', True) self.assertTrue(nm.match('1')) self.assertFalse(nm.match('0')) self.assertFalse(nm.match('-1')) nm = NumberMatcher('>-20', False) self.assertTrue(nm.match('-19')) self.assertTrue(nm.match('20')) self.assertFalse(nm.match('-20')) self.assertFalse(nm.match('-21'))
def test_number_matcher_less_than_equal(self): '''Test NumberMatcher class for less than or equal to, ie <=0''' nm = NumberMatcher('<=0', False) self.assertTrue(nm.match('-1')) self.assertTrue(nm.match('0')) self.assertFalse(nm.match('1')) nm = NumberMatcher('<=-20', False) self.assertTrue(nm.match('-21')) self.assertTrue(nm.match('-20')) self.assertFalse(nm.match('1')) self.assertFalse(nm.match('-1'))
def test_number_matcher_greater_than_equal(self): '''Test NumberMatcher class for greater than or equal to, ie >=0''' nm = NumberMatcher('>=0', False) self.assertTrue(nm.match('1')) self.assertTrue(nm.match('0')) self.assertFalse(nm.match('-1')) # hex handling nm = NumberMatcher('>=-0x20', True) self.assertTrue(nm.match('-0x19')) self.assertTrue(nm.match('0x20')) self.assertTrue(nm.match('-0x20')) self.assertFalse(nm.match('-0x21'))
def test_number_matcher_invalid_operators(self): '''Test NumberMatcher class for bad number strings''' with self.assertRaises(ValueError): NumberMatcher('', False) with self.assertRaises(ValueError): NumberMatcher('lkshfskljdhhf', False) with self.assertRaises(ValueError): NumberMatcher('=)', False) with self.assertRaises(ValueError): NumberMatcher('#=', False) # no numbers with self.assertRaises(ValueError): NumberMatcher('==', False)