forked from EdReingold/calendar-code2
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_roundtrip.py
executable file
·48 lines (36 loc) · 1.69 KB
/
test_roundtrip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import persiancalendar
import persiancalendar_fast
ROUNDTRIP_START_YEAR = 1304
ROUNDTRIP_END_YEAR = 1500
def test_roundtrip_astronomical():
"""Test that the astronomical algorithm roundtrips correctly."""
start = persiancalendar.fixed_from_persian((ROUNDTRIP_START_YEAR, 1, 1))
end = persiancalendar.fixed_from_persian((ROUNDTRIP_END_YEAR, 1, 1))
for date in range(start, end):
p_date = persiancalendar.persian_from_fixed(date)
converted_back = persiancalendar.fixed_from_persian(p_date)
assert (date == converted_back)
def test_roundtrip_fast():
"""Test that the fast algorithm roundtrips correctly."""
start = persiancalendar_fast.fixed_from_persian_fast(
(ROUNDTRIP_START_YEAR, 1, 1))
end = persiancalendar_fast.fixed_from_persian_fast(
(ROUNDTRIP_END_YEAR, 1, 1))
for date in range(start, end):
p_date = persiancalendar_fast.persian_fast_from_fixed(date)
converted_back = persiancalendar_fast.fixed_from_persian_fast(p_date)
assert (date == converted_back)
def test_fast():
"""Test that the results of the fast algorithm matches the results of the astronomical algorithm."""
start = persiancalendar.fixed_from_persian(
(persiancalendar_fast.SUPPORTED_FIRST_YEAR, 1, 1))
end = persiancalendar.fixed_from_persian(
(persiancalendar_fast.SUPPORTED_LAST_YEAR + 1, 1, 1))
for date in range(start, end):
fast_p_date = persiancalendar_fast.persian_fast_from_fixed(date)
astro_p_date = persiancalendar.persian_from_fixed(date)
assert (fast_p_date == astro_p_date)
if __name__ == "__main__":
test_roundtrip_astronomical()
test_roundtrip_fast()
test_fast()