Beispiel #1
0
def test_param():
    p = sampleParamPFrom('ego = Object\n' 'param p = Range(3, 5)')
    assert 3 <= p <= 5
    p = sampleParamPFrom('ego = Object\n' 'param p = [1, 4, 9]')
    assert type(p) is list
    assert p == [1, 4, 9]
    p = sampleParamPFrom('ego = Object\n' 'param p = (1, 4)')
    assert type(p) is tuple
    assert p == (1, 4)
Beispiel #2
0
def test_angle():
    p = sampleParamPFrom("""
        ego = Object facing 30 deg
        other = Object facing 65 deg, at 10@10
        param p = angle to other
    """)
    assert p == pytest.approx(math.radians(-45))
Beispiel #3
0
def test_distance_to_region():
    p = sampleParamPFrom("""
        r = CircularRegion(10@5, 3)
        ego = Object at 13@9
        param p = distance to r
    """)
    assert p == pytest.approx(2)
Beispiel #4
0
def test_distance():
    p = sampleParamPFrom("""
        ego = Object at 5@10
        other = Object at 7@-4
        param p = distance to other
    """)
    assert p == pytest.approx(math.hypot(7 - 5, -4 - 10))
Beispiel #5
0
def test_apparent_heading():
    p = sampleParamPFrom("""
        ego = Object facing 30 deg
        other = Object facing 65 deg, at 10@10
        param p = apparent heading of other
    """)
    assert p == pytest.approx(math.radians(65 + 45))
Beispiel #6
0
def test_oriented_point_can_see_object():
    p = sampleParamPFrom(
        'ego = Object facing -45 deg, with visibleDistance 5, with viewAngle 20 deg\n'
        'other = Object at 4@4, with width 2, with height 2\n'
        'other2 = Object at 4@0, with requireVisible False\n'
        'param p = tuple([ego can see other, ego can see other2])')
    assert p == (True, False)
Beispiel #7
0
def test_point_can_see_vector():
    p = sampleParamPFrom("""
        ego = Object
        pt = Point at 10@20, with visibleDistance 5
        param p = tuple([pt can see 8@19, pt can see 10@26])
    """)
    assert p == (True, False)
Beispiel #8
0
def test_relative_heading():
    p = sampleParamPFrom("""
        ego = Object facing 30 deg
        other = Object facing 65 deg, at 10@10
        param p = relative heading of other
    """)
    assert p == pytest.approx(math.radians(65 - 30))
Beispiel #9
0
def test_object_in_region():
    p = sampleParamPFrom(
        'reg = RectangularRegion(10@5, 0, 4, 2)\n'
        'ego = Object at [email protected], with width 0.25, with height 0.25\n'
        'other = Object at [email protected], with width 2.5\n'
        'param p = tuple([ego in reg, other in reg])')
    assert p == (True, False)
Beispiel #10
0
def test_object_in_region():
    p = sampleParamPFrom("""
        reg = RectangularRegion(10@5, 0, 4, 2)
        ego = Object at [email protected], with width 0.25, with length 0.25
        other = Object at [email protected], with width 2.5
        param p = tuple([ego in reg, other in reg])
    """)
    assert p == (True, False)
Beispiel #11
0
def test_point_in_region():
    p = sampleParamPFrom(
        'ego = Object\n'
        'reg = RectangularRegion(10@5, 0, 4, 2)\n'
        'ptA = Point at [email protected]\n'
        'ptB = Point at [email protected]\n'
        'param p = tuple([[email protected] in reg, 9@7 in reg, ptA in reg, ptB in reg])')
    assert p == (True, False, True, False)
Beispiel #12
0
def test_point_can_see_object():
    p = sampleParamPFrom("""
        ego = Object with width 10, with length 10
        other = Object at 35@10
        pt = Point at 15@10, with visibleDistance 15
        param p = tuple([pt can see ego, pt can see other])
    """)
    assert p == (True, False)
Beispiel #13
0
def test_oriented_point_can_see_vector():
    p = sampleParamPFrom("""
        ego = Object facing -45 deg, with visibleDistance 5, with viewAngle 20 deg
        param p = tuple([ego can see 2@2, ego can see 4@4, ego can see 1@0])
    """)
    assert p == (True, False, False)
Beispiel #14
0
def test_tuple_as_vector():
    p = sampleParamPFrom("""
        ego = Object at 1 @ 2
        param p = distance to (-2, -2)
    """)
    assert p == pytest.approx(5)
Beispiel #15
0
def test_distance():
    p = sampleParamPFrom('ego = Object at 5@10\n'
                         'other = Object at 7@-4\n'
                         'param p = distance to other')
    assert p == pytest.approx(math.hypot(7 - 5, -4 - 10))
Beispiel #16
0
def test_quoted_param():
    p = sampleParamPFrom('ego = Object\n' 'param "p" = Range(3, 5)')
    assert 3 <= p <= 5
Beispiel #17
0
def test_point_can_see_object():
    p = sampleParamPFrom('ego = Object with width 10, with height 10\n'
                         'other = Object at 35@10\n'
                         'pt = Point at 15@10, with visibleDistance 15\n'
                         'param p = tuple([pt can see ego, pt can see other])')
    assert p == (True, False)