few more Y combinator tests

This commit is contained in:
Kacper Donat 2018-08-22 23:09:38 +02:00
parent a24647c455
commit dcee45e10b

View File

@ -84,4 +84,22 @@ class PartialApplicationTest extends \PHPUnit\Framework\TestCase
$applied(1);
}
public function testYCombinatorFactorial()
{
$applied = f\fix(function ($f) {
return function ($x) use ($f) { return $x >= 2 ? $f($x-1) * $x : 1; };
});
$this->assertEquals(6, $applied(3));
$this->assertEquals(24, $applied(4));
}
public function testYCombinatorCurried()
{
$applied = f\fix(f\curry(function ($f, $x) { return $x >= 2 ? $f($x-1) * $x : 1; }));
$this->assertEquals(6, $applied(3));
$this->assertEquals(24, $applied(4));
}
}