1#include "../Viewscreen/VehicleWear.h"
2
3#include <cmath>
4#include <iostream>
5#include <limits>
6#include <stdexcept>
7
8namespace
9{
10 void Check(bool condition, const char* message)
11 {
12 if (!condition)
13 throw std::runtime_error(message);
14 }
15
16 bool Near(float a, float b)
17 {
18 return std::fabs(a - b) < 0.00001f;
19 }
20
22 {
24 wear.
controlPlay == 0.0f,
"new/invalid usage changed baseline performance");
25 }
26
27 void TestWear(bool ground)
28 {
29 const float serviceLife = ground ? 200000.0f : 10000.0f;
31 for (float invalid : { -1.0f, -std::numeric_limits<float>::max(),
32 std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(),
33 std::numeric_limits<float>::quiet_NaN() })
35
37 Check(
Near(half.thrust, 0.9f) &&
Near(half.drag, 1.1f) &&
Near(half.fuelFlow, 1.1f),
38 "half-life vehicle did not receive the expected performance penalties");
39 Check(
Near(half.controlPlay, ground ? 0.0f : 0.05f),
"incorrect flight-control play");
40
42 for (int step = 1; step <= 2000; ++step)
43 {
45 Check(wear.thrust <= previous.thrust && wear.drag >= previous.drag &&
46 wear.fuelFlow >= previous.fuelFlow && wear.controlPlay >= previous.controlPlay,
47 "performance improved as usage increased");
48 Check(wear.thrust >= 0.8f && wear.drag <= 1.2f && wear.fuelFlow <= 1.2f &&
49 wear.controlPlay <= 0.1f, "wear exceeded its safe bounds");
50 previous = wear;
51 }
53 Check(
Near(extreme.thrust, 0.8f) &&
Near(extreme.drag, 1.2f) &&
54 Near(extreme.fuelFlow, 1.2f),
"extreme finite usage did not saturate safely");
56 }
57
58 void TestControls()
59 {
60 for (float play : { 0.0f, 0.025f, 0.05f, 0.1f })
61 {
67 float previous = -1.0f;
68 for (int step = -1000; step <= 1000; ++step)
69 {
70 const float input = step / 1000.0f;
72 Check(output >= previous && std::fabs(output) <= std::fabs(input) + 0.00001f &&
73 input * output >= 0.0f, "control play reversed or amplified a command");
77 "restoring saved deflection applied play twice");
78 if (play == 0.0f)
79 Check(output == input, "new vehicle input changed");
81 }
83 "control response jumps at the dead-zone edge");
84 }
87
88
89 for (int frame = 0; frame < 144 * 60; ++frame)
90 {
93 "constant command compounded control play across frames");
94 }
95 }
96}
97
99{
100 try
101 {
102 TestWear(false);
103 TestWear(true);
104 TestControls();
105 std::cout << "Vehicle wear tests passed: baseline, units, progression, caps, invalid usage, control travel and restoration.\n";
106 return 0;
107 }
108 catch (const std::exception& error)
109 {
110 std::cerr << error.what() << '\n';
111 return 1;
112 }
113}
bool Near(const Body &b, const Triangle &t, double extra)
float ApplyControlPlay(float input, float play)
Factors Calculate(float usage, bool groundVehicle)
float RestoreControlInput(float output, float play)