preCICE v3.2.0
Loading...
Searching...
No Matches
QuickTest.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <string>
5#include <vector>
7#include "testing/Testing.hpp"
8
9namespace precice::testing {
10
11struct QuickTest {
12
13 struct Mesh {
15 };
16
17 struct ReadData {
19 };
20
21 struct WriteData {
23 };
24
26 : interface(p), meshName(m.name), readDataName(r.name)
27 {
28 }
29
31 : interface(p), meshName(m.name), writeDataName(w.name)
32 {
33 }
34
36 : interface(p), meshName(m.name), readDataName(r.name), writeDataName(w.name)
37 {
38 }
39
41 {
42 auto n = pos.size() / interface.getMeshDimensions(meshName);
43 vertexIDs.resize(n, -1);
44 interface.setMeshVertices(meshName, pos, vertexIDs);
45 return *this;
46 }
47
49 {
50 interface.initialize();
51 return *this;
52 }
53
55 {
56 BOOST_TEST_MESSAGE("Remeshing");
57 interface.resetMesh(meshName);
58 return *this;
59 }
60
62 {
63 interface.requiresReadingCheckpoint();
64 return *this;
65 }
66
68 {
69 interface.requiresWritingCheckpoint();
70 return *this;
71 }
72
73 void finalize()
74 {
75 interface.finalize();
76 }
77
79 {
80 interface.advance(interface.getMaxTimeStepSize());
81 return *this;
82 }
83
84 QuickTest &advance(double dt)
85 {
86 interface.advance(dt);
87 return *this;
88 }
89
91 {
92 interface.writeData(meshName, writeDataName, vertexIDs, data);
93 return *this;
94 }
95
97 {
98 std::vector<double> data(vertexIDs.size() * interface.getDataDimensions(meshName, writeDataName), d);
99 interface.writeData(meshName, writeDataName, vertexIDs, data);
100 return *this;
101 }
102
104 {
105 auto n = vertexIDs.size() * interface.getDataDimensions(meshName, readDataName);
106 std::vector<double> result(n, -0.0);
107 interface.readData(meshName, readDataName, vertexIDs, interface.getMaxTimeStepSize(), result);
108 return result;
109 }
110
112 {
113 auto data = read();
114 BOOST_TEST(data == expected, boost::test_tools::per_element());
115 return *this;
116 }
117
119 {
120 auto data = read();
121 std::vector<double> expected(vertexIDs.size() * interface.getDataDimensions(meshName, readDataName), e);
122 BOOST_TEST(data == expected, boost::test_tools::per_element());
123 return *this;
124 }
125
127 {
128 BOOST_TEST(interface.requiresReadingCheckpoint());
129 BOOST_TEST(!interface.requiresWritingCheckpoint());
130 return *this;
131 }
132
134 {
135 BOOST_TEST(!interface.requiresReadingCheckpoint());
136 BOOST_TEST(interface.requiresWritingCheckpoint());
137 return *this;
138 }
139
141 {
142 BOOST_TEST(!interface.isCouplingOngoing());
143 return *this;
144 }
145
151};
152
153inline QuickTest::Mesh operator""_mesh(const char *name, std::size_t)
154{
155 return {name};
156}
157
158inline QuickTest::ReadData operator""_read(const char *name, std::size_t)
159{
160 return {name};
161}
162
163inline QuickTest::WriteData operator""_write(const char *name, std::size_t)
164{
165 return {name};
166}
167
168} // namespace precice::testing
Main Application Programming Interface of preCICE. Include using #include <precice/precice....
contains the testing framework.
Definition helper.hpp:9
T size(T... args)
QuickTest & expect(const std::vector< double > &expected)
QuickTest & writeCheckpoint()
Definition QuickTest.hpp:67
std::vector< VertexID > vertexIDs
QuickTest & advance(double dt)
Definition QuickTest.hpp:84
QuickTest & writeAll(double d)
Definition QuickTest.hpp:96
std::vector< double > read()
QuickTest(Participant &p, Mesh m, WriteData w)
Definition QuickTest.hpp:30
QuickTest & setVertices(const std::vector< double > &pos)
Definition QuickTest.hpp:40
QuickTest & expectAll(double e)
QuickTest(Participant &p, Mesh m, ReadData r, WriteData w)
Definition QuickTest.hpp:35
QuickTest(Participant &p, Mesh m, ReadData r)
Definition QuickTest.hpp:25
QuickTest & expectWriteCheckpoint()
QuickTest & expectReadCheckpoint()
QuickTest & write(const std::vector< double > &data)
Definition QuickTest.hpp:90
QuickTest & expectCouplingCompleted()