Fix research
This commit is contained in:
78
tests/test_gold_mine_click.gd
Normal file
78
tests/test_gold_mine_click.gd
Normal file
@@ -0,0 +1,78 @@
|
||||
extends Node
|
||||
|
||||
var passed: int = 0
|
||||
var failed: int = 0
|
||||
var _game_root: Node = null
|
||||
|
||||
func _ready():
|
||||
await run()
|
||||
if failed == 0:
|
||||
get_tree().quit(0)
|
||||
else:
|
||||
get_tree().quit(1)
|
||||
|
||||
func run():
|
||||
print("\n=== TEST: Gold Mine Click ===\n")
|
||||
TestUtils.set_test_name("gold_mine_click")
|
||||
|
||||
# Load tiny_sword scene
|
||||
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
|
||||
_game_root = scene.instantiate()
|
||||
add_child(_game_root)
|
||||
|
||||
await _wait()
|
||||
|
||||
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
|
||||
var gold_mine = _game_root.find_child("GoldMine") as CurrencyGenerator
|
||||
|
||||
if game_state == null:
|
||||
print("[ERROR] LevelGameState not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
if gold_mine == null:
|
||||
print("[ERROR] GoldMine node not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
# Record initial gold
|
||||
var initial_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
print("[TARGET] initial_gold: %s" % initial_gold.to_string_suffix(2))
|
||||
|
||||
# Simulate clicking the generator
|
||||
gold_mine._on_pressed()
|
||||
|
||||
await _wait()
|
||||
|
||||
# Validate gold increased
|
||||
var final_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
print("[TARGET] final_gold: %s" % final_gold.to_string_suffix(2))
|
||||
|
||||
TestUtils.assert_greater_than(
|
||||
final_gold.mantissa,
|
||||
initial_gold.mantissa,
|
||||
"Gold increased after generator click"
|
||||
)
|
||||
|
||||
# Check specific value (adjust based on click_mantissa in data)
|
||||
var expected_min: float = initial_gold.mantissa + 1.0
|
||||
TestUtils.assert_true(
|
||||
final_gold.mantissa >= expected_min,
|
||||
"Gold increased by at least 1.0"
|
||||
)
|
||||
|
||||
_print_summary()
|
||||
|
||||
func _wait() -> void:
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
|
||||
func _print_summary():
|
||||
TestUtils.print_result()
|
||||
passed = TestUtils.get_passed()
|
||||
failed = TestUtils.get_failed()
|
||||
|
||||
func get_passed() -> int:
|
||||
return passed
|
||||
|
||||
func get_failed() -> int:
|
||||
return failed
|
||||
1
tests/test_gold_mine_click.gd.uid
Normal file
1
tests/test_gold_mine_click.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c2xborf2klkc4
|
||||
94
tests/test_prestige.gd
Normal file
94
tests/test_prestige.gd
Normal file
@@ -0,0 +1,94 @@
|
||||
extends Node
|
||||
|
||||
var passed: int = 0
|
||||
var failed: int = 0
|
||||
var _game_root: Node = null
|
||||
|
||||
func _ready():
|
||||
await run()
|
||||
if failed == 0:
|
||||
get_tree().quit(0)
|
||||
else:
|
||||
get_tree().quit(1)
|
||||
|
||||
func run():
|
||||
print("\n=== TEST: Prestige Mechanics ===\n")
|
||||
TestUtils.set_test_name("prestige")
|
||||
|
||||
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
|
||||
_game_root = scene.instantiate()
|
||||
add_child(_game_root)
|
||||
|
||||
await _wait()
|
||||
|
||||
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
|
||||
var prestige_manager = _game_root.find_child("PrestigeManager") as PrestigeManager
|
||||
|
||||
if game_state == null:
|
||||
print("[ERROR] LevelGameState not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
if prestige_manager == null:
|
||||
print("[ERROR] PrestigeManager not found")
|
||||
_print_summary()
|
||||
return
|
||||
|
||||
# Setup: Accumulate currencies to meet prestige threshold
|
||||
game_state.add_currency_by_id(&"gold", BigNumber.from_float(100000.0))
|
||||
game_state.add_currency_by_id(&"gems", BigNumber.from_float(100.0))
|
||||
|
||||
await _wait()
|
||||
|
||||
# Check if can prestige
|
||||
var can_prestige: bool = prestige_manager.can_prestige()
|
||||
print("[TARGET] can_prestige: %s" % str(can_prestige))
|
||||
|
||||
TestUtils.assert_true(can_prestige, "Should be able to prestige after accumulating currencies")
|
||||
|
||||
if can_prestige:
|
||||
# Perform prestige
|
||||
prestige_manager.perform_prestige()
|
||||
|
||||
await _wait()
|
||||
|
||||
# Check ascension currency
|
||||
var ascension: BigNumber = game_state.get_currency_amount_by_id(&"ascension")
|
||||
print("[TARGET] ascension_currency: %s" % ascension.to_string_suffix(2))
|
||||
|
||||
TestUtils.assert_true(
|
||||
ascension.mantissa > 0,
|
||||
"Should receive ascension currency after prestige"
|
||||
)
|
||||
|
||||
# Check prestige multiplier increased
|
||||
var total_multiplier = prestige_manager.get_total_multiplier()
|
||||
print("[TARGET] total_multiplier: %s" % str(total_multiplier))
|
||||
|
||||
var mult_value: float
|
||||
if total_multiplier is float:
|
||||
mult_value = total_multiplier
|
||||
else:
|
||||
mult_value = float(total_multiplier)
|
||||
|
||||
TestUtils.assert_greater_than(
|
||||
mult_value,
|
||||
1.0,
|
||||
"Prestige multiplier should be > 1.0"
|
||||
)
|
||||
|
||||
_print_summary()
|
||||
|
||||
func _wait() -> void:
|
||||
await get_tree().create_timer(0.5).timeout
|
||||
|
||||
func _print_summary():
|
||||
TestUtils.print_result()
|
||||
passed = TestUtils.get_passed()
|
||||
failed = TestUtils.get_failed()
|
||||
|
||||
func get_passed() -> int:
|
||||
return passed
|
||||
|
||||
func get_failed() -> int:
|
||||
return failed
|
||||
1
tests/test_prestige.gd.uid
Normal file
1
tests/test_prestige.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://mm5vcjq44wf1
|
||||
146
tests/test_research_xp_acquisition.gd
Normal file
146
tests/test_research_xp_acquisition.gd
Normal file
@@ -0,0 +1,146 @@
|
||||
extends SceneTree
|
||||
|
||||
var passed: int = 0
|
||||
var failed: int = 0
|
||||
var _game_root: Node = null
|
||||
var _test_complete: bool = false
|
||||
|
||||
func _init():
|
||||
print("\n=== TEST: Research XP Acquisition ===\n")
|
||||
TestUtils.set_test_name("research_xp_acquisition")
|
||||
|
||||
# Load tiny_sword scene
|
||||
var scene = load("res://docs/gyms/tiny_sword/tiny_sword.tscn")
|
||||
change_scene_to_packed(scene)
|
||||
|
||||
await _wait()
|
||||
|
||||
_game_root = root.get_child(0)
|
||||
|
||||
var game_state: LevelGameState = _game_root.find_child("LevelGameState")
|
||||
|
||||
if game_state == null:
|
||||
print("[ERROR] LevelGameState not found")
|
||||
_print_summary()
|
||||
_test_complete = true
|
||||
quit(1)
|
||||
return
|
||||
|
||||
# Find GoldMine CurrencyGenerator
|
||||
var gold_mine: CurrencyGenerator = null
|
||||
var world = game_state.get_node_or_null("World")
|
||||
if world:
|
||||
for child in world.get_children():
|
||||
if child.get_name() == "GoldMine":
|
||||
for gc_child in child.get_children():
|
||||
if gc_child is CurrencyGenerator:
|
||||
gold_mine = gc_child
|
||||
break
|
||||
|
||||
if gold_mine == null:
|
||||
print("[ERROR] GoldMine CurrencyGenerator node not found")
|
||||
_print_summary()
|
||||
_test_complete = true
|
||||
quit(1)
|
||||
return
|
||||
|
||||
# Give the generator initial ownership so clicks work properly
|
||||
if gold_mine.owned <= 0:
|
||||
game_state.add_currency_by_id(&"worker", BigNumber.from_float(100.0))
|
||||
await _wait(0.05)
|
||||
gold_mine.buy(1)
|
||||
await _wait(0.05)
|
||||
|
||||
# Get initial gold currency
|
||||
var initial_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
print("[TARGET] initial_gold: mantissa=%s, exponent=%s" % [initial_gold.mantissa, initial_gold.exponent])
|
||||
|
||||
# Get initial research XP
|
||||
var initial_xp: BigNumber = game_state.get_research_xp(&"gold_research")
|
||||
print("[TARGET] initial_research_xp: mantissa=%s, exponent=%s" % [initial_xp.mantissa, initial_xp.exponent])
|
||||
|
||||
# Set press_buys_generator to false so clicks grant currency instead of buying
|
||||
gold_mine.press_buys_generator = false
|
||||
|
||||
# Simulate clicking the generator multiple times to produce currency
|
||||
var click_count: int = 5
|
||||
for i in range(click_count):
|
||||
gold_mine._on_pressed()
|
||||
await _wait(0.1)
|
||||
|
||||
# Check gold increased
|
||||
var final_gold: BigNumber = game_state.get_currency_amount_by_id(&"gold")
|
||||
print("[TARGET] final_gold: mantissa=%s, exponent=%s" % [final_gold.mantissa, final_gold.exponent])
|
||||
|
||||
# Check owned count
|
||||
var owned: int = gold_mine.owned
|
||||
print("[TARGET] gold_mine_owned: %d" % owned)
|
||||
|
||||
# Validate research XP increased
|
||||
var final_xp: BigNumber = game_state.get_research_xp(&"gold_research")
|
||||
print("[TARGET] final_research_xp: mantissa=%s, exponent=%s" % [final_xp.mantissa, final_xp.exponent])
|
||||
|
||||
TestUtils.assert_true(
|
||||
final_xp.is_greater_than(initial_xp),
|
||||
"Research XP increased after generator clicks"
|
||||
)
|
||||
|
||||
# Test level calculation
|
||||
var level: int = game_state.get_research_level(&"gold_research")
|
||||
print("[TARGET] research_level: %d" % level)
|
||||
|
||||
TestUtils.assert_true(
|
||||
level >= 0,
|
||||
"Research level is non-negative"
|
||||
)
|
||||
|
||||
# Test research multiplier
|
||||
var multiplier: float = game_state.get_research_multiplier(&"gold_research")
|
||||
print("[TARGET] research_multiplier: %f" % multiplier)
|
||||
|
||||
TestUtils.assert_greater_than(
|
||||
multiplier,
|
||||
0.0,
|
||||
"Research multiplier is positive"
|
||||
)
|
||||
|
||||
# Test BigNumber XP progress calculation
|
||||
var research_data: ResearchData = game_state.research_catalogue.get_research_by_id(&"gold_research")
|
||||
if research_data != null:
|
||||
var progress: float = research_data.get_xp_progress(final_xp)
|
||||
print("[TARGET] xp_progress: %f" % progress)
|
||||
|
||||
TestUtils.assert_true(
|
||||
progress >= 0.0 and progress <= 1.0,
|
||||
"XP progress is between 0.0 and 1.0"
|
||||
)
|
||||
|
||||
# Test level calculation with BigNumber
|
||||
var calculated_level: int = research_data.get_level_for_xp(final_xp)
|
||||
print("[TARGET] calculated_level: %d" % calculated_level)
|
||||
|
||||
TestUtils.assert_true(
|
||||
calculated_level >= 0,
|
||||
"Calculated level is non-negative"
|
||||
)
|
||||
|
||||
_print_summary()
|
||||
_test_complete = true
|
||||
if failed == 0:
|
||||
quit(0)
|
||||
else:
|
||||
quit(1)
|
||||
|
||||
func _wait(seconds: float = 0.1) -> void:
|
||||
await create_timer(seconds).timeout
|
||||
|
||||
func _print_summary():
|
||||
TestUtils.print_result()
|
||||
passed = TestUtils.get_passed()
|
||||
failed = TestUtils.get_failed()
|
||||
|
||||
func get_passed() -> int:
|
||||
return passed
|
||||
|
||||
func get_failed() -> int:
|
||||
return failed
|
||||
1
tests/test_research_xp_acquisition.gd.uid
Normal file
1
tests/test_research_xp_acquisition.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cq65acistj7ar
|
||||
64
tests/test_runner.gd
Normal file
64
tests/test_runner.gd
Normal file
@@ -0,0 +1,64 @@
|
||||
extends Node
|
||||
|
||||
var test_scripts: Array[String] = []
|
||||
var test_index: int = 0
|
||||
var total_passed: int = 0
|
||||
var total_failed: int = 0
|
||||
|
||||
func _ready():
|
||||
print("\n=== GODOT TEST RUNNER ===\n")
|
||||
_discover_tests()
|
||||
|
||||
if test_scripts.is_empty():
|
||||
print("[ERROR] No test scripts found in res://tests/")
|
||||
print("[RESULT] FAIL")
|
||||
get_tree().quit(1)
|
||||
return
|
||||
|
||||
print("Found %d test(s): %s\n" % [test_scripts.size(), str(test_scripts)])
|
||||
|
||||
await _run_next_test()
|
||||
|
||||
print("\n=== TEST SUMMARY ===")
|
||||
print("Total passed: %d" % total_passed)
|
||||
print("Total failed: %d" % total_failed)
|
||||
|
||||
if total_failed == 0:
|
||||
print("[OVERALL_RESULT] PASS")
|
||||
get_tree().quit(0)
|
||||
else:
|
||||
print("[OVERALL_RESULT] FAIL")
|
||||
get_tree().quit(1)
|
||||
|
||||
func _discover_tests() -> void:
|
||||
var dir = DirAccess.open("res://tests")
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
if file_name.ends_with(".gd") and file_name.begins_with("test_") and \
|
||||
file_name != "test_runner.gd" and file_name != "test_utils.gd":
|
||||
test_scripts.append("res://tests/%s" % file_name)
|
||||
file_name = dir.get_next()
|
||||
dir.list_dir_end()
|
||||
test_scripts.sort()
|
||||
|
||||
func _run_next_test() -> void:
|
||||
if test_index >= test_scripts.size():
|
||||
return
|
||||
|
||||
var test_script = test_scripts[test_index]
|
||||
print("--- Running test %d/%d: %s ---" % [test_index + 1, test_scripts.size(), test_script])
|
||||
print("")
|
||||
|
||||
# Load and run test
|
||||
var test_instance = load(test_script).new()
|
||||
add_child(test_instance)
|
||||
await test_instance.run()
|
||||
|
||||
total_passed += test_instance.get_passed()
|
||||
total_failed += test_instance.get_failed()
|
||||
|
||||
print("")
|
||||
test_index += 1
|
||||
await _run_next_test()
|
||||
1
tests/test_runner.gd.uid
Normal file
1
tests/test_runner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://chame3fmeexw6
|
||||
74
tests/test_utils.gd
Normal file
74
tests/test_utils.gd
Normal file
@@ -0,0 +1,74 @@
|
||||
class_name TestUtils
|
||||
extends RefCounted
|
||||
|
||||
static var _test_name: String = ""
|
||||
static var _passed: int = 0
|
||||
static var _failed: int = 0
|
||||
|
||||
static func set_test_name(name: String) -> void:
|
||||
_test_name = name
|
||||
_passed = 0
|
||||
_failed = 0
|
||||
|
||||
static func assert_equals(expected: Variant, actual: Variant, message: String) -> void:
|
||||
if expected == actual:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s (expected %s, got %s)" % [
|
||||
_test_name, message, str(expected), str(actual)
|
||||
])
|
||||
_failed += 1
|
||||
|
||||
static func assert_true(condition: bool, message: String) -> void:
|
||||
if condition:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s" % [_test_name, message])
|
||||
_failed += 1
|
||||
|
||||
static func assert_false(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s (expected false, got true)" % [_test_name, message])
|
||||
_failed += 1
|
||||
|
||||
static func assert_greater_than(a: float, b: float, message: String) -> void:
|
||||
if a > b:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s (expected %s > %s)" % [_test_name, message, str(a), str(b)])
|
||||
_failed += 1
|
||||
|
||||
static func assert_greater_or_equal(a: float, b: float, message: String) -> void:
|
||||
if a >= b:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s (expected %s >= %s)" % [_test_name, message, str(a), str(b)])
|
||||
_failed += 1
|
||||
|
||||
static func assert_not_null(value: Variant, message: String) -> void:
|
||||
if value != null:
|
||||
print("[PASS] %s: %s" % [_test_name, message])
|
||||
_passed += 1
|
||||
else:
|
||||
print("[FAIL] %s: %s" % [_test_name, message])
|
||||
_failed += 1
|
||||
|
||||
static func get_passed() -> int:
|
||||
return _passed
|
||||
|
||||
static func get_failed() -> int:
|
||||
return _failed
|
||||
|
||||
static func print_result() -> void:
|
||||
print("[SUMMARY] %s: %d passed, %d failed" % [_test_name, _passed, _failed])
|
||||
if _failed == 0:
|
||||
print("[RESULT] PASS")
|
||||
else:
|
||||
print("[RESULT] FAIL")
|
||||
1
tests/test_utils.gd.uid
Normal file
1
tests/test_utils.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ous5m4c7jotn
|
||||
Reference in New Issue
Block a user