-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTestLoops.cs
executable file
·76 lines (64 loc) · 1.7 KB
/
TestLoops.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
namespace Flow.Test
{
using System.Collections;
using System.Linq;
using NUnit.Framework;
public class TestLoops
: TestBase
{
private int _count = 0;
[Test]
public void TestDebugLog()
{
Root.Add(New.Log("Hello World"));
Step(5);
}
[Test]
public void TestCoro()
{
Root.Add(New.Coroutine(CountTo, 10).Named("Body"));
_count = 0;
Step(20);
Assert.AreEqual(_count, 10);
}
private IEnumerator CountTo(IGenerator self, int max)
{
while (++_count != max)
yield return 0;
}
[TestCase(5, 5, true)]
[TestCase(3, 3, true)]
[TestCase(5, 3, false)]
[TestCase(3, 5, true)]
[TestCase(0, 5, false)]
public void TestWhile(int upper, int steps, bool shouldMatch)
{
_count = 0;
Root.Add(
New.While(() =>
{
++_count;
Print($"step={Kernel.StepNumber}, count={_count}");
return _count < upper;
})
);
Step(steps);
Print(_count);
if (shouldMatch)
Assert.AreEqual(upper, _count);
else
Assert.AreNotEqual(upper, _count);
}
[Test]
public void TestNop()
{
_count = 0;
New.Nop().AddTo(Root);
Assert.IsTrue(!Root.Contents.Any());
Step();
Assert.IsTrue(Root.Contents.Any());
Step();
Assert.IsTrue(!Root.Contents.Any());
}
}
}