コード例 #1
0
ファイル: notLTest.php プロジェクト: rkgladson/PHPixme
 public function test_return()
 {
     $this->assertTrue(P\notL(false));
     $this->assertFalse(P\notL(true));
     $this->assertTrue(P\notL(P\_())->__invoke(false));
     $this->assertFalse(P\notL(P\_())->__invoke(true));
 }
コード例 #2
0
ファイル: orLTest.php プロジェクト: rkgladson/PHPixme
 /**
  * @dataProvider truthTableProvider
  */
 public function test_return($x = true, $y = false)
 {
     $expectedResult = $x || $y;
     $this->assertEquals($expectedResult, P\orL($x, $y), 'Immediate application');
     $orL_XXY = P\orL(P\_(), $y);
     $this->assertInstanceOf(Closure, $orL_XXY, 'deferred flipped application');
     $this->assertTrue($orL_XXY === $orL_XXY(), 'thunk identity');
     $this->assertEquals($expectedResult, $orL_XXY($x));
     $this->assertEquals($expectedResult, $orL_XXY()->__invoke($x));
     $orLXX = P\orL($x);
     $this->assertInstanceOf(Closure, $orLXX, 'omission should be a closure');
     $this->assertTrue($orLXX === $orLXX(), 'thunk identity');
     $this->assertEquals($expectedResult, $orLXX($y));
     $this->assertEquals($expectedResult, $orLXX()->__invoke($y));
     $orLXX_Y = P\orL($x, P\_());
     $this->assertInstanceOf(Closure, $orLXX_Y, '2nd placeholder should be a closure');
     $this->assertTrue($orLXX_Y === $orLXX_Y(), 'thunk identity');
     $this->assertEquals($expectedResult, $orLXX_Y($y));
     $this->assertEquals($expectedResult, $orLXX_Y()->__invoke($y));
     // Torture the thunk.
     $orL = P\orL();
     $this->assertEquals($expectedResult, $orL($x, $y));
     $this->assertEquals($expectedResult, $orL(P\_(), $y)->__invoke($x));
     $this->assertEquals($expectedResult, $orL($x)->__invoke($y));
     $this->assertEquals($expectedResult, $orL($x, P\_())->__invoke($y));
 }
コード例 #3
0
ファイル: gtTest.php プロジェクト: rkgladson/PHPixme
 public function test_return($x = 0, $y = 1)
 {
     $expectedResult = $x > $y;
     $this->assertEquals($expectedResult, P\gt($x, $y), 'Immediate application');
     $gt_XXY = P\gt(P\_(), $y);
     $this->assertInstanceOf(Closure, $gt_XXY, 'deferred flipped application');
     $this->assertEquals($expectedResult, $gt_XXY($x), 'the function should be able to be placeheld for easier flipping');
 }
コード例 #4
0
ファイル: xorBTest.php プロジェクト: rkgladson/PHPixme
 /**
  * @dataProvider truthTableProvider
  */
 public function test_return($x = true, $y = false)
 {
     $expectedResult = ($x xor $y);
     $this->assertEquals($expectedResult, P\xorB($x, $y), 'Immediate application');
     $xorB_XXY = P\xorB(P\_(), $y);
     $this->assertInstanceOf(Closure, $xorB_XXY, 'deferred flipped application');
     $this->assertEquals($expectedResult, $xorB_XXY($x), 'the function should be able to be placeheld for easier flipping');
 }
コード例 #5
0
ファイル: shiftRTest.php プロジェクト: rkgladson/PHPixme
 public function test_return($lhs = 1, $rhs = 5)
 {
     $expectedResult = $lhs >> $rhs;
     $this->assertEquals($expectedResult, P\shiftR($lhs, $rhs), 'Immediate application');
     $shiftR_XXY = P\shiftR(P\_(), $rhs);
     $this->assertInstanceOf(Closure, $shiftR_XXY, 'deferred flipped application');
     $this->assertEquals($expectedResult, $shiftR_XXY($lhs), 'the function should be able to be placeheld for easier flipping');
 }
コード例 #6
0
ファイル: negTest.php プロジェクト: rkgladson/PHPixme
 public function test_return($x = 1)
 {
     $expectedResult = -$x;
     $this->assertEquals($expectedResult, P\neg($x), 'Immediate application');
     $neg_X = P\neg(P\_());
     $this->assertInstanceOf(Closure, $neg_X, 'deferred flipped application');
     $this->assertEquals($expectedResult, $neg_X($x), 'the function should be able to be placeheld for easier flipping');
 }
コード例 #7
0
ファイル: notBTest.php プロジェクト: rkgladson/PHPixme
 public function test_return()
 {
     $resultFalse = ~1;
     $resultTrue = ~0;
     $this->assertEquals($resultTrue, P\notB(0));
     $this->assertEquals($resultFalse, P\notB(1));
     $this->assertEquals($resultTrue, P\notB(P\_())->__invoke(0));
     $this->assertEquals($resultFalse, P\notB(P\_())->__invoke(1));
 }
コード例 #8
0
ファイル: curryTest.php プロジェクト: rkgladson/PHPixme
 public function test_with_placeholder()
 {
     $equivlentArray5 = [1, 2, 3, 4, 5];
     $equivlentArray7 = [1, 2, 3, 4, 5, 6, 7];
     $getArgs = function () {
         return func_get_args();
     };
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(1, P\_(), 3, P\_(), 5)->__invoke(2)->__invoke(4), $equivlentArray5, 'When within, the placeholders in Curry should be filled in one by one.');
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(P\_(), P\_(), 3, 4, 5)->__invoke(1, 2), $equivlentArray5, 'When using placeholders with curry, it should still be able to have a varadic follow up.');
     $this->assertEquals(P\curry(5, $getArgs)->__invoke(P\_(), P\_(), P\_(), P\_(), 5, 6)->__invoke(1, P\_(), P\_(), P\_(), 7)->__invoke(2, 3, 4), $equivlentArray7, 'The function should be able to exceed its arity');
 }
コード例 #9
0
ファイル: ufoTest.php プロジェクト: rkgladson/PHPixme
 /**
  * @dataProvider returnProvider
  */
 public function test_return($lhs = 0, $rhs = 1)
 {
     //    $expectedResult = $x <=> $y;
     $expectedResult = $lhs > $rhs ? 1 : ($lhs < $rhs ? -1 : 0);
     $this->assertEquals($expectedResult, P\ufo($lhs, $rhs), 'Immediate application');
     $this->assertTrue(is_int(P\ufo($lhs, $rhs)));
     $ufo_XXY = P\ufo(P\_(), $rhs);
     $this->assertInstanceOf(Closure, $ufo_XXY, 'deferred flipped application');
     $this->assertEquals($expectedResult, $ufo_XXY($lhs), 'the function should be able to be placeheld for easier flipping');
     $this->assertTrue(is_int($ufo_XXY($lhs)));
 }
コード例 #10
0
ファイル: _Test.php プロジェクト: rkgladson/PHPixme
 public function test_constant()
 {
     $this->assertInstanceOf(\stdClass::class, P\_(), 'the placeholder should be an instance of standard class');
     $this->assertTrue(P\_() === P\_(), 'the placeholder value should not change between executions.');
 }
コード例 #11
0
ファイル: __PRIVATE__Test.php プロジェクト: rkgladson/PHPixme
 /**
  * @covers PHPixme\__PRIVATE__::curryExactly3
  */
 public function test_curryExactly3()
 {
     // "The flow of time itself is convoluted; with heroes centuries old phasing in and out." -- Solaire of Astora
     $arity3 = internal::curryExactly3(function (...$args) {
         return $args;
     });
     $expectedOutput = [1, 2, 3];
     // Establishing some basic qualities of curryExactly3
     self::assertInstanceOf(Closure, $arity3);
     /*
      * A note about the notation.
      * => means imply.
      * (x)->a is a function.
      * X1 means that the first argument is set
      *  _1 means it is explicitly void in a call
      * -> ... -> between argument states means any number of identity operations caused by no arguments
      * ≅ means 'is essentially the same as' or more formally the categorically congruent to.
      * ∴ means 'therefore'
      * ∎ means end of a proof or Q.E.D.
      * In variable naming __ means a step in the sequence
      */
     /** Show that curryExactly3((x y z) -> a) ≅ (x y z) -> a **/
     self::assertInstanceOf(Closure, $arity3());
     self::assertSame($arity3, $arity3());
     self::assertSame($arity3, $arity3(_()));
     self::assertSame($arity3, $arity3(_(), _()));
     self::assertSame($arity3, $arity3(_(), _(), _()));
     // => curryExactly3((x y z)->a) -> ... -> a
     self::assertEquals($expectedOutput, $arity3(1, 2, 3, 4, 5));
     /** ∴ curryExactly3((x y z) -> a) ≅ (x y z) -> a ∎ **/
     /** show that  (X1)->(X2)->(X3)  ≅ (X1 X2 X3) **/
     $step1 = $arity3(1);
     // Prove that step 1 is a thunk
     self::assertInstanceOf(Closure, $step1);
     self::assertSame($step1, $step1());
     self::assertSame($step1, $step1(_()));
     self::assertSame($step1, $step1(_(), _()));
     $step2 = $step1(2);
     // Prove that step2 is a thunk
     self::assertInstanceOf(Closure, $step2);
     self::assertSame($step2, $step2());
     self::assertSame($step2, $step2(_()));
     self::assertSame($step2, $step2(_(), _()));
     self::assertEquals($expectedOutput, $step2(3, 4, 5));
     // => (X1)->...-> (X2) -> ...-> (X3) -> a
     unset($step1, $step2);
     /** ∴ (X1)->(X2)->(X3) ≅ (X1 X2 X3) ∎ **/
     /** Show that (X1 X2 X3)
      * ≅ (X1) -> (X2 X3)
      * ≅ (X1 _2)-> (X2 X3)
      * ≅ (X1 _2 _3) -> (X2 X3)
      **/
     // The step above proves that (X1) is a thunk.
     $step1X1_2 = $arity3(1, _());
     $step1X1_2_3 = $arity3(1, _(), _());
     // (X1) properties were proven previously as a thunk and a closure
     self::assertInstanceOf(Closure, $step1X1_2);
     self::assertInstanceOf(Closure, $step1X1_2_3);
     // (X1 _2) is a thunk
     self::assertSame($step1X1_2, $step1X1_2());
     self::assertSame($step1X1_2, $step1X1_2(_()));
     self::assertSame($step1X1_2, $step1X1_2(_(), _()));
     // (X1 _2 _3) is a thunk
     self::assertSame($step1X1_2_3, $step1X1_2_3());
     self::assertSame($step1X1_2_3, $step1X1_2_3(_()));
     self::assertSame($step1X1_2_3, $step1X1_2_3(_(), _()));
     // => (X1)-> ... -> (X2 X3) ≅ (X1 _2)-> ... -> (X2 X3) ≅ (X1 _2 _3)-> ... -> (X2 X3)
     self::assertEquals($expectedOutput, $arity3(1)->__invoke(2, 3, 7));
     self::assertEquals($expectedOutput, $step1X1_2(2, 3, 7));
     self::assertEquals($expectedOutput, $step1X1_2_3(2, 3, 7));
     unset($step1X1, $step1X1_2, $step1X1_2_3);
     /** ∴ (X1)->(X2 X3) ≅ (X1 _2)-> (X2 X3) ≅  (X1 _2 _3) -> (X2 X3) ≅ (X1 X2 X3) ∎ **/
     /** Show that (X1 X2 X3)
      * ≅ (X1 X2) -> (X3)
      * ≅ (X1 X2 _3)-> (X3)
      **/
     $step1X1X2 = $arity3(1, 2);
     $step1X1X2_3 = $arity3(1, 2, _());
     self::assertInstanceOf(Closure, $step1X1X2);
     self::assertSame($step1X1X2, $step1X1X2());
     self::assertSame($step1X1X2, $step1X1X2(_()));
     // (X1 X2) is a thunk
     self::assertInstanceOf(Closure, $step1X1X2_3);
     self::assertSame($step1X1X2_3, $step1X1X2_3());
     self::assertSame($step1X1X2_3, $step1X1X2_3(_()));
     // (X1 X2 _3) is a thunk
     // => (X1 X2 _3) -> ... -> (X3) ≅ (X1 X2) -> ... -> (X3)
     self::assertEquals($expectedOutput, $step1X1X2(3, 4, 5));
     self::assertEquals($expectedOutput, $step1X1X2_3(3, 2));
     unset($step1X1X2, $step1X1X2_3);
     /** ∴ (X1 X2 X3)
      * ≅ (X1 X2) -> (X3)
      * ≅ (X1 X2 _3) -> (X3) ∎
      **/
     /** Show that (X1 X2 X3)
      * ≅ (_1 _2 X3) -> (X1 X2)
      * ≅ (_1 _2 X3) -> (X1) -> (X2)
      * ≅ (_1 _2 X3) -> (X1 _2) -> (X2)
      **/
     $step1_1_2X3 = $arity3(_(), _(), 3);
     self::assertInstanceOf(Closure, $step1_1_2X3);
     self::assertSame($step1_1_2X3, $step1_1_2X3());
     self::assertSame($step1_1_2X3, $step1_1_2X3(_()));
     self::assertSame($step1_1_2X3, $step1_1_2X3(_(), _()));
     // (_1 _2 X3) is a thunk
     $step2_1_2X3__X1 = $step1_1_2X3(1);
     $step2_1_2X3__X1_3 = $step1_1_2X3(1, _());
     self::assertInstanceOf(Closure, $step2_1_2X3__X1);
     self::assertSame($step2_1_2X3__X1, $step2_1_2X3__X1());
     self::assertSame($step2_1_2X3__X1, $step2_1_2X3__X1(_()));
     // (_1 _2 X3) -> (X1) is a thunk
     self::assertInstanceOf(Closure, $step2_1_2X3__X1_3);
     self::assertSame($step2_1_2X3__X1_3, $step2_1_2X3__X1_3());
     self::assertSame($step2_1_2X3__X1_3, $step2_1_2X3__X1_3(_()));
     // (_1 _2 X3) -> (X1 _2) is a thunk
     // => (_1 _2 X3) -> ... -> (X1 X2)
     // ≅ (_1 _2 X3) -> ... -> (X1) -> ... -> (X2)
     // ≅ (_1 _2 X3) -> ... -> (X1 _2) -> ... -> (X2)
     self::assertEquals($expectedOutput, $step1_1_2X3(1, 2, 4));
     self::assertEquals($expectedOutput, $step2_1_2X3__X1(2, 4));
     self::assertEquals($expectedOutput, $step2_1_2X3__X1_3(2, 4));
     unset($step1_1_2X3, $step2_1_2X3__X1, $step2_1_2X3__X1_3);
     /** ∴ (X1 X2 X3)
      * ≅ (_1 _2 X3) -> (X1 X2)
      * ≅ (_1 _2 X3) -> (X1) -> (X2)
      * ≅ (_1 _2 X3) -> (X1 _2) -> (X2) ∎
      **/
     /** Show (X1 X2 X3)
      * ≅ (_1 X2) -> (X1 X3)
      * ≅ (_1 X2) -> (X1) -> (X3)
      * ≅ (_1 X2) -> (X1 _3) -> (X3)
      * ≅ (_1 X2 _3) -> (X1 X3)
      * ≅ (_1 X2 _3) -> (X1) -> (X3)
      * ≅ (_1 X2 _3) -> (X1 _3) -> (X3)
      **/
     $step1_1X2 = $arity3(_(), 2);
     self::assertInstanceOf(Closure, $step1_1X2);
     self::assertSame($step1_1X2, $step1_1X2());
     self::assertSame($step1_1X2, $step1_1X2(_()));
     self::assertSame($step1_1X2, $step1_1X2(_(), _()));
     // (_1 X2) is a thunk
     $step1_1X2_3 = $arity3(_(), 2, _());
     self::assertInstanceOf(Closure, $step1_1X2_3);
     self::assertSame($step1_1X2_3, $step1_1X2_3());
     self::assertSame($step1_1X2_3, $step1_1X2_3(_()));
     self::assertSame($step1_1X2_3, $step1_1X2_3(_(), _()));
     // (_1 X2 _3) is a thunk
     $step2_1X2__X1 = $step1_1X2(1);
     self::assertInstanceOf(Closure, $step2_1X2__X1);
     self::assertSame($step2_1X2__X1, $step2_1X2__X1());
     self::assertSame($step2_1X2__X1, $step2_1X2__X1(_()));
     // (_1 X2) -> (X1) is a thunk
     $step2_1X2_3__X1 = $step1_1X2_3(1);
     self::assertInstanceOf(Closure, $step2_1X2_3__X1);
     self::assertSame($step2_1X2_3__X1, $step2_1X2_3__X1());
     self::assertSame($step2_1X2_3__X1, $step2_1X2_3__X1(_()));
     // (_1 X2 _3) -> (X1) is a thunk
     $step2_1X2__X1_3 = $step1_1X2(1, _());
     self::assertInstanceOf(Closure, $step2_1X2__X1_3);
     self::assertSame($step2_1X2__X1_3, $step2_1X2__X1_3());
     self::assertSame($step2_1X2__X1_3, $step2_1X2__X1_3(_()));
     // (_1 X2) -> (X1 _3) is a thunk
     $step2_1X2_3__X1_3 = $step1_1X2_3(1, _());
     self::assertInstanceOf(Closure, $step2_1X2_3__X1_3);
     self::assertSame($step2_1X2_3__X1_3, $step2_1X2_3__X1_3());
     self::assertSame($step2_1X2_3__X1_3, $step2_1X2_3__X1_3(_()));
     // (_1 X2 _3) -> (X1 _3) is a thunk
     // => (_1 X2) -> ... -> (X1 X3)
     // ≅ (_1 X2 _3) -> ... -> (X1 X3)
     // ≅ (_1 X2) -> ... -> (X1) -> ... -> (X3)
     // ≅ (_1 X2 _3) ->  ... ->(X1) -> ... -> (X3)
     // ≅ (_1 X2) -> ... -> (X1 _3) -> ... -> (X3)
     // ≅ (_1 X2 _3) -> ... -> (X1 _3) -> ... -> (X3)
     self::assertEquals($expectedOutput, $step1_1X2(1, 3, 7));
     self::assertEquals($expectedOutput, $step1_1X2_3(1, 3, 7));
     self::assertEquals($expectedOutput, $step2_1X2__X1(3, 7));
     self::assertEquals($expectedOutput, $step2_1X2_3__X1(3, 7));
     self::assertEquals($expectedOutput, $step2_1X2__X1_3(3, 7));
     self::assertEquals($expectedOutput, $step2_1X2_3__X1_3(3, 7));
     unset($step1_1X2, $step1_1X2_3, $step2_1X2__X1, $step2_1X2_3__X1, $step2_1X2__X1_3, $step2_1X2_3__X1_3);
     /** ∴  (X1 X2 X3)
      * ≅ (_1 X2) -> (X1 X3)
      * ≅ (_1 X2) -> (X1) -> (X3)
      * ≅ (_1 X2) -> (X1 _3) -> (X3)
      * ≅ (_1 X2 _3) -> (X1 X3)
      * ≅ (_1 X2 _3) -> (X1) -> (X3)
      * ≅ (_1 X2 _3) -> (X1 _3) -> (X3) ∎
      **/
     /** Show that (X1 X2 X3)
      * ≅ (X1) -> (_2 X3) -> (X2)
      * ≅ (X1 _2) -> (_2 X3) -> (X2)
      * ≅ (X1 _2 _3) -> (_2 X3) -> (X2)
      * ≅ (X1 _2 X3) -> (X2)
      */
     // Previously proven: (X1) === (X1 _2) === (X1 _2 _3) Skipping step.
     $step2X1___2X3 = $arity3(1)->__invoke(_(), 3);
     self::assertInstanceOf(Closure, $step2X1___2X3);
     self::assertSame($step2X1___2X3, $step2X1___2X3());
     self::assertSame($step2X1___2X3, $step2X1___2X3(_()));
     // (X1) -> (_2 X3) is a thunk
     $step1X1_2X3 = $arity3(1, _(), 3);
     self::assertInstanceOf(Closure, $step1X1_2X3);
     self::assertSame($step1X1_2X3, $step1X1_2X3());
     self::assertSame($step1X1_2X3, $step1X1_2X3(_()));
     // (X1 _2 X3) is a thunk
     // => (X1)-> ... -> (_2 X3) -> ... -> (X2)
     // ≅ (X1 _2 X3) -> ... -> (X2)
     self::assertEquals($expectedOutput, $step2X1___2X3(2, 7));
     self::assertEquals($expectedOutput, $step1X1_2X3(2, 7));
     unset($step2X1___2X3, $step1X1_2X3);
     /** ∴ (X1 X2 X3)
      * ≅ (X1) -> (_2 X3) -> (X2)
      * ≅ (X1 _2) -> (_2 X3) -> (X2)
      * ≅ (X1 _2 _3) -> (_2 X3) -> (X2)
      * ≅ (X1 _2 X3) -> (X2) ∎
      */
     /** Show that (X1 X2 X3)
      * ≅ (_1 X2 X3) -> (X1)
      * ≅ (_1 X2)->(_1 X3) -> (X1)
      * ≅ (_1 X2 _3) -> (_1 X3) -> (X1)
      **/
     $step1_1X2X3 = $arity3(_(), 2, 3);
     self::assertInstanceOf(Closure, $step1_1X2X3);
     self::assertSame($step1_1X2X3, $step1_1X2X3());
     self::assertSame($step1_1X2X3, $step1_1X2X3(_()));
     // (_1 X2 X3) is a thunk
     // Previously we showed that (_1 X2) === (_1 X2 _3) and showed they were a thunk.
     // Skipping proofs for both of these steps
     $step2_1X2___1X3 = $arity3(_(), 2)->__invoke(_(), 3);
     self::assertInstanceOf(Closure, $step2_1X2___1X3);
     self::assertSame($step2_1X2___1X3, $step2_1X2___1X3());
     self::assertSame($step2_1X2___1X3, $step2_1X2___1X3(_()));
     // (_1 X2) -> (_1 X3) is a thunk
     $step2_1X2_3___1X3 = $arity3(_(), 2)->__invoke(_(), 3);
     self::assertInstanceOf(Closure, $step2_1X2_3___1X3);
     self::assertSame($step2_1X2_3___1X3, $step2_1X2_3___1X3());
     self::assertSame($step2_1X2_3___1X3, $step2_1X2_3___1X3(_()));
     // (_1 X2 _3) -> (_1 X3) is a thunk
     // => (_1 X2 X3) -> ... -> (X1)
     // ≅ (_1 X2)-> ... -> (_1 X3) -> ... -> (X1)
     // ≅ (_1 X2 _3) -> ... -> (_1 X3) -> ... ->(X1)
     self::assertEquals($expectedOutput, $step1_1X2X3(1, 7));
     self::assertEquals($expectedOutput, $step2_1X2___1X3(1, 7));
     self::assertEquals($expectedOutput, $step2_1X2_3___1X3(1, 7));
     unset($step1_1X2X3, $step2_1X2___1X3, $step2_1X2_3___1X3);
     /** ∴ (X1 X2 X3)
      * ≅ (_1 X2 X3) -> (X1)
      * ≅ (_1 X2)->(_1 X3) -> (X1)
      * ≅ (_1 X2 _3) -> (_1 X3) -> (X1) ∎
      **/
     /** Show that (X1 X2 X3) ≅ (_1 _2 X3) -> (_1 X2) -> (X1) **/
     // Previously we proved that (_1 _2 X3) is a thunk.
     // Skipping proof for this step
     $step2_1_2X3___1X2 = $arity3(_(), _(), 3)->__invoke(_(), 2);
     self::assertInstanceOf(Closure, $step2_1_2X3___1X2);
     self::assertSame($step2_1_2X3___1X2, $step2_1_2X3___1X2());
     self::assertSame($step2_1_2X3___1X2, $step2_1_2X3___1X2(_()));
     // (_1 _2 X3) -> (_1 X2) is a thunk
     // => (_1 _2 X3) -> (_1 X2) -> (X1)
     self::assertEquals($expectedOutput, $step2_1_2X3___1X2(1, 7));
     unset($step2_1_2X3___1X2);
     /** ∴ (X1 X2 X3) ≅ (_1 _2 X3) -> (_1 X2) -> (X1) ∎ **/
     // Praise the sun! \o/
     // Let us now go forth and engage in jolly cooperation!
 }