Checkpoint
This commit is contained in:
parent
973365e2ec
commit
3724ac72f9
13 changed files with 659 additions and 29 deletions
|
@ -10,13 +10,16 @@ import prolog.ast.terms.Variable
|
|||
import prolog.builtins.Add
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Nested
|
||||
import prolog.ast.lists.List
|
||||
import prolog.ast.lists.List.Empty
|
||||
import prolog.ast.lists.List.Cons
|
||||
|
||||
/*
|
||||
* Based on: https://en.wikipedia.org/wiki/Unification_%28computer_science%29#Examples_of_syntactic_unification_of_first-order_terms
|
||||
*/
|
||||
class UnificationTests {
|
||||
@Nested
|
||||
class `unify` {
|
||||
class `unify logic` {
|
||||
@Test
|
||||
fun identical_atoms_unify() {
|
||||
val atom1 = Atom("a")
|
||||
|
@ -330,7 +333,7 @@ class UnificationTests {
|
|||
}
|
||||
|
||||
@Nested
|
||||
class `applySubstitution` {
|
||||
class `applySubstitution logic` {
|
||||
@Test
|
||||
fun `apply substitution without sub`() {
|
||||
val term = Variable("X")
|
||||
|
@ -367,4 +370,67 @@ class UnificationTests {
|
|||
assertEquals(Integer(35), result)
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class `equivalent logic` {
|
||||
@Test
|
||||
fun `empty lists are equivalent`() {
|
||||
val eq = equivalent(Empty, Empty, emptyMap())
|
||||
assertTrue(eq, "Empty lists should be equivalent")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `singletons are equivalent`() {
|
||||
val atom = Atom("a")
|
||||
val list1 = Cons(atom, Empty)
|
||||
val list2 = Cons(atom, Empty)
|
||||
|
||||
val eq = equivalent(list1, list2, emptyMap())
|
||||
|
||||
assertTrue(eq, "Singleton lists should be equivalent")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `singleton and empty list are not equivalent`() {
|
||||
val atom = Atom("a")
|
||||
val list1 = Cons(atom, Empty)
|
||||
val list2 = Empty
|
||||
|
||||
var eq = equivalent(list1, list2, emptyMap())
|
||||
assertFalse(eq, "Singleton and empty lists should not be equivalent")
|
||||
|
||||
eq = equivalent(list2, list1, emptyMap())
|
||||
assertFalse(eq, "Empty and singleton lists should not be equivalent")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `identical lists are equivalent`() {
|
||||
val list1 = Cons(Atom("a"), Cons(Atom("b"), Empty))
|
||||
val list2 = Cons(Atom("a"), Cons(Atom("b"), Empty))
|
||||
|
||||
var eq = equivalent(list1, list2, emptyMap())
|
||||
assertTrue(eq, "Identical lists should be equivalent")
|
||||
|
||||
eq = equivalent(list2, list1, emptyMap())
|
||||
assertTrue(eq, "Identical lists should be equivalent")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `identical nested lists are equivalent`() {
|
||||
val list1 = Cons(Atom("foo"), Cons(Atom("bar"), Cons(Cons(Atom("baz"), Cons(Atom("bar"), Empty)), Empty)))
|
||||
val list2 = Cons(Atom("foo"), Cons(Atom("bar"), Cons(Cons(Atom("baz"), Cons(Atom("bar"), Empty)), Empty)))
|
||||
|
||||
var eq = equivalent(list1, list2, emptyMap())
|
||||
assertTrue(eq, "Identical nested lists should be equivalent")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `lists with different nests are not equivalent`() {
|
||||
val list1 = Cons(Atom("foo"), Cons(Atom("bar"), Cons(Cons(Atom("bar"), Cons(Atom("baz"), Empty)), Empty)))
|
||||
val list2 = Cons(Atom("foo"), Cons(Atom("bar"), Cons(Cons(Atom("baz"), Cons(Atom("bar"), Empty)), Empty)))
|
||||
|
||||
var eq = equivalent(list1, list2, emptyMap())
|
||||
assertFalse(eq, "Lists with different nests should not be equivalent")
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue