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")); |
| 26 | EXPECT_TRUE(value == std::make_pair(2L, 2L)); |
| 27 | } |
| 28 | |
| 29 | TEST(AverageTest, ZeroDelta) |
| 30 | { |
| 31 | Average av; |
| 32 | |
| 33 | EXPECT_FALSE(av.calcAverage(1L, 1L, 2L, 1L)); |
| 34 | } |
| 35 | |
| 36 | TEST(AverageTest, NegativeDelta) |
| 37 | { |
| 38 | Average av; |
| 39 | |
| 40 | ASSERT_DEATH(av.calcAverage(1L, 1L, 2L, 0L), ""); |
| 41 | } |
| 42 | |
| 43 | TEST(AverageTest, RightAverage) |
| 44 | { |
| 45 | Average av; |
| 46 | |
| 47 | EXPECT_TRUE(38837438L == av.calcAverage(27624108L, 132864155500L, 27626120L, |
| 48 | 132887999500L)); |
| 49 | } |