Skip to content

Commit

Permalink
LNX-188 Renamed tests, added type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyJB committed Sep 12, 2023
1 parent e5a81a0 commit 7be9e54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 13 additions & 10 deletions tests/drop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
class TestDropSerialization:
expected_serialization_drop = '{"type": "Drop", "attributes": {"object_id": 1, "target_position": {"x": 1, "y": 0}}}'

def test_success_serialization(self) -> NoReturn:
def test_success_serialization(self) -> None:
serialized_drop = Drop(object_id=1, target_position=Vector(1, 0)).serialize()

assert self.expected_serialization_drop == serialized_drop

def test_success_deserialization(self):
def test_success_deserialization(self) -> None:
expected_drop = Drop(object_id=1, target_position=Vector(1, 0))
dummy_drop = Drop.deserialize(self.expected_serialization_drop)

assert dummy_drop == expected_drop


class TestDropApply:
def test_success_apply(self):
def test_drop_single_object_in_overworld_on_tile_sucessful(self) -> None:
random.seed(1222)
expected_scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
expected_dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5))
Expand All @@ -49,7 +50,7 @@ def test_success_apply(self):

assert scene == expected_scene

def test_success_multiple_objects_apply(self):
def test_drop_multiple_objects_in_overworld_on_tile_sucessful(self) -> None:
random.seed(1222)
expected_scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
expected_dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5))
Expand Down Expand Up @@ -80,7 +81,7 @@ def test_success_multiple_objects_apply(self):

assert scene == expected_scene

def test_success_drop_to_drop_area_apply(self):
def test_success_drop_to_drop_area_apply(self) -> None:
expected_scene = Scene(players=[Player(player_id="test", player_resources={"Wood": 2, "Stone": 1}, drop_area=Vector(5, 6))])
expected_dummy_object = Object(id=1, name="dummy", owner="test", position=Vector(5, 5))
expected_dummy_drop = Drop(target_position=Vector(5, 6), object_id=1)
Expand All @@ -98,33 +99,35 @@ def test_success_drop_to_drop_area_apply(self):
dummy_drop.apply(scene)

assert scene == expected_scene


class TestDropRequirements:

def test_success_requirements(self):
def test_all_requirements_satisified_positive(self) -> None:
scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5), inventory={"Wood": 1})
dummy_drop = Drop(target_position=Vector(5, 6), object_id=1)
scene.add_entity(Object(id=3, name="Grass", position=Vector(5, 6), tags=['walkable']))
scene.add_entity(dummy_object)
assert dummy_drop.satisfies_requirements(scene) is True

def test_fail_requirements_distance(self):
def test_requirements_agent_too_far_fail(self) -> None:
scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5), inventory={"Wood": 1})
dummy_drop = Drop(target_position=Vector(6, 6), object_id=1)
scene.add_entity(Object(id=3, name="Grass", position=Vector(5, 6), tags=['walkable']))
scene.add_entity(Object(id=3, name="Grass", position=Vector(6, 6), tags=['walkable']))
scene.add_entity(dummy_object)
assert dummy_drop.satisfies_requirements(scene) is not True

def test_fail_requirements_inventory(self):
def test_requirements_empty_inventory_fail(self) -> None:
scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5))
dummy_drop = Drop(target_position=Vector(5, 6), object_id=1)
scene.add_entity(Object(id=3, name="Grass", position=Vector(5, 6), tags=['walkable']))
scene.add_entity(dummy_object)
assert dummy_drop.satisfies_requirements(scene) is not True

def test_fail_requirements_walkable(self):
def test_requirements_no_walkable_tile_fail(self) -> None:
scene = Scene(players=[Player(player_id="dummy", player_resources={"Wood": 0, "Stone": 0}, drop_area=Vector(5, 5))])
dummy_object = Object(id=1, name="dummy", owner="dummy", position=Vector(5, 5), inventory={"Wood": 1})
dummy_drop = Drop(target_position=Vector(5, 6), object_id=1)
Expand Down
1 change: 0 additions & 1 deletion tests/user_helper_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TestUserHelperFunctions:
scene.add_entity(dummy_object2)
dummy_object3 = Object(id=4, name="diff_dummy", position=Vector(1, 1))
scene.add_entity(dummy_object3)
random.seed(12)

def test_objects_around_success(self) -> NoReturn:
assert get_objects_around(1, self.scene, 9) == [3, 4]
Expand Down

1 comment on commit 7be9e54

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
lynx/common
   enums.py16850%17–24
   object.py24196%35
   scene.py881978%53, 71–72, 75, 78, 81–85, 88–94, 100, 106
lynx/common/actions
   common_requirements.py54394%18–19, 32
   create_object.py13285%20–22
   error_log.py10280%15, 18
   message_log.py10280%15, 18
   print.py10280%15, 18
   remove_object.py12192%21
   update_resources.py12283%17, 20
TOTAL5424292% 

Tests Skipped Failures Errors Time
82 0 💤 0 ❌ 0 🔥 0.374s ⏱️

Please sign in to comment.