netxsimdg
Loading...
Searching...
No Matches
Iterator_test.cpp
Go to the documentation of this file.
1
7#include "Iterator.hpp"
8
9#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
10#include <doctest/doctest.h>
11
12namespace Nextsim {
13
14// An iterant that counts the number of times it is started, iterated
15// and stopped
17public:
18 void init()
19 {
20 count = 0;
21 startCount = 0;
22 stopCount = 0;
23 };
24 void start(const TimePoint& startTime) { startCount++; };
25 void iterate(const TimestepTime& tst) { count++; };
26 void stop(const TimePoint& stopTime) { stopCount++; };
27
28 int getCount() { return count; };
29
30 int count;
31 int startCount;
32 int stopCount;
33};
34
35template<typename T>
36T zeroTime();
37
38template<>
39std::chrono::time_point<Iterator::Clock> zeroTime<std::chrono::time_point<Iterator::Clock>>()
40{
41 return Iterator::Clock::now();
42}
43template<>
44size_t zeroTime<size_t>()
45{
46 return 0;
47}
48
49TEST_SUITE_BEGIN("Iterator");
50TEST_CASE("Count iterator testing")
51{
52 Counterant cant = Counterant();
53 Iterator iterator = Iterator(&cant);
54
55 int nSteps = 5;
56
57 TimePoint start;
58 Duration dt("P0-0T0:0:1");
59 Duration overall(dt);
60 overall *= nSteps;
61 TimePoint stop = start + overall;
62 iterator.setStartStopStep(start, start + overall, dt);
63 iterator.run();
64
65 REQUIRE(dt.seconds() == 1);
66 REQUIRE(overall.seconds() == nSteps * 1);
67 REQUIRE(stop > start);
68 REQUIRE((stop - start).seconds() == nSteps * 1);
69 REQUIRE(cant.count == nSteps);
70 REQUIRE(cant.startCount == 1);
71 REQUIRE(cant.stopCount == 1);
72}
73TEST_SUITE_END();
74
75} /* namespace Nextsim */
void init()
Initializes the model, based on some environment stored in the implementing class.
void start(const TimePoint &startTime)
void stop(const TimePoint &stopTime)
void iterate(const TimestepTime &tst)
A base class for classes that specify what happens during one timestep.
Definition Iterator.hpp:76