Skip to content

Commit

Permalink
Add SKI tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Feb 5, 2020
1 parent 99f7a2f commit 9a4b71f
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions spec/loophp/combinator/CombinatorsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use loophp\combinator\Combinator\W;
use loophp\combinator\Combinator\Y;
use loophp\combinator\Combinator\Z;
use loophp\combinator\Combinators;
use PhpSpec\ObjectBehavior;

class CombinatorsSpec extends ObjectBehavior
Expand All @@ -43,6 +44,9 @@ public function it_can_test_the_A_combinator()

$this::A()($a)('b')
->shouldBeEqualTo(A::with()($a)('b'));

$this::A()($a)('b')
->shouldReturn(Combinators::S()(Combinators::K())((Combinators::S())(Combinators::K()))($a)('b'));
}

public function it_can_test_the_B_combinator()
Expand All @@ -57,6 +61,17 @@ public function it_can_test_the_B_combinator()

$this::B()($a)($b)('c')
->shouldBeEqualTo(B::with()($a)($b)('c'));

$this::B()($a)($b)('c')
->shouldReturn(
Combinators::S() // S
(
Combinators::K() // K
(Combinators::S()) // S
)(
Combinators::K() // K
)($a)($b)('c')
);
}

public function it_can_test_the_C_combinator()
Expand All @@ -69,6 +84,19 @@ public function it_can_test_the_C_combinator()

$this::C()($f)('b')('c')
->shouldBeEqualTo(C::with()($f)('b')('c'));

$this::C()($f)('b')('c')
->shouldReturn(
Combinators::S() // S
(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()) // S
)(
Combinators::K() // K
(Combinators::K()) // K
)($f)('b')('c')
);
}

public function it_can_test_the_D_combinator()
Expand All @@ -87,6 +115,13 @@ public function it_can_test_the_D_combinator()

$this::D()($f2)('b')($g2)('d')
->shouldBeEqualTo(D::with()($f2)('b')($g2)('d'));

$this::D()($f2)('b')($g2)('d')
->shouldReturn(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
($f2)('b')($g2)('d')
);
}

public function it_can_test_the_E_combinator()
Expand All @@ -105,6 +140,16 @@ public function it_can_test_the_E_combinator()

$this::E()($f2)('b')($g2)('d')('e')
->shouldBeEqualTo(E::with()($f2)('b')($g2)('d')('e'));

$this::E()($f2)('b')($g2)('d')('e')
->shouldReturn(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
)($f2)('b')($g2)('d')('e')
);
}

public function it_can_test_the_F_combinator()
Expand All @@ -117,6 +162,16 @@ public function it_can_test_the_F_combinator()

$this::F()('a')('b')($f2)
->shouldBeEqualTo(F::with()('a')('b')($f2));

$this::F()('a')('b')($f2)
->shouldReturn(
Combinators::S()(Combinators::K()((Combinators::S()(Combinators::K()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))))(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))) // E
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I())) // T
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I())) // T
(Combinators::S()(Combinators::K()((Combinators::S()(Combinators::K()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))))(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))))) // E
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I())) // T
('a')('b')($f2)
);
}

public function it_can_test_the_G_combinator()
Expand All @@ -133,6 +188,14 @@ public function it_can_test_the_G_combinator()

$this::G()($f2)($g)('c')('d')
->shouldBeEqualTo(G::with()($f2)($g)('c')('d'));

$this::G()($f2)($g)('c')('d')
->shouldReturn(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))) // C
($f2)($g)('c')('d')
);
}

public function it_can_test_the_H_combinator()
Expand All @@ -153,6 +216,9 @@ public function it_can_test_the_I_combinator()
{
$this::I()('a')
->shouldBeEqualTo(I::with()('a'));

$this::I()('a')
->shouldReturn((Combinators::S()(Combinators::K())(Combinators::K()))('a'));
}

public function it_can_test_the_J_combinator()
Expand Down Expand Up @@ -197,6 +263,14 @@ public function it_can_test_the_L_combinator()

$this::L()($f)($g)
->shouldBeEqualTo(L::with()($f)($g));

$this::L()($f)($g)
->shouldReturn(
Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K())) // C
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()(Combinators::S()(Combinators::K())(Combinators::K()))(Combinators::S()(Combinators::K())(Combinators::K()))) // M
($f)($g)
);
}

public function it_can_test_the_M_combinator()
Expand All @@ -211,6 +285,14 @@ public function it_can_test_the_M_combinator()

$this::M()($f)
->shouldBeEqualTo(M::with()($f));

$this::M()($f)
->shouldReturn(
Combinators::S() // S
(Combinators::S()(Combinators::K())(Combinators::K())) // I
(Combinators::S()(Combinators::K())(Combinators::K())) // I
($f)
);
}

public function it_can_test_the_O_combinator()
Expand All @@ -229,6 +311,13 @@ public function it_can_test_the_O_combinator()

$this::O()($f)($g)
->shouldBeEqualTo(O::with()($f)($g));

$this::O()($f)($g)
->shouldReturn(
Combinators::S() // S
(Combinators::I()) // I
($f)($g)
);
}

public function it_can_test_the_Omega_combinator()
Expand Down Expand Up @@ -283,6 +372,7 @@ public function it_can_test_the_Psi_combinator()
->shouldBeEqualTo(Psi::with()($f2)($g)('c')('d'));
}

// CB
public function it_can_test_the_Q_combinator()
{
$f = static function (string $x) {
Expand All @@ -295,6 +385,13 @@ public function it_can_test_the_Q_combinator()

$this::Q()($f)($g)('c')
->shouldBeEqualTo(Q::with()($f)($g)('c'));

$this::Q()($f)($g)('c')
->shouldReturn(
Combinators::S()(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()))(Combinators::K()(Combinators::K())) // C
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
($f)($g)('c')
);
}

public function it_can_test_the_R_combinator()
Expand All @@ -307,6 +404,14 @@ public function it_can_test_the_R_combinator()

$this::R()('a')($f)('c')
->shouldBeEqualTo(R::with()('a')($f)('c'));

$this::R()('a')($f)('c')
->shouldReturn(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I())) // T
('a')($f)('c')
);
}

public function it_can_test_the_S_combinator()
Expand All @@ -333,6 +438,13 @@ public function it_can_test_the_T_combinator()

$this::T()('a')($f)
->shouldBeEqualTo(T::with()('a')($f));

$this::T()('a')($f)
->shouldReturn(
(Combinators::S()(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()))(Combinators::K()(Combinators::K()))) // C
(Combinators::I()) // I
('a')($f)
);
}

public function it_can_test_the_U_combinator()
Expand All @@ -359,6 +471,13 @@ public function it_can_test_the_U_combinator()

$this::U()($f2)($g)
->shouldBeEqualTo(U::with()($f2)($g));

$this::U()($f2)($g)
->shouldReturn(
Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()(Combinators::S()(Combinators::K())(Combinators::K()))(Combinators::S()(Combinators::K())(Combinators::K()))) // L
(Combinators::S()(Combinators::I())) // O
($f2)($g)
);
}

public function it_can_test_the_V_combinator()
Expand All @@ -371,6 +490,14 @@ public function it_can_test_the_V_combinator()

$this::V()('a')('b')($f)
->shouldBeEqualTo(V::with()('a')('b')($f));

$this::V()('a')('b')($f)
->shouldReturn(
Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()) // B
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))) // C
(Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I())) // T
('a')('b')($f)
);
}

public function it_can_test_the_W_combinator()
Expand All @@ -383,6 +510,16 @@ public function it_can_test_the_W_combinator()

$this::W()($f)('b')
->shouldBeEqualTo(W::with()($f)('b'));

$this::W()($f)('b')
->shouldReturn(
Combinators::S()((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))((Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())))(Combinators::S()))(Combinators::K()(Combinators::K())) // C
(
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())) // B
(Combinators::S()(Combinators::S()(Combinators::K())(Combinators::K()))(Combinators::S()(Combinators::K())(Combinators::K()))) // M
(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K())(Combinators::S()(Combinators::K()(Combinators::S()))(Combinators::K()))(Combinators::S()))(Combinators::K()(Combinators::K()))(Combinators::I()))) // R
)($f)('b')
);
}

public function it_can_test_the_Y_combinator()
Expand Down

0 comments on commit 9a4b71f

Please sign in to comment.