preCICE v3.1.2
Loading...
Searching...
No Matches
TXTWriterReaderTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include "io/TXTReader.hpp"
3#include "io/TXTWriter.hpp"
4#include "logging/Logger.hpp"
6#include "testing/Testing.hpp"
7
9
10using namespace precice;
11using namespace precice::io;
12
13BOOST_AUTO_TEST_CASE(TXTWriterReaderTest)
14{
15 PRECICE_TEST(1_rank);
16 {
17 Eigen::Matrix<double, 1, 2> output(1, 2);
18 {
19 TXTWriter txtWriter("io-TXTWriterReaderTest-matrix-1by2.log");
20 txtWriter.write(output);
21 }
22 Eigen::Matrix<double, 1, 2> input(1, 2);
23 TXTReader txtReader("io-TXTWriterReaderTest-matrix-1by2.log");
24 txtReader.read(input);
25 BOOST_TEST(testing::equals(output, input));
26 }
27
28 {
29 Eigen::Matrix<double, 2, 1> output(1, 2);
30 {
31 TXTWriter txtWriter("io-TXTWriterReaderTest-matrix-2by1.log");
32 txtWriter.write(output);
33 }
34 Eigen::Matrix<double, 2, 1> input(1, 2);
35 TXTReader txtReader("io-TXTWriterReaderTest-matrix-2by1.log");
36 txtReader.read(input);
37 BOOST_TEST(testing::equals(output, input));
38 }
39
40 {
41 Eigen::Matrix<double, 3, 3> matOutput;
42 matOutput << 1, 2, 3, 4, 5, 6, 7, 8, 9;
43 Eigen::VectorXd vecOutput = Eigen::VectorXd::Constant(1, 1);
44
45 {
46 TXTWriter txtWriter("io-TXTWriterReaderTest-matrix-3by3.log");
47 txtWriter.write(matOutput);
48 txtWriter.write(vecOutput);
49 }
50
51 Eigen::Matrix<double, 3, 3> matInput;
52 TXTReader txtReader("io-TXTWriterReaderTest-matrix-3by3.log");
53 txtReader.read(matInput);
54 BOOST_TEST(testing::equals(matOutput, matInput));
55
56 Eigen::VectorXd vecInput(1);
57 txtReader.read(vecInput);
58 BOOST_TEST(testing::equals(vecOutput, vecInput));
59 }
60
61 {
62 Eigen::Vector3d output(1, 2, 3);
63 {
64 TXTWriter txtWriter("io-TXTWriterReaderTest-vector-3.log");
65 txtWriter.write(output);
66 }
67
68 Eigen::Vector3d input;
69 TXTReader txtReader("io-TXTWriterReaderTest-vector-3.log");
70 txtReader.read(input);
71 BOOST_TEST(testing::equals(output, input));
72 }
73}
74
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TXTWriterReaderTest)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
File reader for matrix/vector in Matlab V7 ASCII format.
Definition TXTReader.hpp:16
void read(Eigen::Matrix< Scalar, Rows, Cols > &matrix)
Reads the Eigen::Matrix from the file.
Definition TXTReader.hpp:23
File writer for matrix in Matlab V7 ASCII format.
Definition TXTWriter.hpp:14
void write(const Eigen::MatrixXd &matrix)
Writes (appends) the matrix to the file.
Definition TXTWriter.cpp:24
provides Import and Export of the coupling mesh and data.
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
Main namespace of the precice library.