|
| 1 | +#include "grid.hpp" |
| 2 | + |
| 3 | +#include "debug.hpp" |
| 4 | +#include "util.hpp" |
| 5 | + |
| 6 | +#include "CachedExponentials.hpp" |
| 7 | +#include "Exponentials.hpp" |
| 8 | + |
| 9 | +#include <gtest/gtest.h> |
| 10 | + |
| 11 | +namespace ahr::exp { |
| 12 | + |
| 13 | +template <typename Exp, typename ExpT> class TestExps : public ::testing::Test { |
| 14 | +protected: |
| 15 | + Grid grid{5, 32, 64}; |
| 16 | + Exp exp{grid}; |
| 17 | + ExpT exp_t{grid}; |
| 18 | + |
| 19 | + void check() |
| 20 | + requires exp::space_like<Exp> |
| 21 | + { |
| 22 | + grid.for_each_kxky([&](Dim kx, Dim ky) { |
| 23 | + EXPECT_THAT(exp(kx, ky), AllClose(exp_t(kx, ky), 1e-16, 1e-15)); // prevent oneline |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + void check() |
| 28 | + requires exp::moment_like<Exp> |
| 29 | + { |
| 30 | + for (int m = 0; m < grid.M; ++m) { |
| 31 | + EXPECT_THAT(exp(m), AllClose(exp_t(m), 1e-16, 1e-15)); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + void test() { |
| 36 | + Real dt = 1.0; |
| 37 | + HyperCoefficients hyper = HyperCoefficients::calculate(dt, grid); |
| 38 | + |
| 39 | + exp.update(hyper, dt); |
| 40 | + exp_t.update(hyper, dt); |
| 41 | + |
| 42 | + this->check(); |
| 43 | + this->check(); // Run again |
| 44 | + |
| 45 | + dt *= 1.2; |
| 46 | + hyper = HyperCoefficients::calculate(dt, grid); |
| 47 | + exp.update(hyper, dt); |
| 48 | + exp_t.update(hyper, dt); |
| 49 | + |
| 50 | + this->check(); |
| 51 | + |
| 52 | + // Update with the same dt |
| 53 | + exp.update(hyper, dt); |
| 54 | + exp_t.update(hyper, dt); |
| 55 | + this->check(); |
| 56 | + |
| 57 | + // Old dt again |
| 58 | + exp.update(hyper, 1.0); |
| 59 | + exp_t.update(hyper, 1.0); |
| 60 | + this->check(); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +/// This struct contains a type definition for the appropriate Cached* class for exp. |
| 65 | +/// It's specialized for space-like/moment-like so they can all use the same test suite. |
| 66 | +template <typename Exp> struct cached; |
| 67 | + |
| 68 | +template <space_like Exp> struct cached<Exp> { |
| 69 | + using type = CachedKXKY<Exp>; |
| 70 | +}; |
| 71 | + |
| 72 | +template <moment_like Exp> struct cached<Exp> { |
| 73 | + using type = CachedM<Exp>; |
| 74 | +}; |
| 75 | + |
| 76 | +template <typename Exp> using TestCachedExps = TestExps<Exp, typename cached<Exp>::type>; |
| 77 | + |
| 78 | +using Types = ::testing::Types<Eta, Nu, NuG, GM>; |
| 79 | +TYPED_TEST_SUITE(TestCachedExps, Types); |
| 80 | + |
| 81 | +TYPED_TEST(TestCachedExps, Exps) { this->test(); } |
| 82 | + |
| 83 | +} // namespace ahr::exp |
0 commit comments