Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
wavefunctionimagerenderer_tests.cpp
Go to the documentation of this file.
1/**
2 * @file wavefunctionimagerenderer_tests.cpp
3 * @brief Implements regression and invariant tests for wavefunctionimagerenderer tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/wavefunctionimagerenderer_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
16
17#include <QColor>
18
19#include <stdexcept>
20
21namespace qpe {
22namespace tests {
23namespace {
24
25/**
26 * @brief Returns whether black.
27 * @param c The c value used by the operation.
28 */
29bool isBlack(const QColor &c)
30{
31 return c.red() == 0 && c.green() == 0 && c.blue() == 0;
32}
33
34} // namespace
35
36/**
37 * @brief Runs wave function image renderer tests.
38 * @param errorMessage The error message value used by the operation.
39 */
40bool runWaveFunctionImageRendererTests(std::string &errorMessage)
41{
42 try {
43 ComplexField2D field(3, 1, 1.0f, 1.0f);
44
45 // Real view: +1 -> red, 0 -> black, -1 -> blue.
46 field(0, 0) = ComplexField2D::Value(1.0f, 0.0f);
47 field(1, 0) = ComplexField2D::Value(0.0f, 0.0f);
48 field(2, 0) = ComplexField2D::Value(-1.0f, 0.0f);
49
51 QColor c0(image.pixel(0, 0));
52 QColor c1(image.pixel(1, 0));
53 QColor c2(image.pixel(2, 0));
54 if (!(c0.red() == 255 && c0.green() == 0 && c0.blue() == 0)) {
55 errorMessage = "positive real value is not mapped to red";
56 return false;
57 }
58 if (!isBlack(c1)) {
59 errorMessage = "zero real value is not mapped to black";
60 return false;
61 }
62 if (!(c2.red() == 0 && c2.green() == 0 && c2.blue() == 255)) {
63 errorMessage = "negative real value is not mapped to blue";
64 return false;
65 }
66
67 // Imaginary view follows the same signed convention.
68 field(0, 0) = ComplexField2D::Value(0.0f, 1.0f);
69 field(1, 0) = ComplexField2D::Value(0.0f, 0.0f);
70 field(2, 0) = ComplexField2D::Value(0.0f, -1.0f);
72 c0 = QColor(image.pixel(0, 0));
73 c2 = QColor(image.pixel(2, 0));
74 if (!(c0.red() == 255 && c0.blue() == 0 && c2.red() == 0 && c2.blue() == 255)) {
75 errorMessage = "imaginary signed color mapping is incorrect";
76 return false;
77 }
78
79 // Phase must visibly distinguish 0 from +pi/2 and suppress zero amplitude.
80 field(0, 0) = ComplexField2D::Value(1.0f, 0.0f);
81 field(1, 0) = ComplexField2D::Value(0.0f, 1.0f);
82 field(2, 0) = ComplexField2D::Value(0.0f, 0.0f);
84 c0 = QColor(image.pixel(0, 0));
85 c1 = QColor(image.pixel(1, 0));
86 c2 = QColor(image.pixel(2, 0));
87 if (c0.rgb() == c1.rgb()) {
88 errorMessage = "different phases produced the same display color";
89 return false;
90 }
91 if (!isBlack(c2)) {
92 errorMessage = "zero-amplitude phase pixel is not black";
93 return false;
94 }
95
97 invalid.gamma = 0.0f;
98 bool threw = false;
99 try {
101 } catch (const std::invalid_argument &) {
102 threw = true;
103 }
104 if (!threw) {
105 errorMessage = "invalid gamma was not rejected";
106 return false;
107 }
108
109 errorMessage.clear();
110 return true;
111 } catch (const std::exception &e) {
112 errorMessage = e.what();
113 return false;
114 } catch (...) {
115 errorMessage = "unknown exception";
116 return false;
117 }
118}
119
120} // namespace tests
121} // namespace qpe
Owning Cartesian grid of complex scalar samples.
std::complex< float > Value
static QImage render(const ComplexField2D &field, WaveFunctionView view, const WaveFunctionRenderOptions &options={})
Renders the component state.
Declares the complex scalar field container representing two-dimensional wave functions.
bool runWaveFunctionImageRendererTests(std::string &errorMessage)
Runs wave function image renderer tests.
Configuration values for Wave Function Render Options.
Declares the wavefunctionimagerenderer visualization component used by QPE.
Declares regression and invariant tests for wavefunctionimagerenderer tests.