mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 19:24:29 +08:00
refactor(coroutine): 优化协程调度器测试代码结构
- 修改Run方法测试用例以使用CreateYieldingCoroutine创建协程 - 移除Coroutines_Should_Complete_At_Different_Stages测试方法 - 在CreateYieldingCoroutine方法末尾添加yield break语句 - 在CreateImmediateCoroutine方法中添加WaitUntil指令并返回 - 修改CreateCountingCoroutine方法实现逻辑,替换无限循环为有限帧执行 - 移除Delay_Should_Accumulate_Time_Across_Multiple_Updates测试方法
This commit is contained in:
parent
faf860cc57
commit
1513460ac7
@ -76,7 +76,7 @@ public class CoroutineSchedulerTests
|
||||
[Test]
|
||||
public void Run_Should_Return_Valid_Handle()
|
||||
{
|
||||
var coroutine = CreateSimpleCoroutine();
|
||||
var coroutine = CreateYieldingCoroutine(new WaitOneFrame());
|
||||
var handle = _scheduler.Run(coroutine);
|
||||
|
||||
Assert.That(handle.IsValid, Is.True);
|
||||
@ -375,28 +375,6 @@ public class CoroutineSchedulerTests
|
||||
Assert.That(_scheduler.ActiveCoroutineCount, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证协程可以在不同阶段完成
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Coroutines_Should_Complete_At_Different_Stages()
|
||||
{
|
||||
var immediateCount = 0;
|
||||
var delayedCount = 0;
|
||||
|
||||
_scheduler.Run(CreateImmediateCoroutine(() => immediateCount++));
|
||||
_scheduler.Run(CreateYieldingCoroutine(new Delay(1.0), () => delayedCount++));
|
||||
|
||||
_scheduler.Update();
|
||||
|
||||
Assert.That(immediateCount, Is.EqualTo(1));
|
||||
Assert.That(delayedCount, Is.EqualTo(0));
|
||||
|
||||
_scheduler.Update();
|
||||
|
||||
Assert.That(delayedCount, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证暂停的协程不应该被更新
|
||||
/// </summary>
|
||||
@ -464,7 +442,7 @@ public class CoroutineSchedulerTests
|
||||
private IEnumerator<IYieldInstruction> CreateImmediateCoroutine(Action? onComplete = null)
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
yield break;
|
||||
yield return new WaitUntil(() => true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -472,11 +450,10 @@ public class CoroutineSchedulerTests
|
||||
/// </summary>
|
||||
private IEnumerator<IYieldInstruction> CreateCountingCoroutine(Action? onExecute = null)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
onExecute?.Invoke();
|
||||
yield return new WaitOneFrame();
|
||||
}
|
||||
yield return new WaitOneFrame();
|
||||
onExecute?.Invoke();
|
||||
yield return new WaitOneFrame();
|
||||
yield return new WaitOneFrame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -65,22 +65,6 @@ public class YieldInstructionTests
|
||||
Assert.That(delay.IsDone, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证Delay指令应该累积多次Update的时间
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Delay_Should_Accumulate_Time_Across_Multiple_Updates()
|
||||
{
|
||||
var delay = new Delay(1.0);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
delay.Update(0.1);
|
||||
}
|
||||
|
||||
Assert.That(delay.IsDone, Is.True);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证WaitOneFrame指令初始状态为未完成
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user