basic operators
This commit is contained in:
parent
3b0f2cfe72
commit
97a5ede24f
@ -108,5 +108,13 @@ class FixedDate:
|
||||
return 4
|
||||
return ((self.day_of_year-1) // 91) + 1
|
||||
|
||||
# TODO: plus and minus operations
|
||||
# TODO: equatable
|
||||
def __eq__(self, o: "FixedDate") -> bool:
|
||||
return self._day_of_year == o.day_of_year and self._year == o.year
|
||||
|
||||
def __gt__(self, o: "FixedDate") -> bool:
|
||||
if self._year == o.year:
|
||||
return self._day_of_year > o.day_of_year
|
||||
return self._year > o.year
|
||||
|
||||
def __sub__(self, o: "FixedDate") -> timedelta:
|
||||
return self.datetime - o.datetime
|
||||
|
35
tests/operations_test.py
Normal file
35
tests/operations_test.py
Normal file
@ -0,0 +1,35 @@
|
||||
import unittest
|
||||
from datetime import datetime, timedelta
|
||||
from fixedcal.core.date import FixedDate
|
||||
|
||||
class TestOperations(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.fixed1 = FixedDate(date=datetime(2022, 12, 5))
|
||||
self.fixed2 = FixedDate(date=datetime(2022, 12, 6))
|
||||
|
||||
def test_equal_with_two_same(self):
|
||||
self.assertTrue(self.fixed1 == self.fixed1)
|
||||
|
||||
def test_equal_with_two_different(self):
|
||||
self.assertFalse(self.fixed1 == self.fixed2)
|
||||
|
||||
def test_greather_than_with_true_expected(self):
|
||||
self.assertTrue(self.fixed2 > self.fixed1)
|
||||
|
||||
def test_greather_than_with_false_expected(self):
|
||||
self.assertFalse(self.fixed1 > self.fixed2)
|
||||
|
||||
def test_greather_than_with_two_same(self):
|
||||
self.assertFalse(self.fixed1 > self.fixed1)
|
||||
|
||||
def test_less_than_with_true_expected(self):
|
||||
self.assertTrue(self.fixed1 < self.fixed2)
|
||||
|
||||
def test_subtration_with_two_different(self):
|
||||
self.assertEqual(self.fixed2-self.fixed1, timedelta(1))
|
||||
|
||||
def test_subtration_with_smaller_first(self):
|
||||
self.assertEqual(self.fixed1-self.fixed2, timedelta(-1))
|
||||
|
||||
def test_subtration_with_two_same(self):
|
||||
self.assertEqual(self.fixed1-self.fixed1, timedelta(0))
|
Loading…
x
Reference in New Issue
Block a user