Skip to content

Commit

Permalink
test: check _count_rails_per_track_in_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
nalquas committed Nov 8, 2024
1 parent 96fc916 commit b509084
Showing 1 changed file with 158 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,143 @@

from raillabel_providerkit.validation.validate_rail_side.validate_rail_side import (
validate_rail_side,
_count_rails_per_track_in_frame,
)


def test_validate_rail_side__no_errors(empty_scene, empty_frame):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
scene.objects[object.uid] = object
sensor = raillabel.format.Sensor(
@pytest.fixture
def example_camera_1() -> raillabel.format.Sensor:
return raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)


@pytest.fixture
def example_camera_2() -> raillabel.format.Sensor:
return raillabel.format.Sensor(
uid="ir_center",
type=raillabel.format.SensorType.CAMERA,
)


@pytest.fixture
def example_track_1() -> raillabel.format.Object:
return raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)


@pytest.fixture
def example_track_2() -> raillabel.format.Object:
return raillabel.format.Object(
uid="6e92e7af-3bc8-4225-b538-16d19e3f8aa7", name="track0002", type="track"
)


def test_count_rails_per_track_in_frame__empty(empty_frame):
frame = empty_frame
results = _count_rails_per_track_in_frame(frame)
assert len(results) == 0


def test_count_rails_per_track_in_frame__many_rails_for_one_track(
empty_frame, example_camera_1, example_track_1
):
frame = empty_frame
sensor = example_camera_1
object = example_track_1

LEFT_COUNT = 32
RIGHT_COUNT = 42

for i in range(LEFT_COUNT):
uid = f"test_left_{i}"
frame.annotations[uid] = raillabel.format.Poly2d(
uid=uid,
object=object,
sensor=sensor,
points=[
raillabel.format.Point2d(0, 0),
raillabel.format.Point2d(0, 1),
],
closed=False,
attributes={"railSide": "leftRail"},
)

for i in range(RIGHT_COUNT):
uid = f"test_right_{i}"
frame.annotations[uid] = raillabel.format.Poly2d(
uid=uid,
object=object,
sensor=sensor,
points=[
raillabel.format.Point2d(1, 0),
raillabel.format.Point2d(1, 1),
],
closed=False,
attributes={"railSide": "rightRail"},
)

results = _count_rails_per_track_in_frame(frame)
assert len(results) == 1
assert object.uid in results.keys()
assert results[object.uid] == (LEFT_COUNT, RIGHT_COUNT)


def test_count_rails_per_track_in_frame__many_rails_for_two_tracks(
empty_frame, example_camera_1, example_track_1, example_track_2
):
frame = empty_frame
sensor = example_camera_1
object1 = example_track_1
object2 = example_track_2

LEFT_COUNT = 32
RIGHT_COUNT = 42

for object in [object1, object2]:
for i in range(LEFT_COUNT):
uid = f"test_left_{i}_object_{object.uid}"
frame.annotations[uid] = raillabel.format.Poly2d(
uid=uid,
object=object,
sensor=sensor,
points=[
raillabel.format.Point2d(0, 0),
raillabel.format.Point2d(0, 1),
],
closed=False,
attributes={"railSide": "leftRail"},
)

for i in range(RIGHT_COUNT):
uid = f"test_right_{i}_object_{object.uid}"
frame.annotations[uid] = raillabel.format.Poly2d(
uid=uid,
object=object,
sensor=sensor,
points=[
raillabel.format.Point2d(1, 0),
raillabel.format.Point2d(1, 1),
],
closed=False,
attributes={"railSide": "rightRail"},
)

results = _count_rails_per_track_in_frame(frame)
assert len(results) == 2
assert object1.uid in results.keys()
assert object2.uid in results.keys()
assert results[object1.uid] == (LEFT_COUNT, RIGHT_COUNT)
assert results[object2.uid] == (LEFT_COUNT, RIGHT_COUNT)


def test_validate_rail_side__no_errors(empty_scene, empty_frame, example_camera_1, example_track_1):
scene = empty_scene
object = example_track_1
scene.objects[object.uid] = object
sensor = example_camera_1
scene.sensors[sensor.uid] = sensor
frame = empty_frame
frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d(
Expand Down Expand Up @@ -49,16 +173,13 @@ def test_validate_rail_side__no_errors(empty_scene, empty_frame):
assert len(actual) == 0


def test_validate_rail_side__rail_sides_switched(empty_scene, empty_frame):
def test_validate_rail_side__rail_sides_switched(
empty_scene, empty_frame, example_camera_1, example_track_1
):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
object = example_track_1
scene.objects[object.uid] = object
sensor = raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor = example_camera_1
scene.sensors[sensor.uid] = sensor
frame = empty_frame
frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d(
Expand Down Expand Up @@ -89,16 +210,13 @@ def test_validate_rail_side__rail_sides_switched(empty_scene, empty_frame):
assert len(actual) == 1


def test_validate_rail_side__two_left_rails(empty_scene, empty_frame):
def test_validate_rail_side__two_left_rails(
empty_scene, empty_frame, example_camera_1, example_track_1
):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
object = example_track_1
scene.objects[object.uid] = object
sensor = raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor = example_camera_1
scene.sensors[sensor.uid] = sensor
frame = empty_frame
frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d(
Expand Down Expand Up @@ -129,16 +247,13 @@ def test_validate_rail_side__two_left_rails(empty_scene, empty_frame):
assert len(actual) == 1


def test_validate_rail_side__two_right_rails(empty_scene, empty_frame):
def test_validate_rail_side__two_right_rails(
empty_scene, empty_frame, example_camera_1, example_track_1
):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
object = example_track_1
scene.objects[object.uid] = object
sensor = raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor = example_camera_1
scene.sensors[sensor.uid] = sensor
frame = empty_frame
frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d(
Expand Down Expand Up @@ -169,20 +284,14 @@ def test_validate_rail_side__two_right_rails(empty_scene, empty_frame):
assert len(actual) == 1


def test_validate_rail_side__two_sensors_with_two_right_rails_each(empty_scene, empty_frame):
def test_validate_rail_side__two_sensors_with_two_right_rails_each(
empty_scene, empty_frame, example_camera_1, example_camera_2, example_track_1
):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
object = example_track_1
scene.objects[object.uid] = object
sensor1 = raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor2 = raillabel.format.Sensor(
uid="ir_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor1 = example_camera_1
sensor2 = example_camera_2
for sensor in [sensor1, sensor2]:
scene.sensors[sensor.uid] = sensor
frame = empty_frame
Expand Down Expand Up @@ -236,20 +345,14 @@ def test_validate_rail_side__two_sensors_with_two_right_rails_each(empty_scene,
assert len(actual) == 2


def test_validate_rail_side__two_sensors_with_one_right_rail_each(empty_scene, empty_frame):
def test_validate_rail_side__two_sensors_with_one_right_rail_each(
empty_scene, empty_frame, example_camera_1, example_camera_2, example_track_1
):
scene = empty_scene
object = raillabel.format.Object(
uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track"
)
object = example_track_1
scene.objects[object.uid] = object
sensor1 = raillabel.format.Sensor(
uid="rgb_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor2 = raillabel.format.Sensor(
uid="ir_center",
type=raillabel.format.SensorType.CAMERA,
)
sensor1 = example_camera_1
sensor2 = example_camera_2
for sensor in [sensor1, sensor2]:
scene.sensors[sensor.uid] = sensor
frame = empty_frame
Expand Down

0 comments on commit b509084

Please sign in to comment.