105 lines
4.8 KiB
TypeScript
105 lines
4.8 KiB
TypeScript
// Movement/Tests/FT_DiagonalMovement.ts
|
|
|
|
import { AC_DebugHUD } from '#root/Debug/Components/AC_DebugHUD.ts';
|
|
import { AC_Movement } from '#root/Movement/Components/AC_Movement.ts';
|
|
import { EFunctionalTestResult } from '#root/UE/EFunctionalTestResult.ts';
|
|
import { FunctionalTest } from '#root/UE/FunctionalTest.ts';
|
|
import { MathLibrary } from '#root/UE/MathLibrary.ts';
|
|
import { Vector } from '#root/UE/Vector.ts';
|
|
|
|
/**
|
|
* Functional Test: Diagonal Movement Speed Control
|
|
* Tests that diagonal movement is not faster than cardinal movement
|
|
* Validates input normalization prevents diagonal speed boost
|
|
*/
|
|
export class FT_DiagonalMovement extends FunctionalTest {
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
// GRAPHS
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
|
|
// ────────────────────────────────────────────────────────────────────────────────────────
|
|
// EventGraph
|
|
// ────────────────────────────────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* Test execution - validates diagonal movement speed control
|
|
* Tests cardinal vs diagonal movement speeds
|
|
*/
|
|
EventStartTest(): void {
|
|
// Initialize movement system
|
|
this.MovementComponent.InitializeMovementSystem(this.DebugHUDComponent);
|
|
|
|
// Test 1: Cardinal movement (forward only)
|
|
for (let i = 0; i < 100; i++) {
|
|
this.MovementComponent.ProcessMovementInput(
|
|
new Vector(1.0, 0, 0), // Pure forward
|
|
0.016
|
|
);
|
|
}
|
|
const cardinalSpeed = this.MovementComponent.CurrentSpeed;
|
|
|
|
// Reset velocity
|
|
this.MovementComponent.CurrentVelocity = new Vector(0, 0, 0);
|
|
|
|
// Test 2: Diagonal movement (forward + right)
|
|
for (let i = 0; i < 100; i++) {
|
|
this.MovementComponent.ProcessMovementInput(
|
|
new Vector(1.0, 1.0, 0), // Diagonal input
|
|
0.016
|
|
);
|
|
}
|
|
const diagonalSpeed = this.MovementComponent.CurrentSpeed;
|
|
|
|
// Test 3: Diagonal should not be faster than cardinal
|
|
if (diagonalSpeed <= cardinalSpeed + 1) {
|
|
// Small tolerance for floating point
|
|
// Test 4: Both speeds should be close to MaxSpeed
|
|
if (
|
|
cardinalSpeed >=
|
|
this.MovementComponent.MovementConstants.MaxSpeed - 50 &&
|
|
diagonalSpeed >= this.MovementComponent.MovementConstants.MaxSpeed - 50
|
|
) {
|
|
// Test 5: Test input normalization directly
|
|
const rawDiagonalInput = new Vector(1.0, 1.0, 0);
|
|
const inputMagnitude = MathLibrary.VectorLength(rawDiagonalInput);
|
|
|
|
if (inputMagnitude > 1.0) {
|
|
// This confirms our diagonal input needs normalization
|
|
this.FinishTest(EFunctionalTestResult.Succeeded);
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Diagonal input magnitude should be > 1.0, got ${inputMagnitude}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Speeds too low: Cardinal=${cardinalSpeed}, Diagonal=${diagonalSpeed}, Expected~${this.MovementComponent.MovementConstants.MaxSpeed}`
|
|
);
|
|
}
|
|
} else {
|
|
this.FinishTest(
|
|
EFunctionalTestResult.Failed,
|
|
`Diagonal speed ${diagonalSpeed} exceeds cardinal speed ${cardinalSpeed}`
|
|
);
|
|
}
|
|
}
|
|
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
// VARIABLES
|
|
// ════════════════════════════════════════════════════════════════════════════════════════
|
|
|
|
/**
|
|
* Movement system component - component under test
|
|
* @category Components
|
|
*/
|
|
private MovementComponent = new AC_Movement();
|
|
|
|
/**
|
|
* Debug HUD system - displays test status and parameters
|
|
* @category Components
|
|
*/
|
|
private DebugHUDComponent = new AC_DebugHUD();
|
|
}
|