Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/WeatherOverrideTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Viewscreen/WeatherOverrides.h"
2#include "../Viewscreen/CloudVolume.h"
3#include <cstdlib>
4#include <clocale>
5#include <iostream>
6
7static void Check(bool condition, const char* message)
8{
9 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
10}
11
12int main()
13{
14 float value = 7.f;
15 for (const auto* text : {L"2.5", L"+2.5", L" 2.5 "})
16 Check(WeatherOverrides::ParseValue(text, 2, 16, value) && value == 2.5f, "fractional rain");
17 Check(WeatherOverrides::ParseValue(L"2", 2, 16, value) && value == 2, "clear endpoint");
18 Check(WeatherOverrides::ParseValue(L"16", 2, 16, value) && value == 16, "downpour endpoint");
19 Check(WeatherOverrides::ParseValue(L"-1.0", 2, 16, value) && value == -1, "weather reset");
20 for (const auto* text : {L"", L" ", L"-", L"+", L"+-1", L"2.5junk", L"2.5 3", L"2,5", L"nan", L"inf",
21 L"1e999", L"1e-999", L"0", L"1", L"1.99", L"16.01", L"-0.5", L"-2"})
22 {
23 value = 7.f;
24 Check(!WeatherOverrides::ParseValue(text, 2, 16, value) && value == 7.f,
25 "invalid rain leaves the prior value alone");
26 }
27 Check(WeatherOverrides::ParseValue(L"0.125", 0, 10, value) && value == .125f, "125 metre base");
28 Check(WeatherOverrides::ParseValue(L"0", 0, 10, value) && value == 0, "ground-level base");
29 Check(WeatherOverrides::ParseValue(L"10", 0, 10, value) && value == 10, "base upper limit");
30 Check(!WeatherOverrides::ParseValue(L"10.001", 0, 10, value), "base above supported deck");
31 Check(!WeatherOverrides::ParseValue(L"-0.1", 0, 10, value), "negative base is not reset");
32 Check(WeatherOverrides::ParseValue(L"-1", 0, 10, value) && value == -1, "base reset");
33 Check(std::setlocale(LC_NUMERIC, "French_France.1252") != nullptr, "French numeric locale available");
34 Check(WeatherOverrides::ParseValue(L"2.5", 2, 16, value) && value == 2.5f, "decimal point ignores UI locale");
35 Check(!WeatherOverrides::ParseValue(L"2,5", 2, 16, value), "comma is not silently truncated");
36 std::setlocale(LC_NUMERIC, "C");
37
38 float weatherBase = 1.8f, baseOverride = -1.f, smoothBase = 1.2f;
39 WeatherOverrides::Apply(.125f, weatherBase, baseOverride, smoothBase);
40 Check(smoothBase == .125f && weatherBase == 1.8f, "base snaps without overwriting weather");
41 weatherBase = 2.4f;
42 Check(WeatherOverrides::Target(baseOverride, weatherBase) == .125f, "weather packet keeps base override");
43 WeatherOverrides::Apply(-1.f, weatherBase, baseOverride, smoothBase);
44 Check(smoothBase == 2.4f, "base reset uses latest weather independently");
45 for (const auto* text : {L"0.010", L"0.150", L"0.500", L"1.5", L"42.16", L"168.64", L"-1"})
46 Check(WeatherOverrides::ParseValue(text, .010f, 168.64f, value), "visibility command accepts supported ranges and reset");
47 for (const auto* text : {L"0", L"0.009", L"-0.1", L"168.641", L"nan", L"inf", L"0.5junk", L"0,5"})
48 {
49 value = 42.16f;
50 Check(!WeatherOverrides::ParseValue(text, .010f, 168.64f, value) && value == 42.16f,
51 "invalid visibility cannot set zero fog distance or silently change the range");
52 }
53 const auto near = [](float a, float b) { return std::fabs(a-b) < .0001f; };
54 const float fog = .5f;
55 Check(near(CloudVolume::AtmosphericVisibility(fog, .3f, .3f, 10.f), .5f), "500 metre fog at Deois ground level");
56 Check(CloudVolume::AtmosphericVisibility(fog, 5.f, .3f, 10.f) > fog, "atmospheric visibility recovers aloft");
58 "surface fog does not obscure orbit");
59
60 // Received weather must produce the same low cloud geometry as BCL,
61 // including the zero-ceiling cases used in the visibility benchmarks.
62 for (float surface : {-.15f, 0.f, .048f, .3f, 2.f})
63 for (float ceiling : {0.f, .025f, .15f})
64 for (bool resetLocal : {false, true})
65 {
67 CloudVolume::Point wind{};
68 CloudVolume::UpdateLocalWeather(automatic, wind, true, surface+ceiling, .6f, {}, 1, resetLocal);
69 auto manual = automatic;
70 manual.base = surface+ceiling;
71 const CloudVolume::Point ground{17.f, automatic.radius+surface, -23.f};
72 Check(near(CloudVolume::Boundaries(ground, automatic).base,
73 CloudVolume::Boundaries(ground, manual).base),
74 "automatic low cloud base must match the manual BCL override over local terrain");
75 for (float height : {.025f, .075f, .15f, .4f})
76 {
77 const auto point = CloudVolume::Add(ground, {0, height, 0});
78 Check(near(CloudVolume::SampleMedium(point, automatic).density,
79 CloudVolume::SampleMedium(point, manual).density),
80 "automatic ground-cloud density must match the benchmarked manual base");
81 }
82 }
83
84 CloudVolume::Parameters destination;
85 destination.base = 6.960f;
86 destination.activity = .95f;
87 destination.noiseOffset = {17.f, 23.f, 31.f};
88 CloudVolume::Point deckWind{.020f, 0, 0};
89 CloudVolume::UpdateLocalWeather(destination, deckWind, true, 3.079f, .08f, {}, 0, true);
90 Check(near(destination.base, 3.079f) && near(destination.activity, .08f),
91 "reposition applies destination cloud base and activity immediately even on a zero-time frame");
92 Check(deckWind.x == 0 && destination.noiseOffset.x == 17.f,
93 "reposition replaces old local wind while preserving the planet-fixed cloud formation");
94 const CloudVolume::Point stationary{0, destination.radius + 2.071f, 0};
95 const float repositionBcl = CloudVolume::Boundaries(stationary, destination).base - 2.071f;
96 for (int frame = 0; frame < 6000; ++frame)
97 CloudVolume::UpdateLocalWeather(destination, deckWind, true, 3.079f, .08f, {}, 1. / 60.);
98 Check(near(CloudVolume::Boundaries(stationary, destination).base - 2.071f, repositionBcl),
99 "stationary BCL has no retained local-weather transition after reset");
100 CloudVolume::UpdateLocalWeather(destination, deckWind, true, 3.079f, .9f, {}, 1);
101 Check(destination.activity > .08f && destination.activity < .1f,
102 "ordinary weather changes still blend after reposition");
103 const auto retained = destination;
104 CloudVolume::UpdateLocalWeather(destination, deckWind, false, .45f, 0, {}, 10, true);
105 Check(destination.base == retained.base && destination.activity == retained.activity,
106 "above-deck aircraft weather cannot replace the retained cloud deck during reset");
107 std::cout << "PASS: weather command parsing, overrides, reposition cloud resets and atmospheric visibility\n";
108}
Point Add(Point a, Point b)
Definition CloudVolume.h:95
void UpdateLocalWeather(Parameters &params, Point &deckWind, bool belowDeck, float base, float activity, Point observedWind, double elapsed, bool reset=false)
constexpr float ClearVisibilityKm
Column Boundaries(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
Medium SampleMedium(Point p, const Parameters &params, uint32_t seed=DefaultSeed)
float AtmosphericVisibility(float surfaceVisibility, float altitude, float surfaceAltitude, float clearAltitude)
bool ParseValue(const wchar_t *text, float minimum, float maximum, float &value)
float Target(float overrideValue, float weatherTarget)
void Apply(float value, float weatherTarget, float &overrideValue, float &smoothValue)