Skip to content

Commit

Permalink
Add some test referred to the built in: atom_chars, atom_length , cha…
Browse files Browse the repository at this point in the history
…r_code, atom_codes and atom_concat.
  • Loading branch information
lanzonisilvia committed Aug 17, 2020
1 parent d2bafa3 commit 1524d19
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,35 @@ class ClassicSolverSystemTesting : SolverFactory, SolverTest {
prototype.testStandardNotEqual()
}

@Test
@Ignore
override fun testAtomChars() {
prototype.testAtomChars()
}

@Test
@Ignore
override fun testAtomLength() {
prototype.testAtomLength()
}

@Test
@Ignore
override fun testCharCode() {
prototype.testCharCode()
}

@Test
@Ignore
override fun testAtomCodes() {
prototype.testAtomCodes()
}

@Test
@Ignore
override fun testAtomConcat() {
prototype.testAtomConcat()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,34 @@ class StreamsSolverSystemTesting : SolverFactory, SolverTest {
prototype.testStandardNotEqual()
}

@Test
@Ignore
override fun testAtomChars() {
prototype.testAtomChars()
}

@Test
@Ignore
override fun testAtomLength() {
prototype.testAtomLength()
}

@Test
@Ignore
override fun testCharCode() {
prototype.testCharCode()
}

@Test
@Ignore
override fun testAtomCodes() {
prototype.testAtomCodes()
}

@Test
@Ignore
override fun testAtomConcat() {
prototype.testAtomConcat()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ interface SolverTest {
/** If-Then-Else rule testing with [ifThenElseStandardExampleNotableGoalToSolution] */
fun testIfThenElseRule()

/** atom_chars/2 test */
fun testAtomChars()

/** atom_length test */
fun testAtomLength()

/** char_code/2 test */
fun testCharCode()

/** atom_codes/2 test */
fun testAtomCodes()

/** atom_concat/3 test */
fun testAtomConcat()


/** Test with [customRangeListGeneratorDatabaseNotableGoalToSolution] */
fun testNumbersRangeListGeneration()
fun testFailure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ import it.unibo.tuprolog.solve.TestingClauseDatabases.simpleCutDatabase
import it.unibo.tuprolog.solve.TestingClauseDatabases.simpleCutDatabaseNotableGoalToSolutions
import it.unibo.tuprolog.solve.TestingClauseDatabases.simpleFactDatabase
import it.unibo.tuprolog.solve.TestingClauseDatabases.simpleFactDatabaseNotableGoalToSolutions
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.charCodeTesting
import it.unibo.tuprolog.solve.TestingPrimitives.timeLibrary
import it.unibo.tuprolog.solve.TestingStandardOperator.equalTesting
import it.unibo.tuprolog.solve.TestingStandardOperator.greaterThanOrEqualTesting
Expand Down Expand Up @@ -932,4 +937,44 @@ internal class SolverTestImpl(private val solverFactory: SolverFactory) : Solver
maxDuration
)
}

override fun testAtomChars() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
atomCharsTesting,
maxDuration
)
}

override fun testAtomLength() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
atomLenghtTesting,
maxDuration
)
}

override fun testCharCode() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
charCodeTesting,
maxDuration
)
}

override fun testAtomCodes() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
atomCodesTesting,
maxDuration
)
}

override fun testAtomConcat() {
assertSolverSolutionsCorrect(
solverFactory.solverWithDefaultBuiltins(),
atomConcatTesting,
maxDuration
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package it.unibo.tuprolog.solve

import it.unibo.tuprolog.dsl.theory.prolog
import kotlin.collections.listOf as ktListOf

object TestingAtomBuiltIn {

/**
* atom_chars Testing
*
* Contained requests:
* ```prolog
* ?- atom_chars(X,[t,e,s,t]).
* ?- atom_chars(test,[t,e,s,t]).
* ?- atom_chars(test,[t,e,s,T]).
* ?- 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_length Testing
*
* Contained requests:
* ```prolog
* ?- atom_length(test,4).
* ?- atom_length(test,X).
* ?- atom_length(X,4).
* ?- atom_length(42,X).
* ?- atom_chars(test,5).
* ```
*/

val atomLenghtTesting 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()}
)
)
}
}

/**
* char_code Testing
*
* Contained requests:
* ```prolog
* ?- char_code(a,X).
* ?- char_code(X,97).
* ?- char_code(X,a).
* ?- 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()}
)
)
}
}

/**
* atom_codes Testing
*
* Contained requests:
* ```prolog
* ?- atom_codes(abc,X).
* ?- atom_codes(test,X).
* ?- atom_codes(test,[116,101,115,116]).
* ?- 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_concat Testing
*
* Contained requests:
* ```prolog
* ?- atom_concat(test,concat,X).
* ?- atom_concat(test,concat,test).
* ?- 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"))}
)
)
}
}


}

0 comments on commit 1524d19

Please sign in to comment.