Implement production vertical slice foundation
This commit is contained in:
1 parent
9d4a89f355
commit
a18e82eb44
104 files changed
+10595
-268
No files matched your search
@@ -0,0 +1,79 @@
|
||||
extends SceneTree
|
||||
|
||||
const VehicleCommand = preload("res://game/application/vehicle/vehicle_command.gd")
|
||||
const CameraLookCommand = preload(
|
||||
"res://game/application/vehicle/camera_look_command.gd"
|
||||
)
|
||||
const PilotUseCase = preload("res://game/application/vehicle/pilot_use_case.gd")
|
||||
const VehicleMotionPort = preload(
|
||||
"res://game/application/interfaces/vehicle_motion_port.gd"
|
||||
)
|
||||
|
||||
const TEST_COUNT := 10
|
||||
|
||||
var _failures: Array[String] = []
|
||||
|
||||
|
||||
class RecordingMotionPort extends VehicleMotionPort:
|
||||
var commands: Array[VehicleCommand] = []
|
||||
|
||||
|
||||
func apply_command(command: VehicleCommand) -> void:
|
||||
commands.append(command)
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_test_vehicle_command_contract()
|
||||
_test_camera_command_contract()
|
||||
_test_pilot_use_case_orders_commands()
|
||||
|
||||
if _failures.is_empty():
|
||||
print("Vehicle application unit tests: %d passed, 0 failed." % TEST_COUNT)
|
||||
quit(0)
|
||||
else:
|
||||
for failure: String in _failures:
|
||||
push_error(failure)
|
||||
print("Vehicle application unit tests: %d failed." % _failures.size())
|
||||
quit(1)
|
||||
|
||||
|
||||
func _test_vehicle_command_contract() -> void:
|
||||
var neutral: VehicleCommand = VehicleCommand.neutral(0)
|
||||
_expect(neutral.validation_error().is_empty(), "neutral command is valid")
|
||||
_expect(
|
||||
VehicleCommand.new(-1, 0.0, 0.0, 0.0, false).validation_error()
|
||||
== "vehicle command sequence is negative",
|
||||
"negative sequence is rejected"
|
||||
)
|
||||
_expect(
|
||||
not VehicleCommand.new(0, 1.01, 0.0, 0.0, false).validation_error().is_empty(),
|
||||
"non-normalized axis is rejected"
|
||||
)
|
||||
|
||||
|
||||
func _test_camera_command_contract() -> void:
|
||||
_expect(CameraLookCommand.new(0.2, -0.1).validation_error().is_empty(), "finite camera look is valid")
|
||||
_expect(
|
||||
not CameraLookCommand.new(NAN, 0.0).validation_error().is_empty(),
|
||||
"non-finite camera look is rejected"
|
||||
)
|
||||
|
||||
|
||||
func _test_pilot_use_case_orders_commands() -> void:
|
||||
var port := RecordingMotionPort.new()
|
||||
var pilot := PilotUseCase.new(port)
|
||||
var first = pilot.execute(VehicleCommand.new(0, 1.0, 0.0, 0.0, false))
|
||||
_expect(first.accepted, "first consecutive vehicle command is accepted")
|
||||
_expect(port.commands.size() == 1 and port.commands[0].longitudinal == 1.0, "accepted command reaches motion port")
|
||||
|
||||
var skipped = pilot.execute(VehicleCommand.neutral(2))
|
||||
_expect(not skipped.accepted, "skipped vehicle sequence is rejected")
|
||||
_expect(port.commands.size() == 1, "rejected command does not reach motion port")
|
||||
|
||||
var retry = pilot.execute(VehicleCommand.neutral(1))
|
||||
_expect(retry.accepted and port.commands.size() == 2, "expected sequence remains retryable")
|
||||
|
||||
|
||||
func _expect(condition: bool, label: String) -> void:
|
||||
if not condition:
|
||||
_failures.append(label)
|
||||
Reference in new issue
Block a user