-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovingMaxTests.cs
More file actions
75 lines (65 loc) · 1.55 KB
/
MovingMaxTests.cs
File metadata and controls
75 lines (65 loc) · 1.55 KB
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
using System.Linq;
using NUnit.Framework;
namespace yield
{
[TestFixture]
public class MovingMaxTests
{
[Test]
public void EmptySequence()
{
CheckMax(10, new double[] { }, new double[] { });
}
[Test]
public void SingleZero()
{
CheckMax(10, new[] { 0.0 }, new[] { 0.0 });
}
[Test]
public void SingleNonZeroValue()
{
CheckMax(10, new[] { 100.0 }, new[] { 100.0 });
}
[Test]
public void TwoValuesIncreasing()
{
CheckMax(2, new[] { 1, 20.0 }, new[] { 1, 20.0 });
}
[Test]
public void TwoValuesDecreasing()
{
CheckMax(2, new[] { 10, 0.0 }, new[] { 10, 10.0 });
}
[Test]
public void TwoValuesWithSmallWindow()
{
CheckMax(1, new[] { 10, 0.0 }, new[] { 10, 0.0 });
}
[Test]
public void WithWindow2()
{
CheckMax(2, new double[] { 1, 2, 5, 1, 0, 6 }, new double[] { 1, 2, 5, 5, 1, 6});
}
[Test]
public void SmoothWithLargeWindow()
{
CheckMax(100500, new double[] { 1, 2, 5, 1, 0, 6 }, new double[] { 1, 2, 5, 5, 5, 6 });
}
private void CheckMax(int windowWidth, double[] ys, double[] expectedYs)
{
var dataPoints = ys.Select((v, index) => new DataPoint(GetX(index), v));
var actual = Factory.CreateAnalyzer().MovingMax(dataPoints, windowWidth).ToList();
Assert.AreEqual(ys.Length, actual.Count);
for (var i = 0; i < actual.Count; i++)
{
Assert.AreEqual(GetX(i), actual[i].X, 1e-7);
Assert.AreEqual(ys[i], actual[i].OriginalY, 1e-7);
Assert.AreEqual(expectedYs[i], actual[i].MaxY, 1e-7);
}
}
private double GetX(int index)
{
return (index - 3.0) / 2;
}
}
}