-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b86c7e8
commit 6d00c0f
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ator-core/src/test/scala/pl/writeonly/catculator/core/adt/calculus/InputEncoderSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package pl.writeonly.catculator.core.adt.calculus | ||
|
||
import pl.writeonly.catculator.core.adt.calculus.Combinator.* | ||
import pl.writeonly.catculator.core.adt.calculus.Constants.* | ||
import pl.writeonly.catculator.core.adt.tree.BinaryTree.* | ||
|
||
import pl.writeonly.catculator.core.TableDrivenPropertySpec | ||
|
||
import spire.math.Natural | ||
|
||
class InputEncoderSpec extends TableDrivenPropertySpec { | ||
|
||
private val oneCom = Node(Leaf(S), Node(Node(Leaf(S), Node(Node(Leaf(K), Leaf(S)), Leaf(K))), Node(Leaf(K), Leaf(I)))) | ||
private var zeroListCom = Node(Leaf(S), Node(Node(Leaf(S), Node(Leaf(I), Node(Leaf(K), Node(Leaf(K), Leaf(I))))), Node(Leaf(K), Node(Leaf(K), Leaf(I))))) | ||
|
||
it should "church number" in { | ||
|
||
val combinators = Table( | ||
("input", "ast"), | ||
(Natural.zero, falseCom), | ||
(Natural.one, oneCom), | ||
) | ||
forAll(combinators) { (input, code) => | ||
InputEncoder.church(input) shouldBe code | ||
} | ||
} | ||
|
||
it should "encode input List" in { | ||
val combinators = Table( | ||
("input", "ast"), | ||
(List(Natural.zero), zeroListCom), | ||
) | ||
forAll(combinators) { (input, code) => | ||
InputEncoder.encodeInput(input) shouldBe code | ||
} | ||
} | ||
|
||
it should "encode input String" in { | ||
val combinators = Table( | ||
("input", "ast"), | ||
("", falseCom), | ||
) | ||
forAll(combinators) { (input, code) => | ||
InputEncoder.readInput(input) shouldBe code | ||
} | ||
} | ||
|
||
} |