Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now an alias for Edit<string> so count_op/apply work on line diffs; Memoized uses std::apply instead of type-based get to handle duplicate arg types. 874/877 tests pass (3 are platform-gated plugin tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
#include <Void/Curry/Curry.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
|
|
using namespace Void::Curry;
|
|
|
|
// ── curry ─────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test curry_binary_full_apply()
|
|
{
|
|
auto add = curry([](int a, int b) { return a + b; });
|
|
Void::Testing::expect_eq(add(3)(4), 7);
|
|
}
|
|
|
|
Void::Testing::Test curry_binary_partial_then_complete()
|
|
{
|
|
auto add = curry([](int a, int b) { return a + b; });
|
|
auto add10 = add(10);
|
|
Void::Testing::expect_eq(add10(5), 15);
|
|
Void::Testing::expect_eq(add10(20), 30);
|
|
}
|
|
|
|
Void::Testing::Test curry_ternary()
|
|
{
|
|
auto sum3 = curry([](int a, int b, int c) { return a + b + c; });
|
|
Void::Testing::expect_eq(sum3(1)(2)(3), 6);
|
|
}
|
|
|
|
Void::Testing::Test curry_ternary_partial_twice()
|
|
{
|
|
auto sum3 = curry([](int a, int b, int c) { return a + b + c; });
|
|
const auto sum3_with_1 = sum3(1);
|
|
const auto sum3_with_1_2 = sum3_with_1(2);
|
|
Void::Testing::expect_eq(sum3_with_1_2(10), 13);
|
|
}
|
|
|
|
Void::Testing::Test curry_type_change()
|
|
{
|
|
auto prefix = curry([](std::string p, std::string s) { return p + s; });
|
|
const auto add_hello = prefix(std::string{"hello "});
|
|
Void::Testing::expect_eq(add_hello(std::string{"world"}), std::string{"hello world"});
|
|
}
|
|
|
|
Void::Testing::Test curry_unary_invokes_immediately()
|
|
{
|
|
auto square = curry([](int x) { return x * x; });
|
|
Void::Testing::expect_eq(square(5), 25);
|
|
}
|
|
|
|
Void::Testing::Test curry_reuse_partial()
|
|
{
|
|
auto mul = curry([](int a, int b) { return a * b; });
|
|
const auto triple = mul(3);
|
|
Void::Testing::expect_eq(triple(4), 12);
|
|
Void::Testing::expect_eq(triple(5), 15);
|
|
Void::Testing::expect_eq(triple(6), 18);
|
|
}
|
|
|
|
Void::Testing::Test curry_with_lambda_capture()
|
|
{
|
|
int offset = 100;
|
|
auto add_offset = curry([&](int a, int b) { return a + b + offset; });
|
|
Void::Testing::expect_eq(add_offset(1)(2), 103);
|
|
}
|