blob: 6d1cab418757b54d41f55c1bb0efe79108d2f1ee [file] [log] [blame]
Atif Niyaz83846822019-07-18 15:17:40 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18#include <input/LatencyStatistics.h>
19#include <cmath>
20#include <limits>
21
22namespace android {
23namespace test {
24
25TEST(LatencyStatisticsTest, ResetStats) {
26 LatencyStatistics stats{5min};
27 stats.addValue(5.0);
28 stats.addValue(19.3);
29 stats.addValue(20);
30 stats.reset();
31
32 ASSERT_EQ(stats.getCount(), 0u);
33 ASSERT_EQ(std::isnan(stats.getStDev()), true);
34 ASSERT_EQ(std::isnan(stats.getMean()), true);
35}
36
37TEST(LatencyStatisticsTest, AddStatsValue) {
38 LatencyStatistics stats{5min};
39 stats.addValue(5.0);
40
41 ASSERT_EQ(stats.getMin(), 5.0);
42 ASSERT_EQ(stats.getMax(), 5.0);
43 ASSERT_EQ(stats.getCount(), 1u);
44 ASSERT_EQ(stats.getMean(), 5.0);
45 ASSERT_EQ(stats.getStDev(), 0.0);
46}
47
48TEST(LatencyStatisticsTest, AddMultipleStatsValue) {
49 LatencyStatistics stats{5min};
50 stats.addValue(4.0);
51 stats.addValue(6.0);
52 stats.addValue(8.0);
53 stats.addValue(10.0);
54
55 float stdev = stats.getStDev();
56
57 ASSERT_EQ(stats.getMin(), 4.0);
58 ASSERT_EQ(stats.getMax(), 10.0);
59 ASSERT_EQ(stats.getCount(), 4u);
60 ASSERT_EQ(stats.getMean(), 7.0);
61 ASSERT_EQ(stdev * stdev, 5.0);
62}
63
64TEST(LatencyStatisticsTest, ShouldReportStats) {
65 LatencyStatistics stats{0min};
66 stats.addValue(5.0);
67
68 ASSERT_EQ(stats.shouldReport(), true);
69}
70
71} // namespace test
72} // namespace android