<?php require_once __DIR__ . '/vendor/autoload.php'; key_map(function ($name, $test) { echo "Checking {$name}: "; if ($result = $test()) { var_dump($result); die; } echo "Passed\n"; }, array('sample counts correctly' => function () { $n = abs(mt_rand()) & 255; $result = sample(function () { return null; }, $n); return $result === array_fill(0, $n, null) ? 0 : get_defined_vars(); }, 'truthy tests fail' => function () { $result = runtests(function () { return true; }); return count($result) === 0 ? 0 : get_defined_vars(); }, 'falsy tests pass' => function () { $pre = runtests(null); deftest('falsy', function () { }); $results = array_diff_key(runtests(null), $pre); return array() === $results ? 0 : get_defined_vars(); }));
$rhs = upto($n + 1); return $lhs === $rhs ? 0 : dump(get_defined_vars()); }, 'y1' => function ($x) { $n = $x % 4; return y(function ($f, $m) use($n) { return $m === $n ? $m : $f($m + 1); }, 0) !== $n; }, 'stream_take1' => function ($x) { $n = $x % 8; $lhs = upto($n); $rhs = stream_take($n, y(function ($f, $n, $_) { return [$n, $f($n + 1)]; }, 0)); return $lhs === $rhs ? 0 : dump(get_defined_vars()); }, 'tabulate1' => function ($a, $b, $c, $d, $e, $f) { $result = tabulate($a, $b, [$c => $d, $e => $f]); return strpos($result, "{$c} {$d}") === FALSE; }, 'tabulate2' => function ($a, $b, $c, $d, $e, $f) { $result = tabulate($a, [$b], [$c => $d]); return strpos($result, "{$a} {$b}") === FALSE; }, 'fanout' => function ($x) { list($s, $m) = fanout(['strval', 'minus'], $x); if ($s !== strval($x)) { return true; } if ($m !== -1 * $x) { return true; } }]); $failures = runtests(null); $failures ? var_dump(array('Test failures' => $failures)) : (print "All tests passed\n");
function id($x) { return $x; } deftests(['id' => function ($n) { $result = plumb([0], $n); return $result === $n ? 0 : get_defined_vars(); }, 'id2' => function ($n) { $result = plumb([], $n); return $result === $n ? 0 : get_defined_vars(); }, 'const' => function ($n, $m) { $result = plumb([[1]], $n, $m); return $result === $n ? 0 : get_defined_vars(); }, 'comp' => function ($l, $m, $n) { $lhs = plumb([[[2, __(1, 0)]]], op('+', $l), op('*', $m), $n); $rhs = $l + $m * $n; return $lhs === $rhs ? 0 : get_defined_vars(); }, 'nest' => function ($n) { $lhs = plumb([__('+', __('*', 0, 0)), __(__('id', 'id'), 0)], $n); $rhs = ($n + 1) * $n; return $lhs === $rhs ? 0 : get_defined_vars(); }, 'ops' => function ($m, $n) { $lhs = plumb([['+', 0, 1]], $m, $n); $rhs = $m + $n; return $lhs === $rhs ? 0 : get_defined_vars(); }]); if ($results = runtests(null)) { var_dump($results); } else { echo "All tests pass\n"; }