Skip to content

Commit

Permalink
fix Lanzoni's tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Aug 31, 2020
1 parent 343057b commit 61c61f8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import it.unibo.tuprolog.solve.PrologStandardExampleTheories.prologStandardExamp
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.atomCharsTesting
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.atomCodesTesting
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.atomConcatTesting
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.atomLenghtTesting
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.atomLengthTesting
import it.unibo.tuprolog.solve.TestingAtomBuiltIn.charCodeTesting
import it.unibo.tuprolog.solve.TestingClauseTheories.allPrologTestingTheoriesToRespectiveGoalsAndSolutions
import it.unibo.tuprolog.solve.TestingClauseTheories.callTestingGoalsToSolutions
Expand All @@ -47,12 +47,12 @@ import it.unibo.tuprolog.solve.TestingClauseTheories.simpleCutTheory
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleCutTheoryNotableGoalToSolutions
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheory
import it.unibo.tuprolog.solve.TestingClauseTheories.simpleFactTheoryNotableGoalToSolutions
import it.unibo.tuprolog.solve.TestingStandardOperator.equalTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.greaterThanOrEqualTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.greaterThanTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.lowerThanOrEqualTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.lowerThanTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.notEqualTesting
import it.unibo.tuprolog.solve.TestingTermOperators.equalTesting
import it.unibo.tuprolog.solve.TestingTermOperators.greaterThanOrEqualTesting
import it.unibo.tuprolog.solve.TestingTermOperators.greaterThanTesting
import it.unibo.tuprolog.solve.TestingTermOperators.lowerThanOrEqualTesting
import it.unibo.tuprolog.solve.TestingTermOperators.lowerThanTesting
import it.unibo.tuprolog.solve.TestingTermOperators.notEqualTesting
import it.unibo.tuprolog.solve.TimeRelatedTheories.lessThan500MsGoalToSolution
import it.unibo.tuprolog.solve.TimeRelatedTheories.slightlyMoreThan500MsGoalToSolution
import it.unibo.tuprolog.solve.TimeRelatedTheories.slightlyMoreThan600MsGoalToSolution
Expand Down Expand Up @@ -1325,7 +1325,7 @@ internal class TestSolverImpl(private val solverFactory: SolverFactory) : TestSo
override fun testAtomLength() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
atomLenghtTesting,
atomLengthTesting,
mediumDuration
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ object TestingAtomBuiltIn {
* ?- atom_chars(test1,[t,e,s,T]).
* ```
*/

val atomCharsTesting by lazy {
prolog {
ktListOf(
"atom_chars"("X", listOf("t", "e", "s", "t")).hasSolutions({ yes("X" to "test") }
),
"atom_chars"(atomOf("test"), listOf("t", "e", "s", "t")).hasSolutions({ yes() }
),
"atom_chars"(atomOf("test"), listOf("t", "e", "s", "T")).hasSolutions({ yes("T" to "t") }
),
"atom_chars"(atomOf("test1"), listOf("t", "e", "s", "t")).hasSolutions({ no() }
)
"atom_chars"("X", listOf("t", "e", "s", "t")).hasSolutions({ yes("X" to "test") }),
"atom_chars"("test", listOf("t", "e", "s", "t")).hasSolutions({ yes() }),
"atom_chars"("test", listOf("t", "e", "s", "T")).hasSolutions({ yes("T" to "t") }),
"atom_chars"("test1", listOf("t", "e", "s", "T")).hasSolutions({ no() })
)
}
}
Expand All @@ -44,20 +39,14 @@ object TestingAtomBuiltIn {
* ?- atom_chars(test,5).
* ```
*/

val atomLenghtTesting by lazy {
val atomLengthTesting by lazy {
prolog {
ktListOf(
"atom_length"(atomOf("test"), intOf(4)).hasSolutions({ yes() }
),
"atom_length"(atomOf("test"), "X").hasSolutions({ yes("X" to 4) }
),
"atom_length"("X", intOf(4)).hasSolutions({ no() }
),
"atom_length"(atomOf("42"), "X").hasSolutions({ yes("X" to 2) }
),
"atom_length"(atomOf("test"), intOf(5)).hasSolutions({ no() }
)
"atom_length"("test", intOf(4)).hasSolutions({ yes() }),
"atom_length"("test", "X").hasSolutions({ yes("X" to 4) }),
"atom_length"("X", intOf(4)).hasSolutions({ no() }), // TODO should throw instantiation_error
"atom_length"(intOf(42), "X").hasSolutions({ yes("X" to 2) }),
"atom_length"("test", intOf(5)).hasSolutions({ no() })
)
}
}
Expand All @@ -73,19 +62,13 @@ object TestingAtomBuiltIn {
* ?- char_code(g,103).
* ```
*/


val charCodeTesting by lazy {
prolog {
ktListOf(
"char_code"("a", "X").hasSolutions({ yes("X" to 97) }
),
"char_code"("X", intOf(97)).hasSolutions({ yes("X" to "a") }
),
"char_code"("X", "a").hasSolutions({ no() }
),
"char_code"("g", intOf(103)).hasSolutions({ yes() }
)
"char_code"("a", "X").hasSolutions({ yes("X" to 97) }),
"char_code"("X", intOf(97)).hasSolutions({ yes("X" to "a") }),
"char_code"("X", "a").hasSolutions({ no() }), // TODO should throw type_error
"char_code"("g", intOf(103)).hasSolutions({ yes() })
)
}
}
Expand All @@ -101,18 +84,17 @@ object TestingAtomBuiltIn {
* ?- atom_codes(test,[112,101,115,116]).
* ```
*/

val atomCodesTesting by lazy {
prolog {
ktListOf(
"atom_codes"(atomOf("abc"), "X").hasSolutions({ yes("X" to listOf("97,98,99")) }
),
"atom_codes"(atomOf("test"), "X").hasSolutions({ yes("X" to listOf("116,101,115,116")) }
),
"atom_codes"(atomOf("test"), listOf("116,101,115,116")).hasSolutions({ yes() }
),
"atom_codes"(atomOf("test"), listOf("112,101,115,116")).hasSolutions({ no() }
)
"atom_codes"("abc", "X")
.hasSolutions({ yes("X" to listOf(97, 98, 99)) }),
"atom_codes"("test", "X")
.hasSolutions({ yes("X" to listOf(116, 101, 115, 116)) }),
"atom_codes"("test", listOf(116, 101, 115, 116))
.hasSolutions({ yes() }),
"atom_codes"("test", listOf(112, 101, 115, 116))
.hasSolutions({ no() })
)
}
}
Expand All @@ -127,23 +109,16 @@ object TestingAtomBuiltIn {
* ?- atom_concat(test,X,testTest).
* ```
*/

val atomConcatTesting by lazy {
prolog {
ktListOf(
"atom_concat"(atomOf("test"), atomOf("concat"), "X").hasSolutions({ yes("X" to atomOf("testconcat")) }
),
"atom_concat"(atomOf("test"), atomOf("concat"), atomOf("test")).hasSolutions({ no() }
),
"atom_concat"(
atomOf("test"),
atomOf("X"),
atomOf("testTest")
).hasSolutions({ yes("X" to atomOf("Test")) }
)
"atom_concat"(atomOf("test"), atomOf("concat"), "X")
.hasSolutions({ yes("X" to atomOf("testconcat")) }),
"atom_concat"(atomOf("test"), atomOf("concat"), atomOf("test"))
.hasSolutions({ no() }),
"atom_concat"("test", "X", "testTest")
.hasSolutions({ yes("X" to atomOf("Test")) })
)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package it.unibo.tuprolog.solve
import it.unibo.tuprolog.dsl.theory.prolog
import kotlin.collections.listOf as ktListOf

object TestingStandardOperator {
object TestingTermOperators {

/**
* Standard operator greater than
Expand All @@ -16,14 +16,13 @@ object TestingStandardOperator {
* ?- @>(stringTest,1).
* ```
*/

val greaterThanTesting by lazy {
prolog {
ktListOf(
"@>"(1,1.0).hasSolutions({yes()}),
"@>"(1.0,1).hasSolutions({no()}),
"@>"("stringTestA","stringTestZ").hasSolutions({no()}),
"@>"("stringTest",1).hasSolutions({yes()})
"@>"(intOf(1), realOf(1.0)).hasSolutions({ yes() }),
"@>"(realOf(1.0), intOf(1)).hasSolutions({ no() }),
"@>"("stringTestA", "stringTestZ").hasSolutions({ no() }),
"@>"("stringTest", intOf(1)).hasSolutions({ yes() })
)
}
}
Expand All @@ -39,15 +38,13 @@ object TestingStandardOperator {
* ?- @>=(stringTest,1).
* ```
*/


val greaterThanOrEqualTesting by lazy {
prolog {
ktListOf(
"@>="(1,1).hasSolutions({yes()}),
"@>="("stringTest","stringTest").hasSolutions({yes()}),
"@>="("stringTest","stringTest1").hasSolutions({no()}),
"@>="("stringTest",1).hasSolutions({yes()}
"@>="(intOf(1), intOf(1)).hasSolutions({ yes() }),
"@>="("stringTest", "stringTest").hasSolutions({ yes() }),
"@>="("stringTest", "stringTest1").hasSolutions({ no() }),
"@>="("stringTest", intOf(1)).hasSolutions({ yes() }
)
)
}
Expand All @@ -63,13 +60,12 @@ object TestingStandardOperator {
* ?- =@=(stringTest,1.0).
* ```
*/

val equalTesting by lazy {
prolog {
ktListOf(
"=@="(1.0,1.0).hasSolutions({yes()}),
"=@="("stringTest","stringTest").hasSolutions({yes()}),
"=@="("stringTest",1.0).hasSolutions({no()})
"=@="(realOf(1.0), realOf(1.0)).hasSolutions({ yes() }),
"=@="("stringTest", "stringTest").hasSolutions({ yes() }),
"=@="("stringTest", realOf(1.0)).hasSolutions({ no() })
)
}
}
Expand All @@ -89,10 +85,10 @@ object TestingStandardOperator {
val lowerThanTesting by lazy {
prolog {
ktListOf(
"@<"(1.0,1).hasSolutions({yes()}),
"@<"(1,1.0).hasSolutions({no()}),
"@<"("stringTestA","stringTestZ").hasSolutions({yes()}),
"@<"(1,"stringTest").hasSolutions({yes()})
"@<"(realOf(1.0), intOf(1)).hasSolutions({ yes() }),
"@<"(intOf(1), realOf(1.0)).hasSolutions({ no() }),
"@<"("stringTestA", "stringTestZ").hasSolutions({ yes() }),
"@<"(intOf(1), "stringTest").hasSolutions({ yes() })
)
}
}
Expand All @@ -107,16 +103,12 @@ object TestingStandardOperator {
* ?- @<=(stringTest,stringTest).
* ```
*/

val lowerThanOrEqualTesting by lazy {
prolog {
ktListOf(
"@<="(1,1.0).hasSolutions({no()}
),
"@<="(1.0,1.0).hasSolutions({yes()}
),
"@<="("stringTest","stringTest").hasSolutions({yes()}
)
"@<="(intOf(1), 1.0).hasSolutions({ no() }),
"@<="(1.0, 1.0).hasSolutions({ yes() }),
"@<="("stringTest", "stringTest").hasSolutions({ yes() })
)
}
}
Expand All @@ -131,14 +123,12 @@ object TestingStandardOperator {
* ?- \=@=(stringTest,1.0).
* ```
*/


val notEqualTesting by lazy{
val notEqualTesting by lazy {
prolog {
ktListOf(
"\\=@="(1.0,1.0).hasSolutions({no()}),
"\\=@="("stringTest","stringTest").hasSolutions({no()}),
"\\=@="("stringTest",1.0).hasSolutions({yes()})
"\\=@="(1.0, 1.0).hasSolutions({ no() }),
"\\=@="("stringTest", "stringTest").hasSolutions({ no() }),
"\\=@="("stringTest", 1.0).hasSolutions({ yes() })
)
}
}
Expand Down

0 comments on commit 61c61f8

Please sign in to comment.