Files
Library/tests/standalone/Pipeline/Pipeline.cpp
T
faumarayandClaude Sonnet 4.6 58ff7b38a0 Add 20+ new modules with tests: Pipeline, Matrix, Tokenizer, ScopeGuard, Bitset, Optional, Counted, Curry, TypeMap, Bench, DisjointSet, Histogram, StopWatch, and more
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>
2026-05-14 23:49:09 +03:00

118 lines
4.0 KiB
C++

#include <Void/Pipeline/Pipeline.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
using namespace Void::Pipeline;
// ── pipe ──────────────────────────────────────────────────────────────────────
Void::Testing::Test pipe_single_step()
{
const int result = pipe(5) | [](int x) { return x * 2; };
Void::Testing::expect_eq(result, 10);
}
Void::Testing::Test pipe_multi_step()
{
const int result = pipe(3)
| [](int x) { return x + 1; } // 4
| [](int x) { return x * 3; } // 12
| [](int x) { return x - 2; }; // 10
Void::Testing::expect_eq(result, 10);
}
Void::Testing::Test pipe_type_change()
{
const std::string result = pipe(42)
| [](int x) { return std::to_string(x); }
| [](std::string s) { return "[" + s + "]"; };
Void::Testing::expect_eq(result, std::string{"[42]"});
}
Void::Testing::Test pipe_get_accessor()
{
auto p = pipe(99);
Void::Testing::expect_eq(p.get(), 99);
}
Void::Testing::Test pipe_implicit_conversion()
{
int v = pipe(7) | [](int x) { return x + 1; };
Void::Testing::expect_eq(v, 8);
}
Void::Testing::Test pipe_string_chain()
{
const std::string result = pipe(std::string{"hello"})
| [](std::string s) { s += " world"; return s; }
| [](std::string s) { s[0] = 'H'; return s; };
Void::Testing::expect_eq(result, std::string{"Hello world"});
}
// ── compose ───────────────────────────────────────────────────────────────────
Void::Testing::Test compose_two()
{
auto fn = compose([](int x) { return x + 1; },
[](int x) { return x * 2; });
Void::Testing::expect_eq(fn(3), 8); // (3+1)*2
}
Void::Testing::Test compose_three()
{
auto fn = compose([](int x) { return x + 1; },
[](int x) { return x * 2; },
[](int x) { return x - 1; });
Void::Testing::expect_eq(fn(3), 7); // ((3+1)*2)-1
}
Void::Testing::Test compose_type_change()
{
auto fn = compose([](int x) { return std::to_string(x); },
[](const std::string& s) { return s.size(); });
Void::Testing::expect_eq(fn(12345), std::size_t{5});
}
// ── partial ───────────────────────────────────────────────────────────────────
Void::Testing::Test partial_one_arg()
{
auto add = [](int a, int b) { return a + b; };
auto add5 = partial(add, 5);
Void::Testing::expect_eq(add5(3), 8);
Void::Testing::expect_eq(add5(10), 15);
}
Void::Testing::Test partial_two_args()
{
auto sum3 = [](int a, int b, int c) { return a + b + c; };
auto fixed = partial(sum3, 1, 2);
Void::Testing::expect_eq(fixed(10), 13);
}
// ── flip ──────────────────────────────────────────────────────────────────────
Void::Testing::Test flip_reverses_args()
{
auto sub = [](int a, int b) { return a - b; };
auto flipped = flip(sub);
Void::Testing::expect_eq(flipped(3, 10), 7); // sub(10, 3)
}
// ── identity / constant ───────────────────────────────────────────────────────
Void::Testing::Test identity_returns_value()
{
Void::Testing::expect_eq(identity(42), 42);
Void::Testing::expect_eq(identity(std::string{"x"}), std::string{"x"});
}
Void::Testing::Test constant_ignores_args()
{
auto always5 = constant(5);
Void::Testing::expect_eq(always5(), 5);
Void::Testing::expect_eq(always5(1, 2, 3), 5);
}