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