blob: 9eef0f811e188427678061ffe9d7ab58d045b946 [file] [log] [blame]
Carol Wang9bbe6022019-08-01 17:31:30 +08001#include "average.hpp"
2
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
6using ::testing::Return;
7
8TEST(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
18TEST(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 EXPECT_TRUE(value == std::make_pair(2L, 2L));
27}
28
29TEST(AverageTest, ZeroDelta)
30{
31 Average av;
32
33 EXPECT_FALSE(av.calcAverage(1L, 1L, 2L, 1L));
34}
35
36TEST(AverageTest, NegativeDelta)
37{
38 Average av;
39
40 ASSERT_DEATH(av.calcAverage(1L, 1L, 2L, 0L), "");
41}
42
43TEST(AverageTest, RightAverage)
44{
45 Average av;
46
47 EXPECT_TRUE(38837438L == av.calcAverage(27624108L, 132864155500L, 27626120L,
48 132887999500L));
49}