summaryrefslogtreecommitdiffstats
path: root/dom/media/gtest/TestBenchmarkStorage.cpp
blob: 0f1eb7e4c42d59119a04cdf8b44f51dd9a8ac844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/BenchmarkStorageParent.h"

#include "gmock/gmock.h"
#include "gtest/gtest-printers.h"
#include "gtest/gtest.h"

using ::testing::Return;
using namespace mozilla;

TEST(BenchmarkStorage, MovingAverage)
{
  int32_t av = 0;
  int32_t win = 0;
  int32_t val = 100;
  BenchmarkStorageParent::MovingAverage(av, win, val);
  EXPECT_EQ(av, val) << "1st average";
  EXPECT_EQ(win, 1) << "1st window";

  av = 50;
  win = 1;
  val = 100;
  BenchmarkStorageParent::MovingAverage(av, win, val);
  EXPECT_EQ(av, 75) << "2nd average";
  EXPECT_EQ(win, 2) << "2nd window";

  av = 100;
  win = 9;
  val = 90;
  BenchmarkStorageParent::MovingAverage(av, win, val);
  EXPECT_EQ(av, 99) << "9th average";
  EXPECT_EQ(win, 10) << "9th window";

  av = 90;
  win = 19;
  val = 90;
  BenchmarkStorageParent::MovingAverage(av, win, val);
  EXPECT_EQ(av, 90) << "19th average";
  EXPECT_EQ(win, 20) << "19th window";

  av = 90;
  win = 20;
  val = 100;
  BenchmarkStorageParent::MovingAverage(av, win, val);
  EXPECT_EQ(av, 91) << "20th average";
  EXPECT_EQ(win, 20) << "20th window";
}

TEST(BenchmarkStorage, ParseStoredValue)
{
  int32_t win = 0;
  int32_t score = BenchmarkStorageParent::ParseStoredValue(1100, win);
  EXPECT_EQ(win, 1) << "Window";
  EXPECT_EQ(score, 100) << "Score/Percentage";

  win = 0;
  score = BenchmarkStorageParent::ParseStoredValue(10099, win);
  EXPECT_EQ(win, 10) << "Window";
  EXPECT_EQ(score, 99) << "Score/Percentage";

  win = 0;
  score = BenchmarkStorageParent::ParseStoredValue(15038, win);
  EXPECT_EQ(win, 15) << "Window";
  EXPECT_EQ(score, 38) << "Score/Percentage";

  win = 0;
  score = BenchmarkStorageParent::ParseStoredValue(20099, win);
  EXPECT_EQ(win, 20) << "Window";
  EXPECT_EQ(score, 99) << "Score/Percentage";
}

TEST(BenchmarkStorage, PrepareStoredValue)
{
  int32_t stored_value = BenchmarkStorageParent::PrepareStoredValue(80, 1);
  EXPECT_EQ(stored_value, 1080) << "Window";

  stored_value = BenchmarkStorageParent::PrepareStoredValue(100, 6);
  EXPECT_EQ(stored_value, 6100) << "Window";

  stored_value = BenchmarkStorageParent::PrepareStoredValue(1, 10);
  EXPECT_EQ(stored_value, 10001) << "Window";

  stored_value = BenchmarkStorageParent::PrepareStoredValue(88, 13);
  EXPECT_EQ(stored_value, 13088) << "Window";

  stored_value = BenchmarkStorageParent::PrepareStoredValue(100, 20);
  EXPECT_EQ(stored_value, 20100) << "Window";
}