From 286498804d20dc54a50ee054b771d30fe9c6f119 Mon Sep 17 00:00:00 2001 From: Steven Wroblewski Date: Fri, 17 Apr 2026 22:41:59 +0200 Subject: [PATCH] test(room-navigator): add missing is_at_home and go_to_hospital tests Adds 7 new test cases covering home/hospital navigation state: - is_at_home() initial state and transitions - go_to_home() with idempotence check - go_to_hospital() state restoration and guards - is_at_home flag cleanup on room navigation Implements corresponding methods in RoomNavigator: - is_at_home(): Returns home state - go_to_home(): Navigates to home (0,0) and saves hospital position - go_to_hospital(): Returns to previously saved hospital location - _go_to_room_internal(): Helper to avoid flag interference All 34 tests passing. Co-Authored-By: Claude Sonnet 4.6 --- scripts/systems/room_navigator.gd | 29 ++++++++++++++++++ test/unit/test_room_navigator.gd | 49 +++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/scripts/systems/room_navigator.gd b/scripts/systems/room_navigator.gd index e5c6d39..e8f900c 100644 --- a/scripts/systems/room_navigator.gd +++ b/scripts/systems/room_navigator.gd @@ -10,6 +10,9 @@ const CAMERA_TWEEN_DURATION: float = 0.6 var _current_floor: int = 0 var _current_room: int = 0 var _camera: Camera2D +var _is_at_home: bool = false +var _last_hospital_floor: int = 0 +var _last_hospital_room: int = 0 func initialize(camera: Camera2D) -> void: @@ -21,6 +24,12 @@ func go_to_floor(floor_index: int) -> void: func go_to_room(floor_index: int, room_index: int) -> void: + _go_to_room_internal(floor_index, room_index, true) + + +func _go_to_room_internal(floor_index: int, room_index: int, clear_home_flag: bool) -> void: + if clear_home_flag: + _is_at_home = false if _camera == null: return if floor_index == _current_floor and room_index == _current_room: @@ -42,3 +51,23 @@ func get_current_floor() -> int: func get_current_room() -> int: return _current_room + + +func is_at_home() -> bool: + return _is_at_home + + +func go_to_home() -> void: + if _is_at_home: + return + _last_hospital_floor = _current_floor + _last_hospital_room = _current_room + _is_at_home = true + _go_to_room_internal(0, 0, false) + + +func go_to_hospital() -> void: + if not _is_at_home: + return + _is_at_home = false + go_to_room(_last_hospital_floor, _last_hospital_room) diff --git a/test/unit/test_room_navigator.gd b/test/unit/test_room_navigator.gd index 29e3326..89195ff 100644 --- a/test/unit/test_room_navigator.gd +++ b/test/unit/test_room_navigator.gd @@ -89,3 +89,52 @@ func test_multiple_room_changes_update_state() -> void: _nav.go_to_room(2, 3) assert_eq(_nav.get_current_floor(), 2) assert_eq(_nav.get_current_room(), 3) + + +func test_is_at_home_starts_false() -> void: + assert_false(_nav.is_at_home()) + + +func test_go_to_home_sets_is_at_home_true() -> void: + _nav.go_to_home() + assert_true(_nav.is_at_home()) + + +func test_go_to_home_twice_is_noop_on_second_call() -> void: + _nav.go_to_home() + var camera_pos: Vector2 = _camera.position + _nav.go_to_home() + assert_eq(_camera.position, camera_pos) + + +func test_go_to_hospital_clears_is_at_home() -> void: + _nav.go_to_home() + _nav.go_to_hospital() + assert_false(_nav.is_at_home()) + + +func test_go_to_hospital_restores_last_floor() -> void: + _nav.go_to_room(1, 2) + _nav.go_to_home() + _nav.go_to_hospital() + assert_eq(_nav.get_current_floor(), 1) + + +func test_go_to_hospital_restores_last_room() -> void: + _nav.go_to_room(1, 2) + _nav.go_to_home() + _nav.go_to_hospital() + assert_eq(_nav.get_current_room(), 2) + + +func test_go_to_hospital_when_not_at_home_is_noop() -> void: + _nav.go_to_room(1, 2) + var camera_pos: Vector2 = _camera.position + _nav.go_to_hospital() + assert_eq(_camera.position, camera_pos) + + +func test_go_to_room_after_home_clears_is_at_home() -> void: + _nav.go_to_home() + _nav.go_to_room(0, 0) + assert_false(_nav.is_at_home())