File: test_mayan.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 (89 lines) | stat: -rw-r--r-- 3,172 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
# -*- coding: utf-8 -*-
import time

from convertdate import gregorian, mayan

from . import CalTestCase


class TestMayan(CalTestCase):
    def setUp(self):
        self.gdate = 2021, 2, 5
        self.c_greg = (1492, 10, 21)
        self.c = gregorian.to_jd(*self.c_greg)
        self.jd = gregorian.to_jd(*self.gdate)
        self.jdcs = range(2159677, 2488395, 2000)

    def test_mayan_reflexive(self):
        assert self.jd == mayan.to_jd(*mayan.from_jd(self.jd))

        self.reflexive(mayan)

    def test_mayan_count(self):
        assert mayan.to_jd(13, 0, 0, 0, 0) == 2456282.5
        assert mayan.from_gregorian(2012, 12, 21) == (13, 0, 0, 0, 0)
        assert mayan.to_gregorian(13, 0, 0, 0, 0) == (2012, 12, 21)
        assert mayan.from_jd(self.c) == (11, 13, 12, 4, 13)

    def test_mayan_haab(self):
        # haab
        assert mayan.HAAB[2] == 'Zip'
        assert mayan.HAAB.index("Xul") == 5
        assert mayan.to_haab(self.c) == (16, "Sotz'")
        assert mayan.to_haab(2456282.5) == (3, "K'ank'in")

    def test_mayan_tzolkin(self):
        # tzolkin
        assert mayan.TZOLKIN[0] == "Imix'"
        assert mayan.to_tzolkin(self.c) == (12, "B'en")
        assert mayan.to_tzolkin(2456282.5) == (4, 'Ajaw')
        assert mayan.to_tzolkin(2456850.5) == (13, 'Lamat')

    def test_mayan_convenience(self):

        self.assertEqual(mayan.lc_to_haab(0, 0, 0, 0, 0), (8, "Kumk'u"))
        assert mayan.lc_to_tzolkin(0, 0, 0, 0, 0) == (4, "Ajaw")

        assert mayan.lc_to_tzolkin(9, 16, 12, 5, 17) == (6, "Kab'an")
        assert mayan.lc_to_haab(9, 16, 12, 5, 17) == (10, "Mol")

        assert mayan.lc_to_haab_tzolkin(9, 16, 12, 5, 17) == "6 Kab'an 10 Mol"

        assert mayan.translate_haab("Wayeb'") == 'Nameless'

    def test_mayan_predictions(self):
        assert mayan.next_haab("Sotz'", self.c) == 2266280.5

        for h in mayan.HAAB:
            assert mayan.to_haab(mayan.next_haab(h, self.c)) == (1, h)

        assert mayan.next_tzolkin_haab((13, "Ajaw"), (3, "Kumk'u"), 2456849.5) == 2463662.5

    def test_mayan_monthcalendar(self):
        calendar = mayan.haab_monthcalendar(13, 0, 2, 11, 13)
        row = calendar[0]
        square = row[-1]
        assert isinstance(row, list)
        assert isinstance(square, tuple)
        assert row[7][0] == 1

        assert mayan.to_jd(*calendar[-1][-1][-1]) == 19 + mayan.to_jd(13, 0, 2, 11, 13)
        self.assertEqual(square, (6, (13, "Etz'nab'"), (13, 0, 2, 11, 18)))

    def test_mayan_generators(self):
        lcg = mayan.longcount_generator(13, 0, 2, 11, 13)
        assert next(lcg) == (13, 0, 2, 11, 13)
        assert next(lcg) == (13, 0, 2, 11, 14)
        assert next(lcg) == (13, 0, 2, 11, 15)

        tzg = mayan.tzolkin_generator(9, "Ix")
        self.assertEqual(next(tzg), (9, "Ix"))
        assert next(tzg) == (10, "Men")
        assert next(tzg) == (11, "K'ib'")

    def test_start_epoch(self):
        self.assertSequenceEqual(mayan.from_jd(mayan.EPOCH + 1), (0, 0, 0, 0, 1))
        self.assertSequenceEqual(mayan.from_jd(mayan.EPOCH), (0, 0, 0, 0, 0))

        with self.assertRaises(ValueError):
            mayan.from_jd(mayan.EPOCH - 1)