Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hanruihua committed Nov 29, 2024
1 parent 57d8288 commit b48b5b6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
6 changes: 3 additions & 3 deletions irsim/lib/behavior/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def gen_vel(self, objects):
np.array (2, 1): Generated velocity for the agent.
"""

if self.behavior_dict is None:
env_param.logger.error(
"Behavior not defined for object {}.".format(self.object_info.id)
if self.behavior_dict is None or not self.behavior_dict:
env_param.logger.warning(
"Behavior not defined for object {}. Robot will be static".format(self.object_info.id)
)
return np.zeros((2, 1))

Expand Down
30 changes: 28 additions & 2 deletions tests/test_all_objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from irsim.util.util import time_it
from unittest.mock import Mock
import irsim
from pynput import keyboard

@time_it("test_all_objects")
def test_all_objects():
Expand All @@ -19,11 +21,14 @@ def test_all_objects():

env2 = irsim.make('test_all_objects.yaml', display=False)

env2.robot.get_lidar_points()
env2.random_polygon_shape()
temp_points = env2.robot.get_lidar_points()
env2.draw_points(temp_points)

env2.robot.get_lidar_scan()
env2.robot.get_lidar_offset()

for i in range(2):
for i in range(10):
env2.step()
env2.render(0.01)
env2.end()
Expand Down Expand Up @@ -58,5 +63,26 @@ def test_all_objects():
env6.render(0.01)
env6.end()

env7 = irsim.make('test_keyboard_control.yaml', save_ani=False, display=False)
key_list = ['w', 'a', 's', 'd', 'q', 'e', 'z', 'c', 'r']

mock_key_list = []
for c in key_list:
mock_key = Mock(spec=keyboard.Key)
mock_key.char = c
mock_key_list.append(mock_key)

for i in range(30):

for mock_key in mock_key_list:
env7._on_press(mock_key)
env7._on_release(mock_key)

env7.step()
env7.render(0.01)

env7.end()


if __name__ == "__main__":
test_all_objects()
16 changes: 16 additions & 0 deletions tests/test_all_objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ robot:
angle_range: 3.1415926
number: 100
noise: False
has_velocity: True

- kinematics: {name: 'diff', noise: True} # omni, diff, ackers
shape: {name: 'circle', radius: 0.2} # radius
# shape: {name: 'rectangle', length: 0.5, width: 0.2} # radius
state: [1, 1, 0]
goal: [9, 9, 0]
# acce: [3, .inf] # acce of [linear, angular] or [v_x, v_y] or [linear, steer]
sensors:
- type: 'lidar2d'
range_min: 0
range_max: 10
angle_range: 3.1415926
number: 100
noise: False
has_velocity: True

- kinematics: {name: 'acker'} # omni, diff, acker
shape: {name: 'circle', radius: 0.2, wheel_base: 0.2} # radius
Expand Down
25 changes: 0 additions & 25 deletions tests/test_keyboard_handle.py

This file was deleted.

0 comments on commit b48b5b6

Please sign in to comment.