-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.cs
95 lines (80 loc) · 3.79 KB
/
Graph.cs
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
93
94
95
#region SearchAThing.UnitTests, Copyright(C) 2015-2016 Lorenzo Delana, License under MIT
/*
* The MIT License(MIT)
* Copyright(c) 2016 Lorenzo Delana, https://searchathing.com
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion
using SearchAThing.Core;
using SearchAThing.Graph;
using System;
using System.Linq;
using Xunit;
namespace SearchAThing.UnitTests
{
public class Graph
{
#region monitor plot [tests]
[Fact(DisplayName = "MonitorPlot")]
public void MonitorPlotTest1()
{
IMonitorPlot plot = new MonitorPlot(3);
var dsmean = plot.AddDataSet("6 seconds", TimeSpan.FromSeconds(6));
var dtnow = DateTime.Now;
var ts = TimeSpan.FromSeconds(1);
plot.Add(new MonitorData(dtnow, 5), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 6), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 1), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 2), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 3), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 4), dtnow); dtnow += ts;
var q1 = plot.DataSets.First(w => w.Name == "default");
var q1lst = q1.Points.ToList();
Assert.True(q1lst.Count == 3);
// checks that the first "default" set window move to the last three data
Assert.True(q1lst[0].Value.EqualsAutoTol(2));
Assert.True(q1lst[1].Value.EqualsAutoTol(3));
Assert.True(q1lst[2].Value.EqualsAutoTol(4));
// now check that the "6 seconds" dataset mean 3 points over last 6 seconds
// in other words it will get (5.5, 1.5, 3.5) that are means of ( (5,6), (1,2), (3,4) )
var meanlst = dsmean.Points.ToList();
Assert.True(meanlst.Count == 3);
Assert.True(meanlst[0].Value.EqualsAutoTol(5.5));
Assert.True(meanlst[1].Value.EqualsAutoTol(1.5));
Assert.True(meanlst[2].Value.EqualsAutoTol(3.5));
// proceed adding 2 more items
plot.Add(new MonitorData(dtnow, 6), dtnow); dtnow += ts;
plot.Add(new MonitorData(dtnow, 7), dtnow); dtnow += ts;
q1lst = q1.Points.ToList();
Assert.True(q1lst.Count == 3);
Assert.True(q1lst[0].Value.EqualsAutoTol(4));
Assert.True(q1lst[1].Value.EqualsAutoTol(6));
Assert.True(q1lst[2].Value.EqualsAutoTol(7));
// check the mean, should be (1.5, 3.5, 6.5)
meanlst = dsmean.Points.ToList();
Assert.True(meanlst.Count == 3);
Assert.True(meanlst[0].Value.EqualsAutoTol(1.5));
Assert.True(meanlst[1].Value.EqualsAutoTol(3.5));
Assert.True(meanlst[2].Value.EqualsAutoTol(6.5));
}
#endregion
}
}