129 lines
5.9 KiB
TypeScript
129 lines
5.9 KiB
TypeScript
// Movement/Tests/FT_BasicMovement.ts
|
|
|
|
import { AC_Movement } from '#root/Movement/Components/AC_Movement.ts';
|
|
import { E_MovementState } from '#root/Movement/Enums/E_MovementState.ts';
|
|
import { EFunctionalTestResult } from '#root/UE/EFunctionalTestResult.ts';
|
|
import { FunctionalTest } from '#root/UE/FunctionalTest.ts';
|
|
import { Vector } from '#root/UE/Vector.ts';
|
|
|
|
/**
|
|
* Functional Test: Basic Movement System
|
|
* Tests fundamental movement mechanics: acceleration, friction, max speed
|
|
* Validates movement state transitions and input processing
|
|
*/
|
|
export class FT_BasicMovement extends FunctionalTest {
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
// GRAPHS
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────────────────
|
|
// EventGraph
|
|
// ────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Test execution - validates basic movement functionality
|
|
* Tests initialization, input processing, state management
|
|
*/
|
|
EventStartTest(): void {
|
|
// Initialize movement system
|
|
this.MovementComponent.InitializeMovementSystem();
|
|
|
|
// Test 1: Initialization
|
|
if (this.MovementComponent.IsInitialized) {
|
|
// Test 2: Initial state should be Idle
|
|
if (this.MovementComponent.MovementState === E_MovementState.Idle) {
|
|
// Test 3: Process forward input and verify acceleration
|
|
this.MovementComponent.ProcessMovementInput(
|
|
new Vector(1.0, 0, 0), // Forward input
|
|
0.016 // 60 FPS delta
|
|
);
|
|
|
|
if (this.MovementComponent.CurrentVelocity.X > 0) {
|
|
// Test 4: Movement state should change to Walking
|
|
if (
|
|
(this.MovementComponent.MovementState as string) ===
|
|
(E_MovementState.Walking as string)
|
|
) {
|
|
// Test 5: Process multiple frames to test max speed limit
|
|
for (let i = 0; i < 100; i++) {
|
|
this.MovementComponent.ProcessMovementInput(
|
|
new Vector(1.0, 0, 0),
|
|
0.016
|
|
);
|
|
}
|
|
|
|
// Verify max speed is not exceeded
|
|
if (
|
|
this.MovementComponent.CurrentSpeed <=
|
|
this.MovementComponent.MovementConstants.MaxSpeed + 1
|
|
) {
|
|
// Test 6: Test friction by removing input
|
|
for (let i = 0; i < 50; i++) {
|
|
this.MovementComponent.ProcessMovementInput(
|
|
new Vector(0, 0, 0), // No input
|
|
0.016
|
|
);
|
|
}
|
|
|
|
// Verify friction slowed down the character
|
|
if (this.MovementComponent.CurrentSpeed < 50) {
|
|
// Test 7: Verify state changed back to Idle when stopped
|
|
if (
|
|
this.MovementComponent.MovementState === E_MovementState.Idle
|
|
) {
|
|
this.FinishTest(EFunctionalTestResult.Succeeded);
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Movement state should be Idle when stopped, got ${this.MovementComponent.MovementState as string}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Friction should reduce speed, current speed: ${this.MovementComponent.CurrentSpeed}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Speed ${this.MovementComponent.CurrentSpeed} exceeds MaxSpeed ${this.MovementComponent.MovementConstants.MaxSpeed}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Movement state should be Walking with input, got ${this.MovementComponent.MovementState}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
'Forward input should produce forward velocity'
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Initial movement state should be Idle, got ${this.MovementComponent.MovementState}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
'Movement system failed to initialize'
|
|
);
|
|
}
|
|
}
|
|
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
// VARIABLES
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
|
|
/**
|
|
* Movement system component - component under test
|
|
* @category Components
|
|
*/
|
|
private MovementComponent = new AC_Movement();
|
|
}
|