[Tests] cleanup
This commit is contained in:
parent
d9adb4e1b9
commit
1cce6c1f70
23 changed files with 540 additions and 467 deletions
|
|
@ -1,5 +1,3 @@
|
|||
import pytest
|
||||
import numpy
|
||||
from numpy.testing import assert_equal, assert_allclose
|
||||
from numpy import pi
|
||||
|
||||
|
|
@ -7,47 +5,51 @@ from ..pattern import Pattern
|
|||
from ..ref import Ref
|
||||
from ..repetition import Grid
|
||||
|
||||
def test_ref_init():
|
||||
ref = Ref(offset=(10, 20), rotation=pi/4, mirrored=True, scale=2.0)
|
||||
|
||||
def test_ref_init() -> None:
|
||||
ref = Ref(offset=(10, 20), rotation=pi / 4, mirrored=True, scale=2.0)
|
||||
assert_equal(ref.offset, [10, 20])
|
||||
assert ref.rotation == pi/4
|
||||
assert ref.rotation == pi / 4
|
||||
assert ref.mirrored is True
|
||||
assert ref.scale == 2.0
|
||||
|
||||
def test_ref_as_pattern():
|
||||
|
||||
def test_ref_as_pattern() -> None:
|
||||
sub_pat = Pattern()
|
||||
sub_pat.polygon((1, 0), vertices=[[0, 0], [1, 0], [0, 1]])
|
||||
|
||||
ref = Ref(offset=(10, 10), rotation=pi/2, scale=2.0)
|
||||
|
||||
ref = Ref(offset=(10, 10), rotation=pi / 2, scale=2.0)
|
||||
transformed_pat = ref.as_pattern(sub_pat)
|
||||
|
||||
|
||||
# Check transformed shape
|
||||
shape = transformed_pat.shapes[(1, 0)][0]
|
||||
# ref.as_pattern deepcopies sub_pat then applies transformations:
|
||||
# 1. pattern.scale_by(2) -> vertices [[0,0], [2,0], [0,2]]
|
||||
# 2. pattern.rotate_around((0,0), pi/2) -> vertices [[0,0], [0,2], [-2,0]]
|
||||
# 3. pattern.translate_elements((10,10)) -> vertices [[10,10], [10,12], [8,10]]
|
||||
|
||||
|
||||
assert_allclose(shape.vertices, [[10, 10], [10, 12], [8, 10]], atol=1e-10)
|
||||
|
||||
def test_ref_with_repetition():
|
||||
|
||||
def test_ref_with_repetition() -> None:
|
||||
sub_pat = Pattern()
|
||||
sub_pat.polygon((1, 0), vertices=[[0, 0], [1, 0], [0, 1]])
|
||||
|
||||
|
||||
rep = Grid(a_vector=(10, 0), b_vector=(0, 10), a_count=2, b_count=2)
|
||||
ref = Ref(repetition=rep)
|
||||
|
||||
|
||||
repeated_pat = ref.as_pattern(sub_pat)
|
||||
# Should have 4 shapes
|
||||
assert len(repeated_pat.shapes[(1, 0)]) == 4
|
||||
|
||||
|
||||
first_verts = sorted([tuple(s.vertices[0]) for s in repeated_pat.shapes[(1, 0)]])
|
||||
assert first_verts == [(0.0, 0.0), (0.0, 10.0), (10.0, 0.0), (10.0, 10.0)]
|
||||
|
||||
def test_ref_get_bounds():
|
||||
|
||||
def test_ref_get_bounds() -> None:
|
||||
sub_pat = Pattern()
|
||||
sub_pat.polygon((1, 0), vertices=[[0, 0], [5, 0], [0, 5]])
|
||||
|
||||
|
||||
ref = Ref(offset=(10, 10), scale=2.0)
|
||||
bounds = ref.get_bounds_single(sub_pat)
|
||||
# sub_pat bounds [[0,0], [5,5]]
|
||||
|
|
@ -55,12 +57,12 @@ def test_ref_get_bounds():
|
|||
# translated [[10,10], [20,20]]
|
||||
assert_equal(bounds, [[10, 10], [20, 20]])
|
||||
|
||||
def test_ref_copy():
|
||||
|
||||
def test_ref_copy() -> None:
|
||||
ref1 = Ref(offset=(1, 2), rotation=0.5, annotations={"a": [1]})
|
||||
ref2 = ref1.copy()
|
||||
assert ref1 == ref2
|
||||
assert ref1 is not ref2
|
||||
|
||||
|
||||
ref2.offset[0] = 100
|
||||
assert ref1.offset[0] == 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue