Skip to content

Commit

Permalink
Merge pull request #25 from kagikn/CoroutineEnhancement_
Browse files Browse the repository at this point in the history
IsCoroutineActiveの追加とtypo修正
  • Loading branch information
TORISOUP committed Oct 27, 2015
2 parents 91bf63a + f7c8bdf commit d96f7cd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Inferno/InfernoScripts/InfernoCore/CoroutineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public CoroutineSystem(DebugLogger logger = null)
/// </summary>
/// <param name="coroutine">登録するコルーチン</param>
/// <returns></returns>
public uint AddCrotoutine(IEnumerable<Object> coroutine)
public uint AddCoroutine(IEnumerable<Object> coroutine)
{
lock (_lockObject)
{
Expand All @@ -60,6 +60,15 @@ public void RemoveCoroutine(uint id)
}
}

/// <summary>
/// コルーチンが存在するかどうかチェックする
/// </summary>
/// <param name="id">存在するかどうか確認したいコルーチンID</param>
public bool ContainsCoroutine(uint id)
{
return _coroutines.ContainsKey(id);
}


/// <summary>
/// コルーチンの処理を行う
Expand Down
14 changes: 13 additions & 1 deletion Inferno/InfernoScripts/InfernoCore/InfernoScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected IObservable<Unit> CreateTickAsObservable(int millsecond)

protected uint StartCoroutine(IEnumerable<Object> coroutine)
{
return coroutineSystem.AddCrotoutine(coroutine);
return coroutineSystem.AddCoroutine(coroutine);
}

protected void StopCoroutine(uint id)
Expand All @@ -127,6 +127,18 @@ protected void StopCoroutine(uint id)
}
}

protected bool IsCoroutineActive(uint id)
{
if (coroutineSystem != null)
{
return coroutineSystem.ContainsCoroutine(id);
}
else
{
return false;
}
}

/// <summary>
/// 指定秒数待機するIEnumerable
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace InfernoTest
public class ChaosModeSettingLoaderTest
{
[TestMethod]
public void 全て正常値が設定されたJosonからChaosSettingが生成できる()
public void 全て正常値が設定されたJsonからChaosSettingが生成できる()
{
var testLoader =
new TestChaosModeSettingLoader(
Expand Down
40 changes: 34 additions & 6 deletions InfernoTest/CoroutineSystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public void Initialize()
}

[TestMethod]
public void AddCroutine時にそれぞれ別のidが連番で割り振られる()
public void AddCoroutine時にそれぞれ別のidが連番で割り振られる()
{
for (uint expected = 0; expected < 10; expected++)
{
var resultId = testCoroutineSystem.AddCrotoutine(testEnumerable(1));
var resultId = testCoroutineSystem.AddCoroutine(testEnumerable(1));
Assert.AreEqual(expected, resultId);
}

Expand All @@ -42,10 +42,10 @@ IEnumerable<Object> ExecuteEnumerator()


[TestMethod]
public void AddCroutine時に最初のコルーチンが実行される()
public void AddCoroutine時に最初のコルーチンが実行される()
{
actionCount = 0;
testCoroutineSystem.AddCrotoutine(ExecuteEnumerator());
testCoroutineSystem.AddCoroutine(ExecuteEnumerator());

//登録直後に実行されているはず
Assert.AreEqual(1, actionCount);
Expand All @@ -63,7 +63,7 @@ public void RemoveCoroutineで該当のCoroutineが削除される()
//10個登録
for (uint expected = 0; expected < 10; expected++)
{
testCoroutineSystem.AddCrotoutine(testEnumerable(5));
testCoroutineSystem.AddCoroutine(testEnumerable(5));
}

//IDは10個全て存在する
Expand Down Expand Up @@ -110,11 +110,39 @@ public void RemoveCoroutineで存在しないキーを削除しても例外に
testCoroutineSystem.RemoveCoroutine(0);
}

[TestMethod]
public void ContainsCoroutineで該当のCoroutineが存在するかどうかチェックされる()
{
//10個登録
for (uint expected = 0; expected < 10; expected++)
{
testCoroutineSystem.AddCoroutine(testEnumerable(5));
}

//IDは10個全て存在するか確認し、すぐに除去
Assert.AreEqual(10, testCoroutineSystem.RegisteredCoroutineCount);
for (uint id = 0; id < 10; id++)
{
Assert.IsTrue(testCoroutineSystem.ContainsCoroutine(id));
testCoroutineSystem.RemoveCoroutine(id);
}

//一度コルーチンを回す
testCoroutineSystem.CoroutineLoop();

//IDは10個全て存在していない
Assert.AreEqual(0, testCoroutineSystem.RegisteredCoroutineCount);
for (uint id = 0; id < 10; id++)
{
Assert.IsFalse(testCoroutineSystem.ContainsCoroutine(id));
}
}


[TestMethod]
public void NestしたIEnumerableを展開して実行できる()
{
testCoroutineSystem.AddCrotoutine(nestEnumerable());
testCoroutineSystem.AddCoroutine(nestEnumerable());
var i = 0;

//コルーチンが終了するまでの実行回数を数える
Expand Down

0 comments on commit d96f7cd

Please sign in to comment.