few more Y combinator tests
This commit is contained in:
parent
a24647c455
commit
dcee45e10b
@ -84,4 +84,22 @@ class PartialApplicationTest extends \PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
$applied(1);
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user