1
+ #include " Exporter.hpp"
2
+ #include " Transformer.hpp"
3
+ #include " debug.hpp"
4
+ #include " util.hpp"
5
+ #include < gtest/gtest.h>
6
+
7
+ namespace ahr {
8
+
9
+ class TestExporter : public ::testing::Test {
10
+ protected:
11
+ Grid grid{5 , 16 , 24 };
12
+ Transformer tf{grid};
13
+ fs::path const tmp_dir{fs::temp_directory_path ()};
14
+ Exporter exporter{grid, tf, tmp_dir};
15
+
16
+ TestExporter () { tf.init (); }
17
+ };
18
+
19
+ TEST_F (TestExporter, RoundTripReal) {
20
+
21
+ auto rBuf = grid.rBufXY ();
22
+ grid.for_each_xy ([&](Dim x, Dim y) { rBuf (x, y) = Real (x + y * grid.X ); });
23
+
24
+ exporter.exportTo (" test.npy" , rBuf);
25
+
26
+ auto const path = tmp_dir / " test.npy" ;
27
+ ASSERT_TRUE (fs::exists (path));
28
+
29
+ // Import buffer and compare
30
+ auto rBuf2 = exporter.importRealBuf (" test.npy" );
31
+ // No math, tolerance is 0
32
+ EXPECT_THAT (rBuf2.to_mdspan (), MdspanElementsAllClose (rBuf.to_mdspan (), 0.0 ));
33
+
34
+ // Import into npy view and compare
35
+ auto rNpy = exporter.importReal (" test.npy" );
36
+ EXPECT_THAT (rNpy.view (), MdspanElementsAllClose (rBuf.to_mdspan (), 0.0 ));
37
+ }
38
+
39
+ TEST_F (TestExporter, RoundTripComplex) {
40
+ auto cBuf = grid.cBufXY ();
41
+ grid.for_each_kxky ([&](Dim kx, Dim ky) {
42
+ cBuf (kx, ky) = Complex (Real (kx + ky * grid.KX ), Real (kx - ky * grid.KX ));
43
+ });
44
+
45
+ // Use absolute path this time
46
+ exporter.exportTo (tmp_dir / " test.npy" , cBuf);
47
+
48
+ auto const path = tmp_dir / " test.npy" ;
49
+ ASSERT_TRUE (fs::exists (path));
50
+
51
+ // Import buffer and compare
52
+ auto rBuf = exporter.importReal (" test.npy" );
53
+ auto rBuf2 = grid.rBufXY ();
54
+ tf.bfft (cBuf, rBuf2);
55
+
56
+ // No math, tolerance is 0
57
+ EXPECT_THAT (rBuf.view (), MdspanElementsAllClose (rBuf2.to_mdspan (), 0.0 ))
58
+ << " rBuf:\n "
59
+ << rBuf.view () << " \n rBuf2:\n "
60
+ << rBuf2.to_mdspan ();
61
+ }
62
+
63
+ } // namespace ahr
0 commit comments