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
;
17 explicit MyClass(uint32_t aValue
= 0) : mValue(aValue
) { }
19 bool operator==(const MyClass
& aOther
) const
21 return mValue
== aOther
.mValue
;
24 MyClass
operator+(const MyClass
& aOther
) const
26 return MyClass(mValue
+ aOther
.mValue
);
29 MyClass
operator-(const MyClass
& aOther
) const
31 return MyClass(mValue
- aOther
.mValue
);
34 MyClass
operator/(uint32_t aDiv
) const
36 return MyClass(mValue
/ aDiv
);
40 class RollingMeanSuite
43 RollingMeanSuite() { }
56 RollingMean
<uint32_t, uint64_t> mean(3);
57 MOZ_RELEASE_ASSERT(mean
.empty());
62 RollingMean
<uint32_t, uint64_t> mean(3);
65 MOZ_RELEASE_ASSERT(mean
.mean() == 4);
68 MOZ_RELEASE_ASSERT(mean
.empty());
71 MOZ_RELEASE_ASSERT(mean
.mean() == 3);
76 RollingMean
<uint32_t, uint64_t> mean(3);
79 MOZ_RELEASE_ASSERT(mean
.mean() == 10);
82 MOZ_RELEASE_ASSERT(mean
.mean() == 15);
85 MOZ_RELEASE_ASSERT(mean
.mean() == 21);
88 MOZ_RELEASE_ASSERT(mean
.mean() == 20);
91 MOZ_RELEASE_ASSERT(mean
.mean() == 16);
96 RollingMean
<MyClass
, MyClass
> mean(3);
98 mean
.insert(MyClass(4));
99 MOZ_RELEASE_ASSERT(mean
.mean() == MyClass(4));
102 MOZ_RELEASE_ASSERT(mean
.empty());
107 RollingMean
<uint32_t, uint64_t> mean(3);
108 mean
= RollingMean
<uint32_t, uint64_t>(4);
109 MOZ_RELEASE_ASSERT(mean
.maxValues() == 4);
112 MOZ_RELEASE_ASSERT(mean
.mean() == 10);
114 mean
= RollingMean
<uint32_t, uint64_t>(3);
119 MOZ_RELEASE_ASSERT(mean
.mean() == 50);
126 RollingMeanSuite suite
;