#include #include #include #include "strawberry/learn/features.hpp" using namespace strawberry::learn; #define CHECK(cond) \ do { \ if (!(cond)) { \ std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ std::exit(1); \ } \ } while (0) int main() { static_assert(kTupleKinds == 5, "layout assumes 5 tuple kinds"); static_assert(37 + kTupleKinds <= kDenseDims, "fleet slots must fit in dense dims"); { WindowSummary s{}; auto x0 = featurize(s); CHECK(x0[37] == 0.0f && x0[41] == 0.0f); } { WindowSummary s{}; s.fleet_bits = {1.6f, 3.2f, 0.0f, 16.0f, 8.0f}; auto x = featurize(s); CHECK(x[37] == 1.6f / 16.0f); CHECK(x[38] == 3.2f / 16.0f); CHECK(x[39] == 0.0f); CHECK(x[40] == 16.0f / 16.0f); CHECK(x[41] == 8.0f / 16.0f); } { WindowSummary s{}; s.max_bits = {2, 4, 6, 8, 10}; s.fleet_bits = {1, 1, 1, 1, 1}; CHECK(featurize(s)[25] == 2.0f / 16.0f); } { // Write->exec data-flow (Stage 3.5b2): differs exactly at x[42]. WindowSummary a{}; a.execs = 4; WindowSummary b = a; b.self_written_execs = 2; const auto xa = featurize(a); const auto xb = featurize(b); CHECK(featurize(b) == xb); // deterministic CHECK(xa[42] == 0.0f); CHECK(xb[42] == 0.5f); for (std::size_t i = 0; i < kFeatureDim; ++i) { if (i != 42) CHECK(xa[i] == xb[i]); } WindowSummary c = a; c.self_written_execs = 9; // clamped CHECK(featurize(c)[42] == 1.0f); CHECK(featurize(WindowSummary{})[42] == 0.0f); // execs == 0 // empty summary: hashed region stays all-zero const auto e = featurize(WindowSummary{}); for (std::size_t i = kDenseDims; i < kFeatureDim; ++i) CHECK(e[i] == 0.0f); } std::puts("test_features OK"); return 0; }