-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
110 lines (96 loc) · 4.55 KB
/
tests.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import unittest
from antiquity import *
class TestDate(unittest.TestCase):
# test data from http://www.fourmilab.ch/documents/calendar/
def setUp(self):
self.real_dates = {
'great_fire_of_london': {
'gregorian_date': (1666,9,12), # Paris
'julian_date': (1666,9,2), # London
'julian_day': 2329808.5,
'mod_julian_day': -70192,
'weekday': 6,
},
'october_revolution': {
'gregorian_date': (1917,11,7), # the West (actually November)
'julian_date': (1917,10,25), # Petrograd
'julian_day': 2421539.5,
'mod_julian_day': 21539,
'weekday': 2,
},
'invasion_day': {
'gregorian_date': (1788,1,26), # Sydney
'julian_date': (1788,1,15), # Bulgaria and Russia
'julian_day': 2374138.5,
'mod_julian_day': -25862,
'weekday': 5,
},
'nick_drake': {
'gregorian_date': (1974,11,25),
'julian_date': (1974,11,12), # Berbers and Mt Athos only
'julian_day': 2442376.5,
'mod_julian_day': 42376,
'weekday': 0,
}
}
self.fire = PGDate(*self.real_dates['great_fire_of_london']['gregorian_date'])
self.october = PGDate(*self.real_dates['october_revolution']['gregorian_date'])
self.invasion = PGDate(*self.real_dates['invasion_day']['gregorian_date'])
self.drake = PGDate(*self.real_dates['nick_drake']['gregorian_date'])
self.impossible_dates = (
(0,1,24),
(2012,0,15),
(2012,13,8),
# (2012,9,0), # haven't figured out how to validate days yet
# (2012,9,31),
# (2011,2,29),
)
def test_impossible_dates(self):
# this doesn't indicate which one failed
for test_date in self.impossible_dates:
self.assertRaises(ValueError, lambda: PGDate(*test_date))
def test_leap_years(self):
leap_day = PGDate(2012,2,29)
# bad_day = PGDate(2011,2,29) # this should actually fail
def test_PJDay_to_PGDate(self):
for value in self.real_dates.values():
self.assertEqual(PJDay(days=value['julian_day']), PGDate(*value['gregorian_date']))
def test_leapiness(self):
self.assertEqual(PGDate(1964,1,1).leap_year, True)
self.assertEqual(PGDate(1963,1,1).leap_year, False)
self.assertEqual(PGDate(1900,1,1).leap_year, False)
self.assertEqual(PGDate(2000,1,1).leap_year, True)
self.assertEqual(PGDate(2011,1,1).year_length, 365)
self.assertEqual(PGDate(2012,1,1).year_length, 366)
def test_month_length(self):
self.assertEqual(PGDate(1964,1,1).month_length, 31)
self.assertEqual(PGDate(1964,2,1).month_length, 29)
self.assertEqual(PGDate(1963,2,1).month_length, 28)
self.assertEqual(PGDate(1964,3,1).month_length, 31)
self.assertEqual(PGDate(1964,4,1).month_length, 30)
self.assertEqual(PGDate(1964,5,1).month_length, 31)
self.assertEqual(PGDate(1964,6,1).month_length, 30)
self.assertEqual(PGDate(1964,7,1).month_length, 31)
self.assertEqual(PGDate(1964,8,1).month_length, 31)
self.assertEqual(PGDate(1964,9,1).month_length, 30)
self.assertEqual(PGDate(1964,10,1).month_length, 31)
self.assertEqual(PGDate(1964,11,1).month_length, 30)
self.assertEqual(PGDate(1964,12,1).month_length, 31)
def test_comparison(self):
self.assertTrue(self.drake > self.invasion)
self.assertTrue(self.fire < self.october)
self.assertTrue(PGDate(-400,3,4) > PGDate(-500,1,1))
self.assertTrue(FuzzyPGDate(1930) > FuzzyPGDate(1820))
sorted_dates = sorted([self.drake, self.invasion, self.fire, self.october])
self.assertEquals(sorted_dates[0], self.fire)
self.assertEquals(sorted_dates[3], self.drake)
def test_weekdays(self):
for value in self.real_dates.values():
self.assertEqual(PJDay(days=value['julian_day']).weekday, value['weekday'])
# def test_centuries(self):
# self.assertEqual(self.last_day_of_20thC.century, 20)
# self.assertEqual(self.first_day_of_21stC.century, 21)
# self.assertEqual(self.last_day_of_1stC_BC.century, -1)
# self.assertEqual(self.first_day_of_1stC_BC.century, -1)
if __name__ == '__main__':
unittest.main()