-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release 0.9.3 #18
Release 0.9.3 #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using Cysharp.Threading.Tasks; | ||
using GameLovers.StatechartMachine; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
using UnityEngine.TestTools; | ||
|
||
// ReSharper disable CheckNamespace | ||
|
||
|
@@ -79,6 +78,33 @@ public async Task TaskWait_EventTrigger_DoesNothing() | |
_caller.Received().FinalOnEnterCall(0); | ||
} | ||
|
||
[Test] | ||
public async Task UniTaskWait_EventTrigger_DoesNothing() | ||
{ | ||
var statechart = new Statechart(SetupUniTaskWaitState); | ||
|
||
statechart.Run(); | ||
|
||
_caller.Received().OnTransitionCall(0); | ||
_caller.DidNotReceive().OnTransitionCall(1); | ||
_caller.DidNotReceive().OnTransitionCall(2); | ||
_caller.Received().InitialOnExitCall(0); | ||
_caller.Received().StateOnEnterCall(0); | ||
_caller.DidNotReceive().StateOnExitCall(0); | ||
_caller.DidNotReceive().FinalOnEnterCall(0); | ||
|
||
statechart.Trigger(_event); | ||
|
||
_blocker = false; | ||
|
||
await YieldWaitUniTask(); | ||
|
||
_caller.Received().OnTransitionCall(1); | ||
_caller.DidNotReceive().OnTransitionCall(2); | ||
_caller.Received().StateOnExitCall(0); | ||
_caller.Received().FinalOnEnterCall(0); | ||
} | ||
|
||
Comment on lines
+81
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new test method [Test]
public async Task UniTaskWait_EventTrigger_DoesNothing()
{
var statechart = new Statechart(SetupUniTaskWaitState);
statechart.Run();
_caller.Received().OnTransitionCall(0);
_caller.DidNotReceive().OnTransitionCall(1);
_caller.DidNotReceive().OnTransitionCall(2);
_caller.Received().InitialOnExitCall(0);
_caller.Received().StateOnEnterCall(0);
_caller.DidNotReceive().StateOnExitCall(0);
_caller.DidNotReceive().FinalOnEnterCall(0);
statechart.Trigger(_event);
_blocker = false;
await YieldWaitUniTask();
_caller.Received().OnTransitionCall(1);
_caller.DidNotReceive().OnTransitionCall(2);
_caller.Received().StateOnExitCall(0);
_caller.Received().FinalOnEnterCall(0);
} |
||
[Test] | ||
public void TaskWait_MissingConfiguration_ThrowsException() | ||
{ | ||
|
@@ -122,7 +148,17 @@ private async Task TaskWaitAction() | |
|
||
_done = true; | ||
} | ||
|
||
|
||
private async UniTask UniTaskWaitAction() | ||
{ | ||
while (_blocker) | ||
{ | ||
await UniTask.Yield(); | ||
} | ||
|
||
_done = true; | ||
} | ||
|
||
Comment on lines
+151
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
private async Task YieldWaitTask() | ||
{ | ||
while (!_done) | ||
|
@@ -133,6 +169,16 @@ private async Task YieldWaitTask() | |
await Task.Yield(); | ||
} | ||
|
||
private async UniTask YieldWaitUniTask() | ||
{ | ||
while (!_done) | ||
{ | ||
await UniTask.Yield(); | ||
} | ||
|
||
await UniTask.Yield(); | ||
} | ||
Comment on lines
+172
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
private IFinalState SetupSimpleFlow(IStateFactory factory, IState state) | ||
{ | ||
var initial = factory.Initial("Initial"); | ||
|
@@ -155,5 +201,15 @@ private void SetupTaskWaitState(IStateFactory factory) | |
waiting.WaitingFor(TaskWaitAction).OnTransition(() => _caller.OnTransitionCall(1)).Target(final); | ||
waiting.OnExit(() => _caller.StateOnExitCall(0)); | ||
} | ||
|
||
private void SetupUniTaskWaitState(IStateFactory factory) | ||
{ | ||
var waiting = factory.TaskWait("Task Wait"); | ||
var final = SetupSimpleFlow(factory, waiting); | ||
|
||
waiting.OnEnter(() => _caller.StateOnEnterCall(0)); | ||
waiting.WaitingFor(UniTaskWaitAction).OnTransition(() => _caller.OnTransitionCall(1)).Target(final); | ||
waiting.OnExit(() => _caller.StateOnExitCall(0)); | ||
} | ||
Comment on lines
+205
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The private void SetupUniTaskWaitState(IStateFactory factory)
{
var waiting = factory.TaskWait("Task Wait");
var final = SetupSimpleFlow(factory, waiting);
waiting.OnEnter(() => _caller.StateOnEnterCall(0));
waiting.WaitingFor(UniTaskWaitAction).OnTransition(() => _caller.OnTransitionCall(1)).Target(final);
waiting.OnExit(() => _caller.StateOnExitCall(0));
} Overall, the changes seem fine. However, there are a few suggestions to improve the code:
Let me know if you have any questions or need further assistance! |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
using
statements have been modified.