Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
wavepacketkinematics_tests.cpp
Go to the documentation of this file.
1/**
2 * @file wavepacketkinematics_tests.cpp
3 * @brief Implements regression and invariant tests for wavepacketkinematics tests.
4 * @ingroup qpe_tests
5 *
6 * Source: @c tests/wavepacketkinematics_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
18namespace qpe {
19namespace tests {
20namespace {
21
22/**
23 * @brief Performs nearly equal.
24 * @param a The a value used by the operation.
25 * @param b The b value used by the operation.
26 * @param tolerance The tolerance value used by the operation.
27 */
28bool nearlyEqual(double a, double b, double tolerance)
29{
30 return std::abs(a - b) <= tolerance;
31}
32
33/**
34 * @brief Performs fail.
35 * @param errorMessage The error message value used by the operation.
36 * @param message The message value used by the operation.
37 */
38bool fail(std::string &errorMessage, const char *message)
39{
40 errorMessage = message;
41 return false;
42}
43
44} // namespace
45
46/**
47 * @brief Runs wave packet kinematics tests.
48 * @param errorMessage The error message value used by the operation.
49 */
50bool runWavePacketKinematicsTests(std::string &errorMessage)
51{
52 errorMessage.clear();
53
54 if (!nearlyEqual(WavePacketKinematics::kineticEnergy(3.0, 4.0, 2.0),
55 6.25, 1.0e-12)) {
56 return fail(errorMessage, "2D kinetic energy is incorrect");
57 }
58
59 if (!nearlyEqual(WavePacketKinematics::kineticEnergyX(3.0, 2.0),
60 2.25, 1.0e-12)) {
61 return fail(errorMessage, "longitudinal X kinetic energy is incorrect");
62 }
63
64 if (WavePacketKinematics::kineticEnergy(1.0, 2.0, 0.0) != 0.0 ||
65 WavePacketKinematics::kineticEnergyX(1.0, -1.0) != 0.0) {
66 return fail(errorMessage, "invalid mass was not handled safely");
67 }
68
69 return true;
70}
71
72} // namespace tests
73} // namespace qpe
static double kineticEnergy(double momentumX, double momentumY, double mass) noexcept
Performs kinetic energy.
static double kineticEnergyX(double momentumX, double mass) noexcept
Performs kinetic energy x.
bool runWavePacketKinematicsTests(std::string &errorMessage)
Runs wave packet kinematics tests.
Declares the wavepacketkinematics physics/numerical component used by QPE experiments.
Declares regression and invariant tests for wavepacketkinematics tests.