Beispiel #1
0
def test_one_point_line() -> None:
    inst = Line(x, 0, 1, 1)
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {x: pytest.approx([0])}
    assert dim.lower == {x: pytest.approx([-0.5])}
    assert dim.upper == {x: pytest.approx([0.5])}
    assert dim.snake is False
Beispiel #2
0
def test_many_point_line() -> None:
    inst = Line(x, 0, 1, 5)
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {x: pytest.approx([0, 0.25, 0.5, 0.75, 1])}
    assert dim.lower == {
        x: pytest.approx([-0.125, 0.125, 0.375, 0.625, 0.875])
    }
    assert dim.upper == {x: pytest.approx([0.125, 0.375, 0.625, 0.875, 1.125])}
Beispiel #3
0
def test_zipped_lines() -> None:
    inst = Line(x, 0, 1, 5) + Line(y, 1, 2, 5)
    assert inst.axes() == [x, y]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([0, 0.25, 0.5, 0.75, 1]),
        y: pytest.approx([1, 1.25, 1.5, 1.75, 2]),
    }
Beispiel #4
0
def test_rect_region_symmetricdifference() -> None:
    inst = Line(y, 1, 3, 5) * Line(x, 0, 2, 3) & Rectangle(
        x, y, 0, 1, 1.5, 2.2) ^ Rectangle(x, y, 0.5, 1.5, 2, 2.5)
    assert inst.axes() == [y, x]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([0, 1, 0, 2, 0, 2, 1, 2]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2, 2.5, 2.5]),
    }
Beispiel #5
0
def test_zipped_product_lines() -> None:
    inst = Line(y, 1, 2, 3) * Line(x, 0, 1, 5) + Line(z, 2, 3, 5)
    assert inst.axes() == [y, x, z]
    dimy, dimxz = inst.create_dimensions()
    assert dimxz.midpoints == {
        x: pytest.approx([0, 0.25, 0.5, 0.75, 1]),
        z: pytest.approx([2, 2.25, 2.5, 2.75, 3]),
    }
    assert dimy.midpoints == {
        y: pytest.approx([1, 1.5, 2]),
    }
Beispiel #6
0
def test_squashed_multiplied_snake_scan() -> None:
    inst = Line(z, 1, 2, 2) * Squash(
        Line(y, 1, 2, 2) * ~Line.bounded(x, 3, 7, 2) * Static.duration(9, 2))
    assert inst.axes() == [z, y, x, DURATION]
    dimz, dimxyt = inst.create_dimensions()
    for d in dimxyt.midpoints, dimxyt.lower, dimxyt.upper:
        assert d == {
            x: pytest.approx([4, 4, 6, 6, 6, 6, 4, 4]),
            y: pytest.approx([1, 1, 1, 1, 2, 2, 2, 2]),
            DURATION: pytest.approx([9, 9, 9, 9, 9, 9, 9, 9]),
        }
    assert dimz.midpoints == dimz.lower == dimz.upper == {
        z: pytest.approx([1, 2])
    }
Beispiel #7
0
def test_circle_region() -> None:
    inst = Line(y, 1, 3, 3) * Line(x, 0, 2, 3) & Circle(x, y, 1, 2, 1)
    assert inst.axes() == [y, x]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([1, 0, 1, 2, 1]),
        y: pytest.approx([1, 2, 2, 2, 3]),
    }
    assert dim.lower == {
        x: pytest.approx([0.5, -0.5, 0.5, 1.5, 0.5]),
        y: pytest.approx([1, 2, 2, 2, 3]),
    }
    assert dim.upper == {
        x: pytest.approx([1.5, 0.5, 1.5, 2.5, 1.5]),
        y: pytest.approx([1, 2, 2, 2, 3]),
    }
Beispiel #8
0
def test_ellipse_region() -> None:
    inst = Line("y", 1, 3, 3) * Line("x", 0, 2, 3) & Ellipse(
        x, y, 1, 2, 2, 1, 45)
    assert inst.axes() == [y, x]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([0, 1, 0, 1, 2, 1, 2]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3]),
    }
    assert dim.lower == {
        x: pytest.approx([-0.5, 0.5, -0.5, 0.5, 1.5, 0.5, 1.5]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3]),
    }
    assert dim.upper == {
        x: pytest.approx([0.5, 1.5, 0.5, 1.5, 2.5, 1.5, 2.5]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3]),
    }
Beispiel #9
0
def test_rect_region() -> None:
    inst = Line(y, 1, 3, 5) * Line(x, 0, 2, 3) & Rectangle(
        x, y, 0, 1, 1.5, 2.2)
    assert inst.axes() == [y, x]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([0, 1, 0, 1, 0, 1]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
    assert dim.lower == {
        x: pytest.approx([-0.5, 0.5, -0.5, 0.5, -0.5, 0.5]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
    assert dim.upper == {
        x: pytest.approx([0.5, 1.5, 0.5, 1.5, 0.5, 1.5]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
Beispiel #10
0
def test_product_snaking_lines() -> None:
    inst = Line(y, 1, 2, 3) * ~Line(x, 0, 1, 2)
    assert inst.axes() == [y, x]
    dims = inst.create_dimensions()
    assert len(dims) == 2
    dim = Path(dims).consume()
    assert dim.midpoints == {
        x: pytest.approx([0, 1, 1, 0, 0, 1]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
    assert dim.lower == {
        x: pytest.approx([-0.5, 0.5, 1.5, 0.5, -0.5, 0.5]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
    assert dim.upper == {
        x: pytest.approx([0.5, 1.5, 0.5, -0.5, 0.5, 1.5]),
        y: pytest.approx([1, 1, 1.5, 1.5, 2, 2]),
    }
Beispiel #11
0
def test_polygon_region() -> None:
    x_verts = [0, 0.5, 4.0, 2.5]
    y_verts = [0, 3.5, 3.5, 0.5]
    inst = Line("y", 1, 3, 3) * Line("x", 0, 4, 5) & Polygon(
        x, y, x_verts, y_verts)
    assert inst.axes() == [y, x]
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {
        x: pytest.approx([1, 2, 1, 2, 3, 1, 2, 3]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]),
    }
    assert dim.lower == {
        x: pytest.approx([0.5, 1.5, 0.5, 1.5, 2.5, 0.5, 1.5, 2.5]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]),
    }
    assert dim.upper == {
        x: pytest.approx([1.5, 2.5, 1.5, 2.5, 3.5, 1.5, 2.5, 3.5]),
        y: pytest.approx([1, 1, 2, 2, 2, 3, 3, 3]),
    }
Beispiel #12
0
def test_snake_not_allowed_inside_odd_nested() -> None:
    spec = Line("z", 1, 2, 2) * Squash(Line("y", 1, 3, 3) * ~Line("x", 0, 2, 3))
    with pytest.raises(ValueError) as cm:
        spec.create_dimensions()
    assert "['x'] would jump in position" in cm.value.args[0]
Beispiel #13
0
def test_non_snake_not_allowed_inside_snaking_dim() -> None:
    spec = Line("z", 1, 2, 2) * Squash(~Line("y", 1, 3, 3) * Line("x", 0, 2, 3))
    with pytest.raises(ValueError) as cm:
        spec.create_dimensions()
    assert "['x'] would run backwards" in cm.value.args[0]
Beispiel #14
0
def test_two_point_line() -> None:
    inst = Line(x, 0, 1, 2)
    (dim, ) = inst.create_dimensions()
    assert dim.midpoints == {x: pytest.approx([0, 1])}
    assert dim.lower == {x: pytest.approx([-0.5, 0.5])}
    assert dim.upper == {x: pytest.approx([0.5, 1.5])}