Files
Ransom-s-wake/tests/unit/run_site_application_tests.gd
2026-10-06 19:55:19 +02:00

43 lines
1.7 KiB
GDScript

extends SceneTree
const PlayableBoundsRule = preload("res://game/application/sites/playable_bounds_rule.gd")
const PlayableBoundsStatus = preload("res://game/application/sites/playable_bounds_status.gd")
const TEST_COUNT := 9
var _failures: Array[String] = []
func _init() -> void:
_test_bounds_rule()
if _failures.is_empty():
print("Site application unit tests: %d passed, 0 failed." % TEST_COUNT)
quit(0)
else:
for failure: String in _failures:
push_error(failure)
print("Site application unit tests: %d failed." % _failures.size())
quit(1)
func _test_bounds_rule() -> void:
var rule := PlayableBoundsRule.new(Rect2(-300.0, -300.0, 600.0, 600.0), 40.0)
var centre := rule.evaluate(Vector3(0.0, -20.0, 0.0))
_expect(centre.state == PlayableBoundsStatus.State.INSIDE, "centre is inside")
_expect(is_equal_approx(centre.distance_to_edge_m, 300.0), "distance to the nearest edge")
_expect(not centre.requires_warning(), "inside needs no warning")
var near := rule.evaluate(Vector3(275.0, -20.0, 10.0))
_expect(near.state == PlayableBoundsStatus.State.NEAR_EDGE, "within the margin is near the edge")
_expect(is_equal_approx(near.distance_to_edge_m, 25.0), "near edge distance is measured to the east edge")
_expect(near.return_direction.is_equal_approx(Vector3.LEFT), "return direction points back toward the centre")
var outside := rule.evaluate(Vector3(0.0, -20.0, -340.0))
_expect(outside.state == PlayableBoundsStatus.State.OUTSIDE, "beyond the edge is outside")
_expect(is_equal_approx(outside.distance_to_edge_m, -40.0), "outside distance is negative")
_expect(outside.return_direction.is_equal_approx(Vector3.BACK), "outside north returns south")
func _expect(condition: bool, label: String) -> void:
if not condition:
_failures.append(label)