Skip to content

Commit

Permalink
Add specs for InputEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-adam committed May 13, 2024
1 parent b86c7e8 commit 6d00c0f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object InputEncoder {
},
)

private def encodeInput(input: List[Natural]): CombinatorBT = input
def encodeInput(input: List[Natural]): CombinatorBT = input
.foldRight(falseCom) { case (n, l) =>
cons(church(n), l)
}
Expand Down
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
}
}

}

0 comments on commit 6d00c0f

Please sign in to comment.