JayBeams  0.1
Another project to have fun coding.
ut_delay_timeseries.cpp
Go to the documentation of this file.
3 
4 #include <boost/test/unit_test.hpp>
5 #include <chrono>
6 
7 namespace std {
8 
9 // Horrible hack to make Boost.Test happy
10 std::ostream&
11 operator<<(std::ostream& os, std::pair<std::ptrdiff_t, float> const& x) {
12  return os << "{" << x.first << "," << x.second << "}";
13 }
14 
15 } // namespace std
16 
17 /**
18  * @test Test jb::testing::delay_timeseries_periodic with default types
19  *
20  * Usually I do not spend time testing helper functions for tests, but
21  * in this case the helper has a lot of template code and we want to
22  * validate this before too long.
23  */
24 BOOST_AUTO_TEST_CASE(delay_timeseries_periodic_default) {
25  int delay = 23;
26  std::vector<float> ts;
29  ts, std::chrono::microseconds(delay), std::chrono::microseconds(1));
30 
31  for (std::size_t i = 0; i != std::size_t(delay); ++i) {
32  float expected = ts.at(ts.size() + i - delay);
33  BOOST_CHECK_CLOSE(expected, delayed.at(i), 1.0 / 1024);
34  }
35  for (std::size_t i = delay; i != delayed.size(); ++i) {
36  float expected = ts.at(i - delay);
37  BOOST_CHECK_CLOSE(expected, delayed.at(i), 1.0 / 1024);
38  }
39 }
40 
41 /**
42  * @test Improve coverage for jb::testing::extrapolate_periodic.
43  */
44 BOOST_AUTO_TEST_CASE(extrapolate_periodic) {
46  BOOST_CHECK_EQUAL(tested(0, 0), std::make_pair(std::ptrdiff_t(0), float(0)));
47  BOOST_CHECK_EQUAL(
48  tested(1, 100), std::make_pair(std::ptrdiff_t(1), float(0)));
49  BOOST_CHECK_EQUAL(
50  tested(120, 100), std::make_pair(std::ptrdiff_t(20), float(0)));
51  BOOST_CHECK_EQUAL(
52  tested(-20, 100), std::make_pair(std::ptrdiff_t(80), float(0)));
53 }
54 
55 /**
56  * @test Test jb::testing::delay_timeseries_zeroes with default types
57  *
58  * Usually I do not spend time testing helper functions for tests, but
59  * in this case the helper has a lot of template code and we want to
60  * validate this before too long.
61  */
62 BOOST_AUTO_TEST_CASE(delay_timeseries_zeroes_default) {
63  int delay = 23;
64  std::vector<float> ts;
67  ts, std::chrono::microseconds(delay), std::chrono::microseconds(1));
68 
69  for (std::size_t i = 0; i != std::size_t(delay); ++i) {
70  BOOST_CHECK_SMALL(delayed.at(i), 1.0f / 1024);
71  }
72  for (std::size_t i = delay; i != delayed.size() - delay; ++i) {
73  float expected = ts.at(i - delay);
74  BOOST_CHECK_CLOSE(expected, delayed.at(i), 1.0 / 1024);
75  }
76 }
timeseries_t delay_timeseries_periodic(timeseries_t const &ts, duration_t delay, duration_t sampling_period)
Delay a timeseries using a periodic extension for early values.
STL namespace.
A functor to extrapolate a periodic timseries.
void create_triangle_timeseries(int nsamples, timeseries &ts)
Create a simple timeseries where the values look like a triangle.
BOOST_AUTO_TEST_CASE(delay_timeseries_periodic_default)
timeseries_t delay_timeseries_zeroes(timeseries_t const &ts, duration_t delay, duration_t sampling_period)
Delay a timeseries using zeroes for early values.