Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
observablestimeseries2d_tests.cpp
Go to the documentation of this file.
1/**
2 * @file observablestimeseries2d_tests.cpp
3 * @brief Implements regression and invariant tests for observablestimeseries2d tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/observablestimeseries2d_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 <exception>
18
19namespace qpe {
20namespace tests {
21
22/**
23 * @brief Runs observables time series2 d tests.
24 * @param error Output diagnostic text on failure.
25 */
26bool runObservablesTimeSeries2DTests(std::string &error)
27{
28 try {
29 ObservablesTimeSeries2D history(3u);
30 for (int i = 0; i < 5; ++i) {
32 sample.time = static_cast<double>(i) * 0.5;
33 sample.meanX = static_cast<double>(i);
34 history.append(sample);
35 }
36
37 if (history.size() != 3u) {
38 error = "bounded history did not trim to maximum size";
39 return false;
40 }
41 if (std::fabs(history.samples().front().time - 1.0) > 1.0e-12 ||
42 std::fabs(history.samples().back().time - 2.0) > 1.0e-12) {
43 error = "bounded history kept the wrong sample range";
44 return false;
45 }
46
47 history.setMaximumSamples(2u);
48 if (history.size() != 2u ||
49 std::fabs(history.samples().front().meanX - 3.0) > 1.0e-12) {
50 error = "setMaximumSamples did not preserve newest samples";
51 return false;
52 }
53
54 history.clear();
55 if (!history.empty()) {
56 error = "clear did not empty the history";
57 return false;
58 }
59
60 return true;
61 } catch (const std::exception &e) {
62 error = e.what();
63 return false;
64 }
65}
66
67} // namespace tests
68} // namespace qpe
Implements the Observables Time Series2D component.
void setMaximumSamples(std::size_t maximumSamples)
Sets maximum samples.
void clear() noexcept
Clears stored state and returns the component to its empty/default state.
std::size_t size() const noexcept
Returns size.
bool empty() const noexcept
Returns whether the object contains no data.
const std::vector< ObservablesTimeSeries2DSample > & samples() const noexcept
Samples s.
void append(const ObservablesTimeSeries2DSample &sample)
Carries out append.
bool runObservablesTimeSeries2DTests(std::string &error)
Runs observables time series2 d tests.
Declares the observablestimeseries2d physics/numerical component used by QPE experiments.
Declares regression and invariant tests for observablestimeseries2d tests.
Data record containing Observables Time Series2D Sample.