1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/Assertions.h"
8 #include "mozilla/RollingMean.h"
10 using mozilla::RollingMean
;
16 explicit MyClass(uint32_t aValue
= 0) : mValue(aValue
) {}
18 bool operator==(const MyClass
& aOther
) const {
19 return mValue
== aOther
.mValue
;
22 MyClass
operator+(const MyClass
& aOther
) const {
23 return MyClass(mValue
+ aOther
.mValue
);
26 MyClass
operator-(const MyClass
& aOther
) const {
27 return MyClass(mValue
- aOther
.mValue
);
30 MyClass
operator/(uint32_t aDiv
) const { return MyClass(mValue
/ aDiv
); }
33 class RollingMeanSuite
{
35 RollingMeanSuite() = default;
47 RollingMean
<uint32_t, uint64_t> mean(3);
48 MOZ_RELEASE_ASSERT(mean
.empty());
52 RollingMean
<uint32_t, uint64_t> mean(3);
55 MOZ_RELEASE_ASSERT(mean
.mean() == 4);
58 MOZ_RELEASE_ASSERT(mean
.empty());
61 MOZ_RELEASE_ASSERT(mean
.mean() == 3);
65 RollingMean
<uint32_t, uint64_t> mean(3);
68 MOZ_RELEASE_ASSERT(mean
.mean() == 10);
71 MOZ_RELEASE_ASSERT(mean
.mean() == 15);
74 MOZ_RELEASE_ASSERT(mean
.mean() == 21);
77 MOZ_RELEASE_ASSERT(mean
.mean() == 20);
80 MOZ_RELEASE_ASSERT(mean
.mean() == 16);
84 RollingMean
<MyClass
, MyClass
> mean(3);
86 mean
.insert(MyClass(4));
87 MOZ_RELEASE_ASSERT(mean
.mean() == MyClass(4));
90 MOZ_RELEASE_ASSERT(mean
.empty());
94 RollingMean
<uint32_t, uint64_t> mean(3);
95 mean
= RollingMean
<uint32_t, uint64_t>(4);
96 MOZ_RELEASE_ASSERT(mean
.maxValues() == 4);
99 MOZ_RELEASE_ASSERT(mean
.mean() == 10);
101 mean
= RollingMean
<uint32_t, uint64_t>(3);
106 MOZ_RELEASE_ASSERT(mean
.mean() == 50);
111 RollingMeanSuite suite
;