Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
simulationtransport_tests.cpp
Go to the documentation of this file.
1/**
2 * @file simulationtransport_tests.cpp
3 * @brief Implements regression and invariant tests for simulationtransport tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/simulationtransport_tests.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
15
16#include <cmath>
17#include <sstream>
18
19namespace qpe {
20namespace tests {
21
22namespace {
23
24/**
25 * @brief Performs fail.
26 * @param error Output diagnostic text on failure.
27 * @param message The message value used by the operation.
28 */
29bool fail(std::string &error, const char *message)
30{
31 error = message;
32 return false;
33}
34
35} // namespace
36
37/**
38 * @brief Runs simulation transport tests.
39 * @param error Output diagnostic text on failure.
40 */
41bool runSimulationTransportTests(std::string &error)
42{
43 error.clear();
44
45 SimulationTransport transport;
46 if (transport.state() != SimulationTransportState::Stopped) {
47 return fail(error, "initial state is not STOPPED");
48 }
49
50 transport.play();
51 if (transport.state() != SimulationTransportState::Running) {
52 return fail(error, "play() did not enter RUNNING");
53 }
54
55 transport.pause();
56 if (transport.state() != SimulationTransportState::Paused) {
57 return fail(error, "pause() did not enter PAUSED");
58 }
59
60 transport.stop();
61 if (transport.state() != SimulationTransportState::Stopped) {
62 return fail(error, "stop() did not enter STOPPED");
63 }
64
65 transport.setSpeedFactor(0.25);
66 if (transport.timerIntervalMs(30) != 120 || transport.stepsPerTick() != 1) {
67 return fail(error, "0.25x timing is incorrect");
68 }
69
70 transport.setSpeedFactor(0.5);
71 if (transport.timerIntervalMs(30) != 60 || transport.stepsPerTick() != 1) {
72 return fail(error, "0.5x timing is incorrect");
73 }
74
75 transport.setSpeedFactor(1.0);
76 if (transport.timerIntervalMs(30) != 30 || transport.stepsPerTick() != 1) {
77 return fail(error, "1x timing is incorrect");
78 }
79
80 transport.setSpeedFactor(2.0);
81 if (transport.timerIntervalMs(30) != 30 || transport.stepsPerTick() != 2) {
82 return fail(error, "2x timing is incorrect");
83 }
84
85 transport.setSpeedFactor(4.0);
86 if (transport.timerIntervalMs(30) != 30 || transport.stepsPerTick() != 4) {
87 return fail(error, "4x timing is incorrect");
88 }
89
90 transport.setSpeedFactor(-10.0);
91 if (!(transport.speedFactor() >= 0.05)) {
92 return fail(error, "speed lower clamp failed");
93 }
94
95 transport.setSpeedFactor(100.0);
96 if (!(transport.speedFactor() <= 16.0)) {
97 return fail(error, "speed upper clamp failed");
98 }
99
100 return true;
101}
102
103} // namespace tests
104} // namespace qpe
Implements the Simulation Transport component.
int timerIntervalMs(int baseIntervalMs) const noexcept
Returns timer interval ms.
int stepsPerTick() const noexcept
Advances the simulation state by one s per tick.
void pause() noexcept
Carries out pause.
void setSpeedFactor(double factor) noexcept
Sets speed factor.
void play() noexcept
Carries out play.
SimulationTransportState state() const noexcept
Carries out state.
double speedFactor() const noexcept
Carries out speed factor.
void stop() noexcept
Carries out stop.
bool runSimulationTransportTests(std::string &error)
Runs simulation transport tests.
Declares the simulationtransport physics/numerical component used by QPE experiments.
Declares regression and invariant tests for simulationtransport tests.