Carol Wang | 9bbe602 | 2019-08-01 17:31:30 +0800 | [diff] [blame] | 1 | #include "average.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | using ::testing::Return; |
| 7 | |
| 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 | |
| 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")); |
Brad Bishop | 57e18b9 | 2019-10-07 18:10:49 -0400 | [diff] [blame] | 26 | auto expected = Average::averageValue(2, 2); |
| 27 | EXPECT_TRUE(value == expected); |
Carol Wang | 9bbe602 | 2019-08-01 17:31:30 +0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | TEST(AverageTest, ZeroDelta) |
| 31 | { |
| 32 | Average av; |
| 33 | |
| 34 | EXPECT_FALSE(av.calcAverage(1L, 1L, 2L, 1L)); |
| 35 | } |
| 36 | |
| 37 | TEST(AverageTest, NegativeDelta) |
| 38 | { |
| 39 | Average av; |
| 40 | |
| 41 | ASSERT_DEATH(av.calcAverage(1L, 1L, 2L, 0L), ""); |
| 42 | } |
| 43 | |
| 44 | TEST(AverageTest, RightAverage) |
| 45 | { |
| 46 | Average av; |
| 47 | |
| 48 | EXPECT_TRUE(38837438L == av.calcAverage(27624108L, 132864155500L, 27626120L, |
| 49 | 132887999500L)); |
| 50 | } |