Checkpoint
This commit is contained in:
parent
e3c84e1761
commit
e73e5cbfc8
32 changed files with 1354 additions and 92 deletions
52
tests/prolog/builtins/UnificationTest.kt
Normal file
52
tests/prolog/builtins/UnificationTest.kt
Normal file
|
@ -0,0 +1,52 @@
|
|||
package prolog.builtins
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Integer
|
||||
import prolog.ast.terms.Variable
|
||||
|
||||
class UnificationTest {
|
||||
/**
|
||||
* ?- X == a.
|
||||
* false.
|
||||
*/
|
||||
@Test
|
||||
fun equivalent_variable_and_atom() {
|
||||
val variable = Variable("X")
|
||||
val atom = Atom("a")
|
||||
|
||||
val result = Equivalent(variable, atom).prove(emptyMap())
|
||||
|
||||
assertFalse(result.any(), "Variable and atom should not be equivalent")
|
||||
}
|
||||
|
||||
/**
|
||||
* ?- a == a.
|
||||
* true.
|
||||
*/
|
||||
@Test
|
||||
fun equivalent_atom_and_atom() {
|
||||
val atom1 = Atom("a")
|
||||
val atom2 = Atom("a")
|
||||
|
||||
val result = Equivalent(atom1, atom2).prove(emptyMap())
|
||||
|
||||
assertTrue(result.any(), "Identical atoms should be equivalent")
|
||||
assertEquals(0, result.first().size, "No substitutions should be made")
|
||||
}
|
||||
|
||||
/**
|
||||
* ?- 1 + 2 == 3.
|
||||
* false.
|
||||
*/
|
||||
@Test
|
||||
fun simple_addition_equivalence() {
|
||||
val addition = Add(Integer(1), Integer(2))
|
||||
val solution = Integer(3)
|
||||
|
||||
val result = Equivalent(addition, solution).prove(emptyMap())
|
||||
|
||||
assertFalse(result.any(), "Addition should be equivalent")
|
||||
}
|
||||
}
|
Reference in a new issue