1from math import sqrt
2
3import pytest
4
5from .. import shape
6from ..shape import Strip
7
8EPSILON = 0.01
9
10def test_subtract_row_no_subtracts():
11    assert shape._subtract_row([Strip(0, 1, 5)], []) == [Strip(0, 1, 5)]
12
13def test_subtract_row_cut_in_two():
14    # shape  12345
15    #  hole   23
16    # result 1  45
17    assert \
18        shape._subtract_row([Strip(0, 1, 5)], [Strip(0, 2, 2)]) == \
19        [Strip(0, 1, 1), Strip(0, 4, 2)]
20
21def test_disc_radius_lt_0_should_raise():
22    with pytest.raises(ValueError):
23        shape.disc(1, 1, -EPSILON)
24
25def test_disc_radius_0():
26    # r==0 is a special case, blank
27    assert shape.disc(3, 3, 0) == []
28
29def test_disc_radius_lt_1():
30    # 0 <  r < 1:                #
31    # (Irregular compared to all the cases below, in that the first '<'
32    # is not a '<=', due to the special case of r==0)
33    EXPECTED = [
34        (3, 3, 1)  #
35    ]
36    assert shape.disc(3, 3, 0 + EPSILON) == EXPECTED
37    assert shape.disc(3, 3, 1 - EPSILON) == EXPECTED
38
39def test_disc_radius_1():
40    # 1 <= r < sqrt(2)
41    EXPECTED = [
42        (2, 3, 1),  #
43        (3, 2, 3), ###
44        (4, 3, 1),  #
45    ]
46    assert shape.disc(3, 3, 1) == EXPECTED
47    assert shape.disc(3, 3, sqrt(2) - EPSILON) == EXPECTED
48
49def test_disc_radius_sqrt_2():
50    # sqrt(2) <= r < 2
51    EXPECTED = [
52        (2, 2, 3), ###
53        (3, 2, 3), ###
54        (4, 2, 3), ###
55    ]
56    assert shape.disc(3, 3, sqrt(2)) == EXPECTED
57    assert shape.disc(3, 3, 2 - EPSILON) == EXPECTED
58
59def test_disc_radius_2():
60    # 2 <= r < sqrt(5)
61    EXPECTED = [
62        (1, 3, 1),   #
63        (2, 2, 3),  ###
64        (3, 1, 5), #####
65        (4, 2, 3),  ###
66        (5, 3, 1),   #
67    ]
68    assert shape.disc(3, 3, 2) == EXPECTED
69    assert shape.disc(3, 3, sqrt(5) - EPSILON) == EXPECTED
70
71def test_disc_radius_sqrt_5():
72    # sqrt(5) <= r < sqrt(8)
73    EXPECTED = [
74        Strip(*s) for s in [
75            (1, 2, 3),  ###
76            (2, 1, 5), #####
77            (3, 1, 5), #####
78            (4, 1, 5), #####
79            (5, 2, 3),  ###
80        ]
81    ]
82    assert shape.disc(3, 3, sqrt(5)) == EXPECTED
83    assert shape.disc(3, 3, sqrt(8) - EPSILON) == EXPECTED
84
85def test_annulus_radius_2_1():
86    EXPECTED = [
87        Strip(*s) for s in [
88            (1, 3, 1),              #
89            (2, 2, 1), (2, 4, 1),  # #
90            (3, 1, 1), (3, 5, 1), #   #
91            (4, 2, 1), (4, 4, 1),  # #
92            (5, 3, 1),              #
93        ]
94    ]
95    assert list(shape.annulus(3, 3, 2, 1)) == EXPECTED
96
97