1 #include "average.hpp"
2
3 #include <gmock/gmock.h>
4 #include <gtest/gtest.h>
5
6 using ::testing::Return;
7
TEST(SensorKeyTest,InvalidSensorKey)8 TEST(SensorKeyTest, InvalidSensorKey)
9 {
10 Average av;
11
12 av.setAverageValue(std::make_pair("power", "0"), std::make_pair(0L, 0L));
13 av.setAverageValue(std::make_pair("power", "1"), std::make_pair(0L, 0L));
14
15 EXPECT_FALSE(av.getAverageValue(std::make_pair("power", "4")));
16 }
17
TEST(SensorKeyTest,ValidSensorKey)18 TEST(SensorKeyTest, ValidSensorKey)
19 {
20 Average av;
21
22 av.setAverageValue(std::make_pair("power", "0"), std::make_pair(0L, 0L));
23 av.setAverageValue(std::make_pair("power", "1"), std::make_pair(2L, 2L));
24
25 auto value = av.getAverageValue(std::make_pair("power", "1"));
26 auto expected = Average::averageValue(2, 2);
27 EXPECT_TRUE(value == expected);
28 }
29
TEST(AverageTest,ZeroDelta)30 TEST(AverageTest, ZeroDelta)
31 {
32 Average av;
33
34 EXPECT_FALSE(av.calcAverage(1L, 1L, 2L, 1L));
35 }
36
TEST(AverageTest,NegativeDelta)37 TEST(AverageTest, NegativeDelta)
38 {
39 Average av;
40
41 ASSERT_DEATH(av.calcAverage(1L, 1L, 2L, 0L), "");
42 }
43
TEST(AverageTest,RightAverage)44 TEST(AverageTest, RightAverage)
45 {
46 Average av;
47
48 EXPECT_TRUE(38837438L == av.calcAverage(27624108L, 132864155500L, 27626120L,
49 132887999500L));
50 }
51