blob: 84e4d3f0293ce791bc9d86d9184d8108426cecd1 [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"));
Brad Bishop57e18b92019-10-07 18:10:49 -040026 auto expected = Average::averageValue(2, 2);
27 EXPECT_TRUE(value == expected);
Carol Wang9bbe6022019-08-01 17:31:30 +080028}
29
30TEST(AverageTest, ZeroDelta)
31{
32 Average av;
33
34 EXPECT_FALSE(av.calcAverage(1L, 1L, 2L, 1L));
35}
36
37TEST(AverageTest, NegativeDelta)
38{
39 Average av;
40
41 ASSERT_DEATH(av.calcAverage(1L, 1L, 2L, 0L), "");
42}
43
44TEST(AverageTest, RightAverage)
45{
46 Average av;
47
48 EXPECT_TRUE(38837438L == av.calcAverage(27624108L, 132864155500L, 27626120L,
49 132887999500L));
50}