Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions GFramework.Core.Tests/coroutine/WaitForConditionChangeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using GFramework.Core.Abstractions.coroutine;
using GFramework.Core.coroutine.instructions;
using NUnit.Framework;

namespace GFramework.Core.Tests.coroutine;

/// <summary>
/// WaitForConditionChange的单元测试类
/// </summary>
[TestFixture]
public class WaitForConditionChangeTests
{
/// <summary>
/// 验证WaitForConditionChange初始状态为未完成
/// </summary>
[Test]
public void WaitForConditionChange_Should_Not_Be_Done_Initially()
{
var condition = false;
var wait = new WaitForConditionChange(() => condition, true);

Assert.That(wait.IsDone, Is.False);
}

/// <summary>
/// 验证WaitForConditionChange从false变为true时完成
/// </summary>
[Test]
public void WaitForConditionChange_Should_Be_Done_When_Changing_From_False_To_True()
{
var condition = false;
var wait = new WaitForConditionChange(() => condition, true);

// 初始状态记录
wait.Update(0.1);

condition = true;
wait.Update(0.1);

Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForConditionChange从true变为false时完成
/// </summary>
[Test]
public void WaitForConditionChange_Should_Be_Done_When_Changing_From_True_To_False()
{
var condition = true;
var wait = new WaitForConditionChange(() => condition, false);

// 初始状态记录
wait.Update(0.1);

condition = false;
wait.Update(0.1);

Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForConditionChange不响应相同状态的变化
/// </summary>
[Test]
public void WaitForConditionChange_Should_Not_Be_Done_When_No_State_Change()
{
var condition = false;
var wait = new WaitForConditionChange(() => condition, true);

// 初始状态记录
wait.Update(0.1);

// 仍然是false,没有状态改变
wait.Update(0.1);

Assert.That(wait.IsDone, Is.False);
}

/// <summary>
/// 验证WaitForConditionChange多次状态切换只响应第一次
/// </summary>
[Test]
public void WaitForConditionChange_Should_Only_Respond_To_First_Transition()
{
var condition = false;
var wait = new WaitForConditionChange(() => condition, true);

// 记录初始状态
wait.Update(0.1);
Assert.That(wait.IsDone, Is.False);

// 触发状态转换到目标状态
condition = true;
wait.Update(0.1);
Assert.That(wait.IsDone, Is.True);

// 再次切换回原始状态
condition = false;
wait.Update(0.1);

// 应该仍然保持完成状态
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForConditionChange抛出ArgumentNullException当conditionGetter为null
/// </summary>
[Test]
public void WaitForConditionChange_Should_Throw_ArgumentNullException_When_ConditionGetter_Is_Null()
{
Assert.Throws<ArgumentNullException>(() => new WaitForConditionChange(null!, true));
}

/// <summary>
/// 验证WaitForConditionChange实现IYieldInstruction接口
/// </summary>
[Test]
public void WaitForConditionChange_Should_Implement_IYieldInstruction()
{
var wait = new WaitForConditionChange(() => false, true);

Assert.That(wait, Is.InstanceOf<IYieldInstruction>());
}
}
61 changes: 61 additions & 0 deletions GFramework.Core.Tests/coroutine/WaitForEndOfFrameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using GFramework.Core.Abstractions.coroutine;
using GFramework.Core.coroutine.instructions;
using NUnit.Framework;

namespace GFramework.Core.Tests.coroutine;

/// <summary>
/// WaitForEndOfFrame的单元测试类
/// </summary>
[TestFixture]
public class WaitForEndOfFrameTests
{
/// <summary>
/// 验证WaitForEndOfFrame初始状态为未完成
/// </summary>
[Test]
public void WaitForEndOfFrame_Should_Not_Be_Done_Initially()
{
var wait = new WaitForEndOfFrame();

Assert.That(wait.IsDone, Is.False);
}

/// <summary>
/// 验证WaitForEndOfFrame在Update后应该完成
/// </summary>
[Test]
public void WaitForEndOfFrame_Should_Be_Done_After_Update()
{
var wait = new WaitForEndOfFrame();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForEndOfFrame多次Update后仍保持完成状态
/// </summary>
[Test]
public void WaitForEndOfFrame_Should_Remain_Done_After_Multiple_Updates()
{
var wait = new WaitForEndOfFrame();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForEndOfFrame实现IYieldInstruction接口
/// </summary>
[Test]
public void WaitForEndOfFrame_Should_Implement_IYieldInstruction()
{
var wait = new WaitForEndOfFrame();

Assert.That(wait, Is.InstanceOf<IYieldInstruction>());
}
}
61 changes: 61 additions & 0 deletions GFramework.Core.Tests/coroutine/WaitForFixedUpdateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using GFramework.Core.Abstractions.coroutine;
using GFramework.Core.coroutine.instructions;
using NUnit.Framework;

namespace GFramework.Core.Tests.coroutine;

/// <summary>
/// WaitForFixedUpdate的单元测试类
/// </summary>
[TestFixture]
public class WaitForFixedUpdateTests
{
/// <summary>
/// 验证WaitForFixedUpdate初始状态为未完成
/// </summary>
[Test]
public void WaitForFixedUpdate_Should_Not_Be_Done_Initially()
{
var wait = new WaitForFixedUpdate();

Assert.That(wait.IsDone, Is.False);
}

/// <summary>
/// 验证WaitForFixedUpdate在Update后应该完成
/// </summary>
[Test]
public void WaitForFixedUpdate_Should_Be_Done_After_Update()
{
var wait = new WaitForFixedUpdate();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForFixedUpdate多次Update后仍保持完成状态
/// </summary>
[Test]
public void WaitForFixedUpdate_Should_Remain_Done_After_Multiple_Updates()
{
var wait = new WaitForFixedUpdate();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForFixedUpdate实现IYieldInstruction接口
/// </summary>
[Test]
public void WaitForFixedUpdate_Should_Implement_IYieldInstruction()
{
var wait = new WaitForFixedUpdate();

Assert.That(wait, Is.InstanceOf<IYieldInstruction>());
}
}
61 changes: 61 additions & 0 deletions GFramework.Core.Tests/coroutine/WaitForNextFrameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using GFramework.Core.Abstractions.coroutine;
using GFramework.Core.coroutine.instructions;
using NUnit.Framework;

namespace GFramework.Core.Tests.coroutine;

/// <summary>
/// WaitForNextFrame的单元测试类
/// </summary>
[TestFixture]
public class WaitForNextFrameTests
{
/// <summary>
/// 验证WaitForNextFrame初始状态为未完成
/// </summary>
[Test]
public void WaitForNextFrame_Should_Not_Be_Done_Initially()
{
var wait = new WaitForNextFrame();

Assert.That(wait.IsDone, Is.False);
}

/// <summary>
/// 验证WaitForNextFrame在Update后应该完成
/// </summary>
[Test]
public void WaitForNextFrame_Should_Be_Done_After_Update()
{
var wait = new WaitForNextFrame();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForNextFrame多次Update后仍保持完成状态
/// </summary>
[Test]
public void WaitForNextFrame_Should_Remain_Done_After_Multiple_Updates()
{
var wait = new WaitForNextFrame();

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);

wait.Update(0.016);
Assert.That(wait.IsDone, Is.True);
}

/// <summary>
/// 验证WaitForNextFrame实现IYieldInstruction接口
/// </summary>
[Test]
public void WaitForNextFrame_Should_Implement_IYieldInstruction()
{
var wait = new WaitForNextFrame();

Assert.That(wait, Is.InstanceOf<IYieldInstruction>());
}
}
Loading
Loading