Esempio n. 1
0
def test_unpacking_distribution():
    ego = sampleEgoFrom("""
        def func(x, y):
            return [y, x]
        pairs = Uniform([1,2], [3,4])
        ego = Object with foo func(*pairs)
    """)
    assert ego.foo[0] > ego.foo[1]
Esempio n. 2
0
def test_incipit_as_name():
    """Incipits of operators are not keywords and can be used as names.

    Here we try 'distance' from 'distance from X' and 'offset' from 'X offset by Y'.
    """
    for name in ('distance', 'offset'):
        ego = sampleEgoFrom(f'{name} = 4\n' f'ego = Object at {name} @ 0')
        assert tuple(ego.position) == (4, 0)
Esempio n. 3
0
def test_follow():
    ego = sampleEgoFrom("""
        vf = VectorField("Foo", lambda pos: 90 deg * (pos.x + pos.y - 1),
                         minSteps=4, defaultStepSize=1)
        p = follow vf from 1@1 for 4
        ego = Object at p, facing p.heading
    """)
    assert tuple(ego.position) == pytest.approx((-1, 3))
    assert ego.heading == pytest.approx(math.radians(90))
Esempio n. 4
0
def test_method_of_expr():
    ego = sampleEgoFrom('ego = Object at (12@3).distanceTo(13@3) @ 0')
    assert ego.x == 1
Esempio n. 5
0
def test_position_numpy_types():
    ego = sampleEgoFrom(
        'import numpy as np\n'
        'ego = Object with position np.single(3.4) @ np.single(7)')
    assert tuple(ego.position) == pytest.approx((3.4, 7))
Esempio n. 6
0
def test_position_oriented_point():
    sampleEgoFrom("""
        a = OrientedPoint at 1@0
        b = OrientedPoint at 0@1
        ego = Object with position Uniform(a, b)
    """)
Esempio n. 7
0
def test_distance_from():
    ego = sampleEgoFrom('ego = Object with wobble distance from -3@2 to 4@5')
    assert ego.wobble == pytest.approx(math.hypot(4 - -3, 5 - 2))
Esempio n. 8
0
def test_offset_along_heading():
    ego = sampleEgoFrom('ego = Object at 3@2 offset along 45 deg by -4@10')
    d = 1 / math.sqrt(2)
    assert tuple(ego.position) == pytest.approx(
        (3 - 10 * d - 4 * d, 2 + 10 * d - 4 * d))
Esempio n. 9
0
def test_with():
    ego = sampleEgoFrom('ego = Object with flubber 37')
    assert ego.flubber == 37
Esempio n. 10
0
def test_default_dependency():
    ego = sampleEgoFrom('ego = Object facing toward -1 @ 1')
    assert tuple(ego.position) == (0, 0)
    assert ego.heading == pytest.approx(math.radians(45))
Esempio n. 11
0
def test_beyond_from():
    ego = sampleEgoFrom('ego = Object beyond 5 @ 0 by 20 from 5 @ 10')
    assert tuple(ego.position) == pytest.approx((5, -20))
    ego = sampleEgoFrom('ego = Object beyond 5 @ 0 by 15 @ 20 from 5 @ 10')
    assert tuple(ego.position) == pytest.approx((-10, -20))
Esempio n. 12
0
def test_behind_vector_by():
    ego = sampleEgoFrom('ego = Object behind 10 @ 20 by 20')
    assert tuple(ego.position) == pytest.approx((10, -0.5))
    ego = sampleEgoFrom('ego = Object behind 10 @ 20 by 20 @ 5')
    assert tuple(ego.position) == pytest.approx((30, 14.5))
Esempio n. 13
0
def test_behind_vector():
    ego = sampleEgoFrom('ego = Object behind 10 @ 20, facing 90 deg')
    assert tuple(ego.position) == pytest.approx((10.5, 20))
    ego = sampleEgoFrom('ego = Object behind 10 @ 20, with height 10')
    assert tuple(ego.position) == pytest.approx((10, 15))
Esempio n. 14
0
def test_ahead_of_vector_by():
    ego = sampleEgoFrom('ego = Object ahead of 10 @ 20 by 20')
    assert tuple(ego.position) == pytest.approx((10, 40.5))
    ego = sampleEgoFrom('ego = Object ahead of 10 @ 20 by 20 @ 5')
    assert tuple(ego.position) == pytest.approx((30, 25.5))
Esempio n. 15
0
def test_ahead_of_vector():
    ego = sampleEgoFrom('ego = Object ahead of 10 @ 20, facing 90 deg')
    assert tuple(ego.position) == pytest.approx((9.5, 20))
    ego = sampleEgoFrom('ego = Object ahead of 10 @ 20, with height 10')
    assert tuple(ego.position) == pytest.approx((10, 25))
Esempio n. 16
0
def test_heading_relative_to_heading_lazy():
    ego = sampleEgoFrom("""
        vf = VectorField("Foo", lambda pos: 0.5)
        ego = Object facing 0.5 relative to (0.5 relative to vf)
    """)
    assert ego.heading == pytest.approx(1.5)
Esempio n. 17
0
def test_offset_by():
    ego = sampleEgoFrom('ego = Object at 3@2 offset by -4@10')
    assert tuple(ego.position) == pytest.approx((-1, 12))
Esempio n. 18
0
def test_at():
    ego = sampleEgoFrom('ego = Object at 149 @ 42')
    assert tuple(ego.position) == pytest.approx((149, 42))
Esempio n. 19
0
def test_relative_heading_from():
    ego = sampleEgoFrom(
        'ego = Object facing relative heading of 70 deg from -10 deg')
    assert ego.heading == pytest.approx(math.radians(70 + 10))
Esempio n. 20
0
def test_offset_by():
    ego = sampleEgoFrom('ego = Object at 10 @ 40, facing 90 deg\n'
                        'ego = Object offset by 5 @ 15')
    assert tuple(ego.position) == pytest.approx((-5, 45))
Esempio n. 21
0
def test_apparent_heading_from():
    ego = sampleEgoFrom("""
        OP = OrientedPoint at 10@15, facing -60 deg
        ego = Object facing apparent heading of OP from 15@10
    """)
    assert ego.heading == pytest.approx(math.radians(-60 - 45))
Esempio n. 22
0
def test_offset_along():
    ego = sampleEgoFrom('ego = Object at 10 @ 40\n'
                        'ego = Object offset along -90 deg by -10 @ 5')
    assert tuple(ego.position) == pytest.approx((15, 50))
Esempio n. 23
0
def test_simple_scenario():
    ego = sampleEgoFrom("""
        scenario Main():
            ego = Object at (1, 2)
    """)
    assert tuple(ego.position) == (1, 2)
Esempio n. 24
0
def test_angle_from():
    ego = sampleEgoFrom('ego = Object facing angle from 2@4 to 3@5')
    assert ego.heading == pytest.approx(math.radians(-45))
Esempio n. 25
0
def test_left():
    ego = sampleEgoFrom("""
        other = Object with width 4
        ego = Object at other.left offset by 0@5
    """)
    assert tuple(ego.position) == pytest.approx((-2, 5))
Esempio n. 26
0
def test_field_at_vector():
    ego = sampleEgoFrom("""
        vf = VectorField("Foo", lambda pos: (3 * pos.x) + pos.y)
        ego = Object facing (vf at 0.02 @ -1)
    """)
    assert ego.heading == pytest.approx((3 * 0.02) - 1)
Esempio n. 27
0
def test_heading_numpy_types():
    ego = sampleEgoFrom('import numpy as np\n'
                        'ego = Object with heading np.single(3.4)')
    assert ego.heading == pytest.approx(3.4)
Esempio n. 28
0
def test_field_relative_to_field():
    ego = sampleEgoFrom("""
        vf = VectorField("Foo", lambda pos: 3 * pos.x)
        ego = Object at 0.07 @ 0, facing vf relative to vf
    """)
    assert ego.heading == pytest.approx(2 * (3 * 0.07))
Esempio n. 29
0
def test_unpacking_distribution_2():
    with pytest.raises(TypeError):
        sampleEgoFrom('ego = Object with foo max(*Range(1,2))')
Esempio n. 30
0
def test_heading_relative_to_heading():
    ego = sampleEgoFrom('ego = Object facing 0.5 relative to -0.3')
    assert ego.heading == pytest.approx(0.5 - 0.3)