File: test_armenian.py

package info (click to toggle)
convertdate 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: python: 4,440; makefile: 33; sh: 11
file content (123 lines) | stat: -rw-r--r-- 4,239 bytes parent folder | download | duplicates (3)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
import time
import unittest

from convertdate import julianday
from convertdate.armenian import (
    _valid_date,
    from_gregorian,
    from_jd,
    from_julian,
    leap,
    month_length,
    to_gregorian,
    to_jd,
    to_julian,
    tostring,
)

from . import CalTestCase


class TestArmenian(CalTestCase):
    def setUp(self):
        self.now = time.localtime()
        self.today = julianday.from_gregorian(self.now[0], self.now[1], self.now[2])

    def testValidDate(self):
        self.assertTrue(_valid_date(1, 1, 1))

        self.assertTrue(_valid_date(533, 1, 1, method="sarkawag"))

        with self.assertRaises(ValueError):
            _valid_date(401, 1, 1, method="sarkawag")

        with self.assertRaises(ValueError):
            _valid_date(30, 4, 31)

        with self.assertRaises(ValueError):
            _valid_date(536, 13, 6)

        with self.assertRaises(ValueError):
            from_jd(1.5)

        self.assertTrue(_valid_date(536, 13, 6, method="sarkawag"))

    def testReflexive(self):
        self.assertEqual(self.today, to_jd(*from_jd(self.today)))
        self.assertEqual(self.today, to_jd(*from_jd(self.today, "sarkawag"), method="sarkawag"))
        for jd in range(2159677, 2488395, 2000):
            jd = jd + 0.5
            self.assertEqual(jd, to_jd(*from_jd(jd)))
            self.assertEqual(jd, to_jd(*from_jd(jd, "sarkawag"), method="sarkawag"))

    def testLeap(self):
        self.assertEqual(True, leap(600))
        self.assertEqual(False, leap(601))

    def testGregorian(self):
        self.assertEqual((2019, 11, 3), to_gregorian(1469, 4, 14))
        self.assertEqual((1469, 4, 14), from_gregorian(2019, 11, 3))

    def testMonthLength(self):
        self.assertEqual(30, month_length(600, 1))
        self.assertEqual(5, month_length(600, 13))
        self.assertEqual(6, month_length(600, 13, "sarkawag"))

    def testJulian(self):
        cases = [
            # first date of the calendar
            [(1, 1, 1), (552, 7, 11)],
            # last day of the year
            [(1, 13, 5), (553, 7, 10)],
            # leap year moves the calendar
            [(4, 13, 5), (556, 7, 9)],
            [(5, 1, 1), (556, 7, 10)],
            # check month boundaries for an entire year
            [(420, 1, 1), (971, 3, 29)],
            [(420, 1, 30), (971, 4, 27)],
            [(420, 2, 1), (971, 4, 28)],
            [(420, 2, 30), (971, 5, 27)],
            [(420, 3, 1), (971, 5, 28)],
            [(420, 3, 30), (971, 6, 26)],
            [(420, 4, 1), (971, 6, 27)],
            [(420, 4, 30), (971, 7, 26)],
            [(420, 5, 1), (971, 7, 27)],
            [(420, 5, 30), (971, 8, 25)],
            [(420, 6, 1), (971, 8, 26)],
            [(420, 6, 30), (971, 9, 24)],
            [(420, 7, 1), (971, 9, 25)],
            [(420, 7, 30), (971, 10, 24)],
            [(420, 8, 1), (971, 10, 25)],
            [(420, 8, 30), (971, 11, 23)],
            [(420, 9, 1), (971, 11, 24)],
            [(420, 9, 30), (971, 12, 23)],
            [(420, 10, 1), (971, 12, 24)],
            [(420, 10, 30), (972, 1, 22)],
            [(420, 11, 1), (972, 1, 23)],
            [(420, 11, 30), (972, 2, 21)],
            [(420, 12, 1), (972, 2, 22)],
            [(420, 12, 30), (972, 3, 22)],
            [(420, 13, 1), (972, 3, 23)],
            [(420, 13, 5), (972, 3, 27)],
            # check month boundaries around Julian leap year
            [(512, 13, 1), (1064, 2, 29)],
            [(512, 13, 2), (1064, 3, 1)],
            [(513, 1, 1), (1064, 3, 5)],
            # check the two calendars in 1084
            [(533, 6, 15), (1084, 8, 11)],
        ]

        for a, j in cases:
            self.assertEqual(a, from_julian(*j))

        for a, j in cases:
            self.assertEqual(j, to_julian(*a))

        self.assertEqual((533, 1, 1), from_julian(1084, 8, 11, method="sarkawag"))
        self.assertEqual((533, 13, 5), from_julian(1085, 8, 10, method="sarkawag"))
        self.assertEqual((536, 13, 6), from_julian(1088, 8, 10, method="sarkawag"))
        self.assertEqual((537, 1, 1), from_julian(1088, 8, 11, method="sarkawag"))

    def testTostring(self):
        self.assertEqual('14 trē 1469', tostring(1469, 4, 14))