Files
idle/tests/test_research_activation.gd
Michele Rossi 81a4058b04 systems rework: buffs, prestige graph, research, modular architecture
Decouples core systems from centralized globals in favor of catalogue-based architecture and data-driven content.

   Key changes:
   - Prestige: node-based buff tech tree, graph panel, progress bar
   - Research: multi-worker system, per-generator research, xp generation
   - Ascension: meta-currency layer via multi-currency prestige resets
   - Buffs: refactored as generator-independent via catalogues
   - UI: currency panel, edge-scrolling camera + zoom, current-goal panel
   - Alchemy Tower: crafting building with recipe/cost system
   - Testing: 7 test suites (ascension, prestige, research, goals)
   - Content: migrated from hardcoded idles/ to gym format (tiny_sword)
2026-05-07 20:36:21 +00:00

160 lines
5.2 KiB
GDScript

extends SceneTree
var passed: int = 0
var failed: int = 0
var _game_root: Node = null
var _local_passed: int = 0
var _local_failed: int = 0
func _init():
await run()
func run():
print("\n=== TEST: Research Activation ===\n")
TestUtils.set_test_name("research_activation")
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
_game_root = scene.instantiate()
root.add_child(_game_root)
await _wait()
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
var research_panel: ResearchPanel = _game_root.find_child("ResearchPanel") as ResearchPanel
if game_state == null or research_panel == null:
print("[ERROR] Missing LevelGameState or ResearchPanel node")
_print_summary()
quit(1)
return
var gold_mine_node = game_state.find_child("GoldMine")
var gold_mine: CurrencyGenerator = gold_mine_node.find_child("CurrencyGenerator") as CurrencyGenerator if gold_mine_node else null
if gold_mine == null:
print("[ERROR] GoldMine node not found")
_print_summary()
quit(1)
return
# Test 1: Verify initial state - no research should be active
print("[TARGET] initial_active_research_id: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"",
"No research active initially"
)
# Test 2: Verify gold mine research exists and is linked to goldmine generator
var gold_research = game_state.research_catalogue.get_research_by_id(&"gold_research")
TestUtils.assert_not_null(
gold_research,
"Gold research exists in catalogue"
)
if gold_research != null:
TestUtils.assert_true(
gold_research.generator_id == &"goldmine",
"Gold research is linked to goldmine generator"
)
# Test 3: Activate gold research
research_panel.activate_research(&"gold_research")
await _wait()
print("[TARGET] active_after_gold_activation: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"gold_research",
"Gold research is active after activation"
)
TestUtils.assert_true(
research_panel.is_research_active(&"gold_research"),
"is_research_active returns true for gold_research"
)
# Test 4: Verify research XP is granted when research is active
var initial_gold_research_xp = game_state.get_research_xp(&"gold_research")
print("[TARGET] initial_gold_research_xp: %s" % initial_gold_research_xp.to_string_suffix(2))
# Simulate gold mine production (gold mine grants XP to gold_research)
gold_mine._on_pressed()
await _wait()
var final_gold_research_xp_active = game_state.get_research_xp(&"gold_research")
print("[TARGET] final_gold_research_xp_active: %s" % final_gold_research_xp_active.to_string_suffix(2))
TestUtils.assert_true(
final_gold_research_xp_active.mantissa > initial_gold_research_xp.mantissa,
"Gold research XP increases when active (gold mine produces)"
)
# Test 5: Deactivate gold research by activating another research
var farm_research = game_state.research_catalogue.get_research_by_id(&"farm_research")
TestUtils.assert_not_null(
farm_research,
"Farm research exists in catalogue"
)
if farm_research != null:
# Activate farm research (should deactivate gold research)
research_panel.activate_research(&"farm_research")
await _wait()
print("[TARGET] active_after_farm_activation: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"farm_research",
"Farm research is active after activation"
)
TestUtils.assert_false(
research_panel.is_research_active(&"gold_research"),
"Gold research is deactivated when farm is activated"
)
# Test 6: Verify research XP is NOT granted when research is inactive
var initial_gold_research_xp_inactive = game_state.get_research_xp(&"gold_research")
print("[TARGET] initial_gold_research_xp_inactive: %s" % initial_gold_research_xp_inactive.to_string_suffix(2))
# Simulate gold mine production (gold mine should NOT grant XP to inactive gold_research)
gold_mine._on_pressed()
await _wait()
var final_gold_research_xp_inactive = game_state.get_research_xp(&"gold_research")
print("[TARGET] final_gold_research_xp_inactive: %s" % final_gold_research_xp_inactive.to_string_suffix(2))
TestUtils.assert_equals(
final_gold_research_xp_inactive.mantissa,
initial_gold_research_xp_inactive.mantissa,
"Gold research XP does not increase when inactive (gold mine produces)"
)
# Test 7: Test mutual exclusivity with multiple activations
research_panel.activate_research(&"gold_research")
await _wait()
research_panel.activate_research(&"farm_research")
await _wait()
research_panel.activate_research(&"gold_research")
await _wait()
print("[TARGET] final_active_research_id: %s" % research_panel.get_active_research_id())
TestUtils.assert_true(
research_panel.get_active_research_id() == &"gold_research",
"Only one research can be active at a time"
)
_print_summary()
if failed == 0:
quit(0)
else:
quit(1)
func _wait() -> void:
await create_timer(0.5).timeout
func _print_summary():
TestUtils.print_result()
_local_passed = TestUtils.get_passed()
_local_failed = TestUtils.get_failed()
passed = _local_passed
failed = _local_failed