コード例 #1
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!
 }