-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExpSmoothingTests.cs
More file actions
69 lines (60 loc) · 1.5 KB
/
ExpSmoothingTests.cs
File metadata and controls
69 lines (60 loc) · 1.5 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
using System.Linq;
using NUnit.Framework;
namespace yield
{
[TestFixture]
public class ExpSmoothingTests
{
[Test]
public void SmoothEmptySequence()
{
CheckSmooth(0.1, new double[] { }, new double[] { });
}
[Test]
public void SmoothSingleZero()
{
CheckSmooth(0.1, new[] { 0.0 }, new[] { 0.0 });
}
[Test]
public void SmoothSingleNonZeroValue()
{
CheckSmooth(0.5, new[] { 100.0 }, new[] { 100.0 });
}
[Test]
public void SmoothTwoValues()
{
CheckSmooth(0.1, new[] { 0, 20.0 }, new[] { 0, 2.0 });
}
[Test]
public void SmoothTwoValues2()
{
CheckSmooth(0.1, new[] { 10, 0.0 }, new[] { 10, 9.0 });
}
[Test]
public void SmoothWithZeroAlpha()
{
CheckSmooth(0.0, new double[] { 1, 2, 3, 4, 5, 6 }, new double[] { 1, 1, 1, 1, 1, 1 });
}
[Test]
public void SmoothWithOneAlpha()
{
CheckSmooth(1.0, new double[] { 1, 2, 3, 4, 5, 6 }, new double[] { 1, 2, 3, 4, 5, 6 });
}
private void CheckSmooth(double alpha, double[] ys, double[] expectedYs)
{
var dataPoints = ys.Select((v, index) => new DataPoint(GetX(index), v));
var actual = Factory.CreateAnalyzer().SmoothExponentialy(dataPoints, alpha).ToList();
Assert.AreEqual(ys.Length, actual.Count);
for (int 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].ExpSmoothedY, 1e-7);
}
}
private double GetX(int index)
{
return (index - 3.0)/2;
}
}
}