SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
BlockInfoTests.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using NUnit.Framework;
6 using Seci.Definitions;
7 
8 namespace SeciTests
9 {
10  [TestFixture]
11  public class BlockInfoTests
12  {
13 
14  [Test]
16  {
17  //No previous value
18  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", null, 0.0));
19  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", null, 1.0));
20  Assert.IsTrue(BlockInfo.ExceedsTolerance("true", null, 1.0));
21  }
22 
23  [Test]
25  {
26  //Boolean values
27  Assert.IsFalse(BlockInfo.ExceedsTolerance("true", "true", 0.0));
28  Assert.IsTrue(BlockInfo.ExceedsTolerance("true", "false", 0.0));
29  Assert.IsTrue(BlockInfo.ExceedsTolerance("false", "true", 0.0));
30 
31  //Tolerance should not matter
32  Assert.IsFalse(BlockInfo.ExceedsTolerance("true", "true", 1.0));
33  Assert.IsTrue(BlockInfo.ExceedsTolerance("true", "false", 1.0));
34  Assert.IsTrue(BlockInfo.ExceedsTolerance("false", "true", 1.0));
35  }
36 
37  [Test]
39  {
40  //No tolerance
41  Assert.IsFalse(BlockInfo.ExceedsTolerance("0.0", "0.0", 0.0));
42  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "0.1", 0.0));
43  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "-0.1", 0.0));
44  }
45 
46  [Test]
48  {
49  //Tolerance
50  Assert.IsFalse(BlockInfo.ExceedsTolerance("0.0", "0.0", 1.0));
51  Assert.IsFalse(BlockInfo.ExceedsTolerance("0.0", "0.9", 1.0));
52  Assert.IsFalse(BlockInfo.ExceedsTolerance("0.0", "-0.9", 1.0));
53  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "1.0", 1.0));
54  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "-1.0", 1.0));
55  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "100.0", 1.0));
56  Assert.IsTrue(BlockInfo.ExceedsTolerance("0.0", "-100.0", 1.0));
57  }
58 
59 
60  [Test]
62  {
63  //Test that can log after a time interval
64  DateTime timeLastLogged = new DateTime(2000, 1, 1, 6, 0, 0);
65 
66  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "0", 0.0, false, false));
67  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "0", 0.0, false, false));
68  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(30), timeLastLogged, 15.0, "0", "0", 0.0, false, false));
69  }
70 
71  [Test]
73  {
74  //Test that it can handle the clocks going forward
75  DateTime timeLastLogged = new DateTime(2012, 3, 25, 1, 59, 55, DateTimeKind.Local);
76  DateTime newTime = new DateTime(2012, 3, 25, 2, 0, 10, DateTimeKind.Local);
77  Assert.IsTrue(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0", 0.0, false, false));
78 
79  //Check it does not log prematurely
80  newTime = new DateTime(2012, 3, 25, 2, 0, 5, DateTimeKind.Local);
81  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0", 0.0, false, false));
82  }
83 
84  [Test]
86  {
87  //Test that it can handle the clocks going back
88  DateTime timeLastLogged = new DateTime(2012, 10, 28, 0, 59, 55, DateTimeKind.Local);
89  DateTime newTime = new DateTime(2012, 10, 28, 1, 0, 10, DateTimeKind.Local);
90  Assert.IsTrue(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0", 0.0, false, false));
91 
92  //Check it does not log prematurely
93  newTime = new DateTime(2012, 10, 28, 1, 0, 5, DateTimeKind.Local);
94  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0", 0.0, false, false));
95  }
96 
97  [Test]
99  {
100  //Test that can log after a time interval
101  DateTime timeLastLogged = new DateTime(2000, 1, 1, 6, 0, 0);
102 
103  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "0", 1.0, false, true));
104  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
105  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
106  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "-1.0", 1.0, false, true));
107  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "100.0", 1.0, false, true));
108  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", "-100.0", 1.0, false, true));
109 
110  //Check it does not log prematurely
111  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "0", 1.0, false, true));
112  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
113  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
114  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "-1.0", 1.0, false, true));
115  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "100.0", 1.0, false, true));
116  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", "-100.0", 1.0, false, true));
117  }
118 
119  [Test]
121  {
122  //Test that it can handle the clocks going forward
123  DateTime timeLastLogged = new DateTime(2012, 3, 25, 1, 59, 55, DateTimeKind.Local);
124  DateTime newTime = new DateTime(2012, 3, 25, 2, 0, 10, DateTimeKind.Local);
125  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
126  Assert.IsTrue(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
127 
128  //Check it does not log prematurely
129  newTime = new DateTime(2012, 3, 25, 2, 0, 5, DateTimeKind.Local);
130  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
131  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
132  }
133 
134  [Test]
136  {
137  //Test that it can handle the clocks going back
138  DateTime timeLastLogged = new DateTime(2012, 10, 28, 0, 59, 55, DateTimeKind.Local);
139  DateTime newTime = new DateTime(2012, 10, 28, 1, 0, 10, DateTimeKind.Local);
140  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
141  Assert.IsTrue(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
142 
143  //Check it does not log prematurely
144  newTime = new DateTime(2012, 10, 28, 1, 0, 5, DateTimeKind.Local);
145  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "0.9", 1.0, false, true));
146  Assert.IsFalse(BlockInfo.OkayToLog(newTime, timeLastLogged, 15.0, "0", "1.0", 1.0, false, true));
147  }
148 
149  [Test]
150  public void OkayToLog_OnAnyChange()
151  {
152  //Test that can log after any change
153  DateTime timeLastLogged = new DateTime(2000, 1, 1, 6, 0, 0);
154 
155  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "0", 0.0, true, false));
156  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "0.1", 0.0, true, false));
157  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "-0.1", 0.0, true, false));
158  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "100.0", 0.0, true, false));
159  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "-100.0", 0.0, true, false));
160  }
161 
162  [Test]
164  {
165  //Test that can log after any change
166  DateTime timeLastLogged = new DateTime(2000, 1, 1, 6, 0, 0);
167 
168  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "0", 1.0, true, false));
169  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "0.9", 1.0, true, false));
170  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "1.0", 1.0, true, false));
171  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "-1.0", 1.0, true, false));
172  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "100.0", 1.0, true, false));
173  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "0", "-100.0", 1.0, true, false));
174  }
175 
176  [Test]
178  {
179  //Test that can log with no previous value
180  DateTime timeLastLogged = new DateTime(2000, 1, 1, 6, 0, 0);
181 
182  //On any change
183  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "1.0", null, 0.0, true, false));
184 
185  //On any change with tolerance
186  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged, timeLastLogged, 15.0, "1.0", null, 1.0, true, false));
187 
188  //On intervals
189  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", null, 0.0, false, false));
190  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", null, 0.0, false, false));
191 
192  //On intervals with tolerance
193  Assert.IsFalse(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(14), timeLastLogged, 15.0, "0", null, 1.0, false, false));
194  Assert.IsTrue(BlockInfo.OkayToLog(timeLastLogged.AddSeconds(15), timeLastLogged, 15.0, "0", null, 1.0, false, false));
195  }
196  }
197 }
void OkayToLog_OnTimeInterval_ClocksForward()
void OkayToLog_OnTimeInterval_ClocksBack()
void OkayToLog_OnTimeInterval_WithTolerance_ClocksBack()
void OkayToLog_OnTimeInterval_WithTolerance_ClocksForward()
void OkayToLog_OnTimeInterval_WithTolerance()
void OkayToLog_OnAnyChange_WithTolerance()