added missing tests

This commit is contained in:
PyryL 2022-12-12 20:15:46 +02:00
parent 14f4b09927
commit 5081fd4060
3 changed files with 13 additions and 2 deletions

View File

@ -20,9 +20,9 @@ class FixedDate:
date: datetime.date = None,
day_of_year: int = None,
year: int = None) -> None:
if date is not None:
if isinstance(date, datetime.date):
init_tuple = self._from_datetime(date)
elif day_of_year is not None and year is not None:
elif isinstance(day_of_year, int) and isinstance(year, int):
init_tuple = self._from_day_of_year(day_of_year, year)
else:
raise ValueError("Invalid FixedDate initialization")

View File

@ -80,3 +80,10 @@ class TestBasicDateInit(unittest.TestCase):
def test_today(self):
fixed_date_datetime = FixedDate.today().date
self.assertEqual(fixed_date_datetime, datetime.date.today())
def test_init_with_invalid_parameter_type(self):
self.assertRaises(ValueError, lambda : FixedDate(date="today"))
def test_init_with_invalid_parameter_combination(self):
# day_of_year also requires year parameter
self.assertRaises(ValueError, lambda : FixedDate(day_of_year=15))

View File

@ -16,6 +16,10 @@ class TestOperations(unittest.TestCase):
def test_greather_than_with_true_expected(self):
self.assertTrue(self.fixed2 > self.fixed1)
def test_greather_than_with_different_years(self):
another_year = FixedDate(date=datetime.date(2023, 12, 5))
self.assertTrue(another_year > self.fixed1)
def test_greather_than_with_false_expected(self):
self.assertFalse(self.fixed1 > self.fixed2)