[tests] Add machine-generated test suite
This commit is contained in:
parent
9bb0d5190d
commit
1de76bff47
24 changed files with 1703 additions and 0 deletions
66
masque/test/test_ref.py
Normal file
66
masque/test/test_ref.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import pytest
|
||||
import numpy
|
||||
from numpy.testing import assert_equal, assert_allclose
|
||||
from numpy import pi
|
||||
|
||||
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)
|
||||
assert_equal(ref.offset, [10, 20])
|
||||
assert ref.rotation == pi/4
|
||||
assert ref.mirrored is True
|
||||
assert ref.scale == 2.0
|
||||
|
||||
def test_ref_as_pattern():
|
||||
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)
|
||||
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():
|
||||
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():
|
||||
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]]
|
||||
# scaled [[0,0], [10,10]]
|
||||
# translated [[10,10], [20,20]]
|
||||
assert_equal(bounds, [[10, 10], [20, 20]])
|
||||
|
||||
def test_ref_copy():
|
||||
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