-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTestKernel.cs
executable file
·107 lines (78 loc) · 2.5 KB
/
TestKernel.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
96
97
98
99
100
101
102
103
104
105
106
107
using System.Linq;
using System.Collections.Generic;
using NUnit.Framework;
namespace Flow.Test
{
public class TestKernel : TestBase
{
[Test]
public void TestCoroutine()
{
var kernel = Create.Kernel();
var coro = kernel.Factory.Coroutine<int>(Coro1);
kernel.Root.Add(coro);
Assert.IsTrue(coro.Active);
Assert.IsTrue(coro.Running);
// first coroutine is added after first step
Assert.AreEqual(0, kernel.Root.Contents.Count());
kernel.Step();
Assert.AreEqual(1, kernel.Root.Contents.Count());
kernel.Step();
//Assert.AreEqual(1, coro.Value);
kernel.Step();
//Assert.AreEqual(2, coro.Value);
kernel.Step();
//Assert.AreEqual(3, coro.Value);
kernel.Step();
//Assert.AreEqual(3, coro.Value);
Assert.IsFalse(coro.Active);
Assert.IsFalse(coro.Running);
}
IEnumerator<int> Coro1(IGenerator self)
{
yield return 1;
yield return 2;
yield return 3;
}
[Test]
public void TestSubroutine()
{
}
int Sub1(IGenerator self, int num)
{
return num * self.StepNumber;
}
[Test()]
public void TestFuture()
{
var kernel = Create.Kernel();
var spawn = kernel.Factory;
var future = spawn.Future<int>();
var coro = spawn.Coroutine<bool, IFuture<int>>(Coro2, future);
_futureSet = false;
kernel.Root.Add(future, coro);
kernel.Step();
kernel.Step();
Assert.IsFalse(_futureSet);
Assert.IsFalse(future.Available);
future.Value = 42;
Assert.IsTrue(future.Available);
Assert.AreEqual(42, future.Value);
kernel.Step();
//Assert.IsFalse(coro.Value);
Assert.IsTrue(_futureSet);
}
bool _futureSet;
IEnumerator<bool> Coro2(IGenerator self, IFuture<int> future)
{
Assert.IsFalse(!future.Active);
Assert.IsFalse(future.Available);
yield return self.ResumeAfter(future) != null;
_futureSet = true;
Assert.IsTrue(!future.Active);
Assert.IsTrue(future.Available);
Assert.AreEqual(future.Value, 42);
yield return false;
}
}
}