|
| 1 | +import unittest |
| 2 | + |
| 3 | +from pyvalueobjects.errors.ValueObjectError import ValueObjectError |
| 4 | +from pyvalueobjects.numbers.nullable_negative_int import NullableNegativeInt |
| 5 | + |
| 6 | + |
| 7 | +class TestNullableNegativeIntValueObject(unittest.TestCase): |
| 8 | + def test_value_raises_error(self): |
| 9 | + self.assertRaises(ValueObjectError, NullableNegativeInt, 39) |
| 10 | + |
| 11 | + def test_from_string_method_raises_error(self): |
| 12 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_str, '39') |
| 13 | + |
| 14 | + def test_from_float_method_raises_error(self): |
| 15 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_float, 39.0) |
| 16 | + |
| 17 | + def test_zero_value_return_input_value(self): |
| 18 | + self.assertRaises(ValueObjectError, NullableNegativeInt, 0) |
| 19 | + |
| 20 | + def test_zero_from_string_method_returns_int(self): |
| 21 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_str, '0') |
| 22 | + |
| 23 | + def test_zero_from_float_method_returns_int(self): |
| 24 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_float, 0.0) |
| 25 | + |
| 26 | + def test_negative_value_return_input_value(self): |
| 27 | + vo = NullableNegativeInt(-39) |
| 28 | + self.assertEqual(-39, vo.value()) |
| 29 | + |
| 30 | + def test_from_string_method_returns_negative_int(self): |
| 31 | + vo = NullableNegativeInt.from_str('-39') |
| 32 | + self.assertEqual(-39, vo.value()) |
| 33 | + |
| 34 | + def test_from_float_method_returns_negative_int(self): |
| 35 | + vo = NullableNegativeInt.from_float(-39.0) |
| 36 | + self.assertEqual(-39, vo.value()) |
| 37 | + |
| 38 | + def test_from_string_with_not_numerical_format_raise_error(self): |
| 39 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_str, 'patata') |
| 40 | + |
| 41 | + def test_from_float_with_decimals_raise_error(self): |
| 42 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_float, 39.1) |
| 43 | + |
| 44 | + def test_from_str_number_with_no_decimals(self): |
| 45 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_str, '39.0') |
| 46 | + |
| 47 | + def test_from_str_negative_number_with_no_decimals(self): |
| 48 | + vo = NullableNegativeInt.from_str('-39.0') |
| 49 | + self.assertEqual(-39, vo.value()) |
| 50 | + |
| 51 | + def test_from_str_number_with_decimals_raises_error(self): |
| 52 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_float, '39.1') |
| 53 | + |
| 54 | + def test_from_str_negative_number_with_decimals_raises_error(self): |
| 55 | + self.assertRaises(ValueObjectError, NullableNegativeInt.from_float, '-39.1') |
| 56 | + |
| 57 | + def test_none_value_return_none(self): |
| 58 | + vo = NullableNegativeInt(None) |
| 59 | + self.assertEqual(None, vo.value()) |
0 commit comments