GeWuYou af583c101c refactor(core): 重构协程扩展和函数式编程相关代码
- 优化 CommandCoroutineExtensions 中的代码格式和异常处理逻辑
- 简化 WaitForEvent 和 WaitForEventWithTimeout 中的EventData属性实现
- 调整 EventListenerScope 中的EventData属性访问器
- 重构 ControlExtensions 中 TakeIf 和 TakeUnless 方法的实现
- 优化 FunctionExtensions 中 Repeat 和 Partial 方法的代码结构
- 调整 PipeExtensions 和其他扩展类的文档注释格式
- 修改测试代码中的协程迭代和事件注册相关实现
- 优化 DataRepository 中的异步操作实现方式
= [release ci]
2026-02-01 14:07:59 +08:00

46 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.Core.functional.functions;
using NUnit.Framework;
namespace GFramework.Core.Tests.functional.functions;
/// <summary>
/// FunctionExtensions扩展方法测试类用于验证高级函数式编程扩展方法的正确性
/// 包括柯里化、偏函数应用、重复执行、安全执行和缓存等功能的测试
/// </summary>
[TestFixture]
public class FunctionExtensionsTests
{
/// <summary>
/// 测试Partial方法 - 验证部分应用函数功能
/// </summary>
[Test]
public void Partial_Should_Fix_First_Argument_Of_Binary_Function()
{
// Arrange
Func<int, int, int> multiply = (x, y) => x * y;
// Act
var doubleFunction = multiply.Partial(2);
var result = doubleFunction(5);
// Assert
Assert.That(result, Is.EqualTo(10));
}
/// <summary>
/// 测试Repeat方法 - 验证重复执行函数功能
/// </summary>
[Test]
public void Repeat_Should_Execute_Function_N_Times()
{
// Arrange
var initialValue = 2;
// Act
var result = initialValue.Repeat(3, x => x * 2);
// Assert
// 2 -> 4 -> 8 -> 16 (3次重复)
Assert.That(result, Is.EqualTo(16));
}
}