46 lines
No EOL
2.3 KiB
Kotlin
46 lines
No EOL
2.3 KiB
Kotlin
package e2e
|
|
|
|
import interpreter.FileLoader
|
|
import org.junit.jupiter.api.Test
|
|
import org.junit.jupiter.api.Assertions.assertEquals
|
|
import org.junit.jupiter.api.BeforeEach
|
|
import org.junit.jupiter.api.TestInstance
|
|
import org.junit.jupiter.params.ParameterizedTest
|
|
import org.junit.jupiter.params.provider.Arguments
|
|
import org.junit.jupiter.params.provider.MethodSource
|
|
import org.junit.jupiter.params.provider.ValueSource
|
|
import prolog.Program
|
|
import java.io.ByteArrayOutputStream
|
|
import java.io.PrintStream
|
|
|
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
|
class Examples {
|
|
private val loader = FileLoader()
|
|
private lateinit var outStream: ByteArrayOutputStream
|
|
|
|
@BeforeEach
|
|
fun setup() {
|
|
Program.reset()
|
|
|
|
outStream = ByteArrayOutputStream()
|
|
System.setOut(PrintStream(outStream))
|
|
}
|
|
|
|
@ParameterizedTest
|
|
@MethodSource("expectations")
|
|
fun test(inputFile: String, expected: String) {
|
|
loader.load(inputFile)
|
|
assertEquals(expected, outStream.toString())
|
|
}
|
|
|
|
fun expectations() = listOf(
|
|
Arguments.of("examples/basics/arithmetics.pl", "gimli is a level 4 fighter with 35 hitpoints.\nlegolas is a level 5 ranger with 30 hitpoints.\ngandalf is a level 10 wizard with 25 hitpoints.\nfrodo is a level 2 rogue with 20 hitpoints.\nlegolas threw gimli, and gimli took 5 damage.\ngimli is a level 4 fighter with 30 hitpoints.\ngandalf casts aid.\ngimli is a level 4 fighter with 35 hitpoints.\nlegolas leveled up.\nlegolas is a level 6 ranger with 30 hitpoints"),
|
|
Arguments.of("examples/basics/backtracking.pl", "0\ns(0)\ns(s(0))\ns(s(s(0)))\n"),
|
|
Arguments.of("examples/basics/cut.pl", "0\n"),
|
|
Arguments.of("examples/basics/disjunction.pl", "Alice likes Italian food.\nBob likes Italian food.\n"),
|
|
Arguments.of("examples/basics/equality.pl", "X == Y failed\nX = Y succeeded\nX == Y succeeded\nX = Y succeeded\nX == Y succeeded\n"),
|
|
Arguments.of("examples/basics/fraternity.pl", "Citizen robespierre is eligible for the event.\nCitizen danton is eligible for the event.\nCitizen camus is eligible for the event.\n"),
|
|
Arguments.of("examples/basics/unification.pl", "While alice got an A, carol got an A, but bob did not get an A, dave did not get an A, unfortunately.\n"),
|
|
Arguments.of("examples/basics/write.pl", "gpl zegt: dag(wereld)\n"),
|
|
)
|
|
} |