-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTestTimers.cs
executable file
·63 lines (51 loc) · 1.69 KB
/
TestTimers.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
namespace Flow.Test
{
using System;
using NUnit.Framework;
public class TestTimers
: TestBase
{
[TestCase(0.4f, 0.5f, true)]
[TestCase(0.4f, 0.2f, false)]
public void TestOneShot(float span, float runTime, bool shouldBeCompleted)
{
var elapsed = false;
var oneShotTimer = New.OneShotTimer(TimeSpan.FromSeconds(span), (timer) => elapsed = true);
Root.Add(oneShotTimer);
RunKernel(runTime);
if (shouldBeCompleted)
{
Assert.IsTrue(!oneShotTimer.Active);
Assert.IsTrue(elapsed);
}
else
{
Assert.IsTrue(oneShotTimer.Active);
Assert.IsFalse(elapsed);
}
}
[TestCase(0.1f, 0.25f, 2)]
[TestCase(0.1f, 0.45f, 4)]
[TestCase(0.1f, 0.0f, 0)]
public void TestPeriodic(float interval, float runTime, int numElapsed)
{
var timer = New.PeriodicTimer(TimeSpan.FromSeconds(interval));
var elapsed = 0;
timer.Elapsed += tr => ++elapsed;
Root.Add(timer);
RunKernel(runTime);
Assert.AreEqual(numElapsed, elapsed);
}
[TestCase(0.1f, 0.2f, true)]
[TestCase(0.2f, 0.1f, false)]
public void TestTimedFuture(float futureLifetime, float runTime, bool result)
{
var future = New.TimedFuture<int>(TimeSpan.FromSeconds(futureLifetime));
Assert.IsFalse(future.Available);
Root.Add(future);
RunKernel(runTime);
Step();
Assert.AreEqual(result, future.HasTimedOut);
}
}
}