File: TestMovDev.cpp

package info (click to toggle)
signal-estimator 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,268 kB
  • sloc: cpp: 4,752; python: 846; sh: 147; makefile: 58
file content (57 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Signal Estimator authors
// Licensed under MIT

#include "processing/MovDev.hpp"

#include <gtest/gtest.h>

using namespace signal_estimator;

namespace {

// Trying to get the average and maximum deviation with an empty window
TEST(MovDevTest, EmptyWindow) {
    MovDev<double> movdev(5);

    EXPECT_DOUBLE_EQ(movdev.avg(), 0);
    EXPECT_DOUBLE_EQ(movdev.max(), 0);
}

// The test verifies that the MovDev class correctly calculates the mean and maximum
// deviation from the mean.
TEST(MovDevTest, AvgAndMax) {
    MovDev<int> movdev(3);

    movdev.add(4);
    movdev.add(6);
    movdev.add(7);

    EXPECT_EQ(movdev.avg(), 1);
    EXPECT_EQ(movdev.max(), 2);
}

// The test verifies that the MovDev object correctly calculates the mean and maximum
// absolute deviation in the case where the window is equal to the buffer size.
TEST(MovDevTest, FullWindow) {
    const size_t window_sz = 3;
    MovDev<double> movdev(window_sz);

    movdev.add(1);
    movdev.add(2);
    movdev.add(3);

    EXPECT_DOUBLE_EQ(movdev.avg(), 0.66666666666666663);
    EXPECT_DOUBLE_EQ(movdev.max(), 1);
}

// The test checks that the MovDev object correctly handles the case where no values have
// been added to it and returns the expected values of 0
TEST(MovDevTest, GetAvgAndMaxWhenEmpty) {
    const size_t window_sz = 3;
    MovDev<double> movdev(window_sz);

    EXPECT_DOUBLE_EQ(movdev.avg(), 0);
    EXPECT_DOUBLE_EQ(movdev.max(), 0);
}

} // namespace