Skip to content

Commit 7b5889e

Browse files
committed
Add nullable_negative_or_zero_int_test.py
#15
1 parent 8d74a35 commit 7b5889e

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import unittest
2+
3+
from pyvalueobjects.errors.ValueObjectError import ValueObjectError
4+
from pyvalueobjects.numbers.nullable_negative_or_zero_int import NullableNegativeOrZeroInt
5+
6+
7+
class TestNullableNegativeOrZeroIntValueObject(unittest.TestCase):
8+
def test_value_raises_error(self):
9+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt, 39)
10+
11+
def test_from_string_method_raises_error(self):
12+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_str, '39')
13+
14+
def test_from_float_method_raises_error(self):
15+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_float, 39.0)
16+
17+
def test_zero_value_return_input_value(self):
18+
vo = NullableNegativeOrZeroInt(0)
19+
self.assertEqual(0, vo.value())
20+
21+
def test_zero_from_string_method_returns_int(self):
22+
vo = NullableNegativeOrZeroInt.from_str('0')
23+
self.assertEqual(0, vo.value())
24+
25+
def test_zero_from_float_method_returns_int(self):
26+
vo = NullableNegativeOrZeroInt.from_float(0.0)
27+
self.assertEqual(0, vo.value())
28+
29+
def test_zero_from_string_with_float_format_method_returns_int(self):
30+
vo = NullableNegativeOrZeroInt.from_str('0.0')
31+
self.assertEqual(0, vo.value())
32+
33+
def test_negative_value_return_input_value(self):
34+
vo = NullableNegativeOrZeroInt(-39)
35+
self.assertEqual(-39, vo.value())
36+
37+
def test_from_string_method_returns_negative_int(self):
38+
vo = NullableNegativeOrZeroInt.from_str('-39')
39+
self.assertEqual(-39, vo.value())
40+
41+
def test_from_float_method_returns_negative_int(self):
42+
vo = NullableNegativeOrZeroInt.from_float(-39.0)
43+
self.assertEqual(-39, vo.value())
44+
45+
def test_from_string_with_not_numerical_format_raise_error(self):
46+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_str, 'patata')
47+
48+
def test_from_float_with_decimals_raise_error(self):
49+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_float, 39.1)
50+
51+
def test_from_str_number_with_no_decimals(self):
52+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_str, '39.0')
53+
54+
def test_from_str_negative_number_with_no_decimals(self):
55+
vo = NullableNegativeOrZeroInt.from_str('-39.0')
56+
self.assertEqual(-39, vo.value())
57+
58+
def test_from_str_number_with_decimals_raises_error(self):
59+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_float, '39.1')
60+
61+
def test_from_str_negative_number_with_decimals_raises_error(self):
62+
self.assertRaises(ValueObjectError, NullableNegativeOrZeroInt.from_float, '-39.1')
63+
64+
def test_none_value_return_none(self):
65+
vo = NullableNegativeOrZeroInt(None)
66+
self.assertEqual(None, vo.value())

0 commit comments

Comments
 (0)