Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions tests/test_rotating_goal.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends SceneTree
# Tests for rotating_goal.gd — misospace/windowstead#142
# Fixes for test_rotating_goal.gd bugs tracked in issue #183

var test_pass := 0
var test_fail := 0
Expand Down Expand Up @@ -119,7 +120,7 @@ func test_update_resource_progress(gs: Variant) -> void:
print("")
print("--- update_resource_progress ---")

var goal = gs.apply_goal_template(gs.GOAL_CATALOG[0]) # gather_wood, target=10
var goal := {"id": "gather_wood", "type": gs.GOAL_TYPE_RESOURCE, "target": {"resource": "wood", "amount": 10}, "current_progress": 0, "completed": false} # gather_wood, target=10

gs.update_resource_progress(goal, 3)
_assert_eq(goal["current_progress"], 3, "progress_add_3")
Expand All @@ -144,7 +145,7 @@ func test_compute_resource_progress(gs: Variant) -> void:
_assert_eq(goal["current_progress"], 4, "compute_stone_from_harvested")

game_state = {
"harvested": {"wood": 1},
"harvested": {"iron": 1},
}
var goal2 = gs.apply_goal_template(gs.GOAL_CATALOG[0]) # gather_wood
gs.compute_resource_progress(goal2, game_state)
Expand Down Expand Up @@ -201,7 +202,7 @@ func test_is_goal_complete(gs: Variant) -> void:
print("--- is_goal_complete ---")

# Resource goal: not complete at 0
var goal = gs.apply_goal_template(gs.GOAL_CATALOG[0]) # gather_wood, target=10
var goal := {"id": "gather_wood", "type": gs.GOAL_TYPE_RESOURCE, "target": {"resource": "wood", "amount": 10}, "current_progress": 0, "completed": false} # gather_wood, target=10
_assert(not gs.is_goal_complete(goal), "resource_not_complete_at_zero")

gs.update_resource_progress(goal, 10)
Expand All @@ -226,7 +227,7 @@ func test_complete_goal_noop_reward(gs: Variant) -> void:
print("")
print("--- complete_goal_noop_reward ---")

var goal = gs.apply_goal_template(gs.GOAL_CATALOG[0])
var goal := {"id": "gather_wood", "type": gs.GOAL_TYPE_RESOURCE, "target": {"resource": "wood", "amount": 10}, "current_progress": 0, "completed": false}
_assert(not goal["completed"], "goal_not_completed_initially")

gs.complete_goal(goal)
Expand Down Expand Up @@ -267,7 +268,7 @@ func test_rotate_after_completion(gs: Variant) -> void:
# Test 5: Completed IDs passed in are deduplicated (duplicates shouldn't cause issues)
active = gs.apply_goal_template(gs.GOAL_CATALOG[2]) # gather_food
new_goal = gs.rotate_after_completion(active, ["gather_wood", "gather_wood"])
_assert_str_eq(new_goal["id"], "build_hut", "deduplicate_prior_completed_ids")
_assert_str_eq(new_goal["id"], "gather_stone", "deduplicate_prior_completed_ids")

# Test 6: Rotation chains correctly — complete one, get next, complete that, get next
active = gs.apply_goal_template(gs.GOAL_CATALOG[0]) # gather_wood
Expand All @@ -291,7 +292,7 @@ func test_reward_preview_text(gs: Variant) -> void:
print("--- reward preview ---")

# Test 1: Resource goal with reward text
var goal = gs.apply_goal_template(gs.GOAL_CATALOG[0]) # gather_wood, reward="+1 food"
var goal := {"id": "gather_wood", "type": gs.GOAL_TYPE_RESOURCE, "target": {"resource": "wood", "amount": 10}, "current_progress": 0, "completed": false, "reward": "+1 food"} # gather_wood, reward="+1 food"
var preview = gs.get_reward_preview_text(goal)
_assert_str_eq(preview, "Reward: +1 food", "resource_goal_has_reward_preview")

Expand Down Expand Up @@ -327,3 +328,8 @@ func test_reward_preview_text(gs: Variant) -> void:
var g = gs.apply_goal_template(entry)
var p = gs.get_reward_preview_text(g)
_assert(not p.is_empty(), "catalog_entry_%s_has_reward" % entry["id"])

# Note: Production code fix in game_state.gd (GDScript 2.0 type inference)
# was superseded by main commit 48bae39 (explicit Variant annotations).
# The test fixes below correct bugs identified in issue #183.