aboutsummaryrefslogtreecommitdiff
path: root/tests/test_angles.py
blob: 44084319bbad0b7d00cb928239fc621097e69d37 (plain)
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
#!/usr/bin/env python3
# *****************************************************************************
# Copyright (C) 2019-2021 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the thcolor project, which is MIT-licensed.
# *****************************************************************************
""" Unit tests for the thcolor color decoding and management module. """

from math import pi

import pytest
from thcolor.angles import *  # NOQA


class TestAngle:
    @pytest.mark.parametrize('fst,snd', (
        (GradiansAngle(.1), GradiansAngle(.2)),
    ))
    def test_not_equal(self, fst, snd):
        assert fst != snd

    @pytest.mark.parametrize('angle,expected', (
        (DegreesAngle(400), DegreesAngle(40)),
        (DegreesAngle(-10), DegreesAngle(350)),
        (TurnsAngle(-1.5), TurnsAngle(1)),
        (RadiansAngle(6 * pi), RadiansAngle(0)),
        (RadiansAngle(7.5 * pi), RadiansAngle(1.5 * pi)),
        (GradiansAngle(-975), GradiansAngle(225)),
    ))
    def test_principal_angles(self, angle, expected):
        return angle.asprincipal() == expected

    @pytest.mark.parametrize('test_input,expected', (
        ('120deg', DegreesAngle(120)),
        ('5rad', RadiansAngle(5)),
        ('3grad', GradiansAngle(3)),
        ('6.turns', TurnsAngle(6)),
        ('355', DegreesAngle(355)),
    ))
    def test_expr(self, test_input, expected):
        angle = Angle.fromtext(test_input)
        assert isinstance(angle, type(expected))
        assert angle == expected


# End of file.