The Quantum Exact Simulation Toolkit v4.1.0
Loading...
Searching...
No Matches
types.cpp
1/** @file
2 * Unit tests of the types module.
3 *
4 * @author Tyson Jones
5 *
6 * @defgroup unittypes Types
7 * @ingroup unittests
8 */
9
10#include "quest.h"
11
12#include <catch2/catch_test_macros.hpp>
13#include <catch2/matchers/catch_matchers_string.hpp>
14
15#include "tests/utils/qvector.hpp"
16#include "tests/utils/qmatrix.hpp"
17#include "tests/utils/compare.hpp"
18#include "tests/utils/convert.hpp"
19#include "tests/utils/evolve.hpp"
20#include "tests/utils/linalg.hpp"
21#include "tests/utils/lists.hpp"
22#include "tests/utils/macros.hpp"
23#include "tests/utils/random.hpp"
24
25using Catch::Matchers::ContainsSubstring;
26
27
28
29/*
30 * UTILITIES
31 */
32
33#define TEST_CATEGORY \
34 LABEL_UNIT_TAG "[types]"
35
36
37
38/**
39 * TESTS
40 *
41 * @ingroup unittypes
42 * @{
43 */
44
45
46TEST_CASE( "getQcomp", TEST_CATEGORY ) {
47
48 SECTION( LABEL_CORRECTNESS ) {
49
50 qreal re = getRandomReal(-10, 10);
51 qreal im = getRandomReal(-10, 10);
52
53 qcomp comp = getQcomp(re, im);
54 REQUIRE( std::real(comp) == re );
55 REQUIRE( std::imag(comp) == im );
56 }
57
58 SECTION( LABEL_VALIDATION ) {
59
60 // no validation!
61 SUCCEED( );
62 }
63}
64
65
66TEST_CASE( "complex arithmetic", TEST_CATEGORY ) {
67
68 SECTION( LABEL_CORRECTNESS ) {
69
70 qcomp x;
71 x = 1 + 2_i;
72 x += 3 - 4_i;
73 x -= - 5 + 6_i;
74 x *= - 7 - 8_i;
75 x /= 9 + 10_i;
76
77 qcomp ref = getQcomp(-1303/181., 1126/181.);
78 REQUIRE_AGREE( x, ref );
79 }
80
81 SECTION( LABEL_VALIDATION ) {
82
83 // no validation!
84 SUCCEED( );
85 }
86}
87
88
89/** @} (end defgroup) */
90
91
92
93/**
94 * @todo
95 * UNTESTED FUNCTIONS
96 */
97
98void reportStr(const char* label);
99void reportStr(std::string str);
100
101void reportScalar(const char* label, qcomp num);
102void reportScalar(const char* label, qreal num);
103void reportScalar(std::string label, qcomp num);
104void reportScalar(std::string label, qreal num);
qreal getRandomReal(qreal min, qreal maxExcl)
Definition random.cpp:63
void reportStr(const char *label)
Definition types.cpp:29
static qcomp getQcomp(qreal re, qreal im)
Definition types.h:91
void reportScalar(const char *label, qcomp num)
Definition types.cpp:51
TEST_CASE("getQcomp", TEST_CATEGORY)
Definition types.cpp:46