예제 #1
0
 def test_numeric_type_validates_and_casts_decimal(self):
     ten_dec = Decimal(10)
     ten_int = 10
     ten_float = 10.0
     ten_long = int(10)  # long and int are same in python3
     ten_var_dec = NumericType(ten_dec)  # this should not throw an exception
     ten_var_int = NumericType(ten_int)
     ten_var_float = NumericType(ten_float)
     ten_var_long = NumericType(ten_long)
     self.assertTrue(isinstance(ten_var_dec.value, Decimal))
     self.assertTrue(isinstance(ten_var_int.value, Decimal))
     self.assertTrue(isinstance(ten_var_float.value, Decimal))
     self.assertTrue(isinstance(ten_var_long.value, Decimal))
예제 #2
0
 def test_numeric_equal_to(self):
     self.assertTrue(NumericType(10).equal_to(10))
     self.assertTrue(NumericType(10).equal_to(10.0))
     self.assertTrue(NumericType(10).equal_to(10.000001))
     self.assertTrue(NumericType(10.000001).equal_to(10))
     self.assertTrue(NumericType(Decimal('10.0')).equal_to(10))
     self.assertTrue(NumericType(10).equal_to(Decimal('10.0')))
     self.assertFalse(NumericType(10).equal_to(10.00001))
     self.assertFalse(NumericType(10).equal_to(11))
예제 #3
0
 def test_numeric_greater_than_or_equal_to(self):
     self.assertTrue(NumericType(10).greater_than_or_equal_to(1))
     self.assertFalse(NumericType(10).greater_than_or_equal_to(11))
     self.assertTrue(NumericType(10.1).greater_than_or_equal_to(10))
     self.assertTrue(NumericType(10.000001).greater_than_or_equal_to(10))
     self.assertTrue(NumericType(10.000002).greater_than_or_equal_to(10))
     self.assertTrue(NumericType(10).greater_than_or_equal_to(10))
예제 #4
0
 def test_other_value_not_numeric(self):
     error_string = "10 is not a valid numeric type"
     with self.assertRaisesRegex(AssertionError, error_string):
         NumericType(10).equal_to("10")
예제 #5
0
 def test_instantiate(self):
     err_string = "foo is not a valid numeric type"
     with self.assertRaisesRegex(AssertionError, err_string):
         NumericType("foo")
예제 #6
0
 def test_numeric_less_than(self):
     self.assertTrue(NumericType(1).less_than(10))
     self.assertFalse(NumericType(11).less_than(10))
     self.assertTrue(NumericType(10).less_than(10.1))
     self.assertFalse(NumericType(10).less_than(10.000001))
     self.assertTrue(NumericType(10).less_than(10.000002))