diff --git a/fixedcal/core/date.py b/fixedcal/core/date.py index e614f64..6f3a99f 100644 --- a/fixedcal/core/date.py +++ b/fixedcal/core/date.py @@ -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") diff --git a/tests/basic_datetime_test.py b/tests/basic_datetime_test.py index 0954922..7cec911 100644 --- a/tests/basic_datetime_test.py +++ b/tests/basic_datetime_test.py @@ -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)) diff --git a/tests/operations_test.py b/tests/operations_test.py index 46142fb..28582ef 100644 --- a/tests/operations_test.py +++ b/tests/operations_test.py @@ -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)