Checkpoint
This commit is contained in:
parent
973365e2ec
commit
3724ac72f9
13 changed files with 659 additions and 29 deletions
60
tests/prolog/builtins/ListOperatorsTests.kt
Normal file
60
tests/prolog/builtins/ListOperatorsTests.kt
Normal file
|
@ -0,0 +1,60 @@
|
|||
package prolog.builtins
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.ast.lists.List.Cons
|
||||
import prolog.ast.lists.List.Empty
|
||||
import prolog.ast.terms.Atom
|
||||
|
||||
class ListOperatorsTests {
|
||||
@Test
|
||||
fun `size empty list is 0`() {
|
||||
assertEquals(0, Empty.size.value, "Expected size of empty list to be 0")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `size of singleton is 1`() {
|
||||
val list = Cons(Atom("a"), Empty)
|
||||
|
||||
assertEquals(1, list.size.value, "Expected size of singleton list to be 1")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `size of list with five elements is 5`() {
|
||||
val list = Cons(Atom("a"), Cons(Atom("b"), Cons(Atom("c"), Cons(Atom("d"), Cons(Atom("e"), Empty)))))
|
||||
|
||||
assertEquals(5, list.size.value, "Expected size of list with five elements to be 5")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `member(a, list of a)`() {
|
||||
val atom = Atom("a")
|
||||
val list = Cons(atom, Empty)
|
||||
|
||||
val member = Member(atom, list)
|
||||
|
||||
val result = member.satisfy(emptyMap()).toList()
|
||||
|
||||
assertEquals(1, result.size, "Expected one solution")
|
||||
assertTrue(result[0].isSuccess, "Expected success")
|
||||
assertTrue(result[0].getOrNull()!!.isEmpty(), "Expected empty substitution map")
|
||||
}
|
||||
|
||||
@Disabled("Not required functionality")
|
||||
@Test
|
||||
fun `member with variable in list`() {
|
||||
val atom = Atom("a")
|
||||
val variable = Atom("X")
|
||||
val list = Cons(variable, Empty)
|
||||
|
||||
val member = Member(atom, list)
|
||||
|
||||
val result = member.satisfy(emptyMap()).toList()
|
||||
|
||||
assertEquals(1, result.size, "Expected one solution")
|
||||
assertTrue(result[0].isSuccess, "Expected success")
|
||||
assertEquals(atom, result[0].getOrNull()!![variable], "Expected variable to be unified with atom")
|
||||
}
|
||||
}
|
Reference in a new issue