From dcee45e10b252a940b88bcdc407f56e1d18fcfc0 Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Wed, 22 Aug 2018 23:09:38 +0200 Subject: [PATCH] few more Y combinator tests --- tests/PartialApplicationTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/PartialApplicationTest.php b/tests/PartialApplicationTest.php index 6bed981..d29c63e 100644 --- a/tests/PartialApplicationTest.php +++ b/tests/PartialApplicationTest.php @@ -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)); + } } \ No newline at end of file