refactor: Rework
This commit is contained in:
parent
ac55ed4c64
commit
6469dd6ced
34 changed files with 593 additions and 552 deletions
|
@ -3,20 +3,19 @@ package prolog.builtins
|
|||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.terms.Atom
|
||||
import prolog.ast.terms.Structure
|
||||
import prolog.ast.terms.Variable
|
||||
import prolog.logic.compound
|
||||
import prolog.logic.nonvariable
|
||||
import prolog.logic.variable
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class VerificationTest {
|
||||
@Test
|
||||
fun unbound_variable_is_var() {
|
||||
val variable = Variable("X")
|
||||
assertTrue(variable(variable))
|
||||
assertTrue(variable.alias().isEmpty)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -26,10 +25,8 @@ class VerificationTest {
|
|||
assertTrue(variable(variable))
|
||||
|
||||
val atom = Atom("a")
|
||||
variable.bind(atom)
|
||||
|
||||
assertFalse(variable(variable))
|
||||
assertEquals(atom, variable.alias().get())
|
||||
assertFalse(variable(variable, mapOf(variable to atom)))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,10 +36,8 @@ class VerificationTest {
|
|||
assertTrue(variable(variable))
|
||||
|
||||
val structure = Structure(Atom("a"), listOf(Atom("b")))
|
||||
variable.bind(structure)
|
||||
|
||||
assertFalse(variable(variable))
|
||||
assertEquals(structure, variable.alias().get())
|
||||
assertFalse(variable(variable, mapOf(variable to structure)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,8 +47,7 @@ class VerificationTest {
|
|||
@Test
|
||||
fun variable_bound_to_itself_is_var() {
|
||||
val variable = Variable("X")
|
||||
variable.bind(variable)
|
||||
assertTrue(variable(variable))
|
||||
assertTrue(variable(variable, mapOf(variable to variable)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,9 +58,7 @@ class VerificationTest {
|
|||
fun variable_bound_to_another_variable_is_var() {
|
||||
val variable1 = Variable("X")
|
||||
val variable2 = Variable("Y")
|
||||
variable1.bind(variable2)
|
||||
assertTrue(variable(variable1))
|
||||
assertEquals(variable2, variable1.alias().get())
|
||||
assertTrue(variable(variable1, mapOf(variable1 to variable2)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,9 +69,11 @@ class VerificationTest {
|
|||
fun variable_bound_to_bound_variable_is_not_var() {
|
||||
val variable1 = Variable("X")
|
||||
val variable2 = Variable("Y")
|
||||
variable2.bind(Atom("a"))
|
||||
variable1.bind(variable2)
|
||||
assertFalse(variable(variable1))
|
||||
val map: Substitutions = mapOf(
|
||||
variable1 to variable2,
|
||||
variable2 to Atom("a")
|
||||
)
|
||||
assertFalse(variable(variable1, map))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,10 +111,8 @@ class VerificationTest {
|
|||
assertFalse(nonvariable(variable))
|
||||
|
||||
val atom = Atom("a")
|
||||
variable.bind(atom)
|
||||
|
||||
assertTrue(nonvariable(variable))
|
||||
assertEquals(atom, variable.alias().get())
|
||||
assertTrue(nonvariable(variable, mapOf(variable to atom)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,10 +126,8 @@ class VerificationTest {
|
|||
assertFalse(nonvariable(variable))
|
||||
|
||||
val structure = Structure(Atom("a"), listOf(Atom("b")))
|
||||
variable.bind(structure)
|
||||
|
||||
assertTrue(nonvariable(variable))
|
||||
assertEquals(structure, variable.alias().get())
|
||||
assertTrue(nonvariable(variable, mapOf(variable to structure)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,8 +137,7 @@ class VerificationTest {
|
|||
@Test
|
||||
fun variable_bound_to_itself_is_not_nonvar() {
|
||||
val variable = Variable("X")
|
||||
variable.bind(variable)
|
||||
assertFalse(nonvariable(variable))
|
||||
assertFalse(nonvariable(variable, mapOf(variable to variable)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,8 +148,7 @@ class VerificationTest {
|
|||
fun variable_bound_to_another_variable_is_not_nonvar() {
|
||||
val variable1 = Variable("X")
|
||||
val variable2 = Variable("Y")
|
||||
variable1.bind(variable2)
|
||||
assertFalse(nonvariable(variable1))
|
||||
assertFalse(nonvariable(variable1, mapOf(variable1 to variable2)))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -195,8 +183,7 @@ class VerificationTest {
|
|||
fun bound_variable_to_atom_is_not_compound() {
|
||||
val variable = Variable("X")
|
||||
val atom = Atom("a")
|
||||
variable.bind(atom)
|
||||
assertFalse(compound(variable))
|
||||
assertFalse(compound(variable, mapOf(variable to atom)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,8 +194,7 @@ class VerificationTest {
|
|||
fun bound_variable_to_compound_term_is_compound() {
|
||||
val variable = Variable("X")
|
||||
val structure = Structure(Atom("a"), listOf(Atom("b")))
|
||||
variable.bind(structure)
|
||||
assertTrue(compound(variable))
|
||||
assertTrue(compound(variable, mapOf(variable to structure)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,13 +207,12 @@ class VerificationTest {
|
|||
val variable2 = Variable("Y")
|
||||
val structure = Structure(Atom("a"), listOf(Atom("b")))
|
||||
|
||||
variable2.bind(structure)
|
||||
variable1.bind(variable2)
|
||||
val subs: Substitutions = mapOf(
|
||||
variable1 to variable2,
|
||||
variable2 to structure
|
||||
)
|
||||
|
||||
assertTrue(compound(variable1))
|
||||
|
||||
assertEquals(structure, variable2.alias().get())
|
||||
assertEquals(variable2, variable1.alias().get())
|
||||
assertTrue(compound(variable1, subs))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Reference in a new issue