Fix tests, move weights.txt out of src
This commit is contained in:
@@ -176,13 +176,13 @@ class BasicTests: TestBase() {
|
||||
var games = TestAPI.post("/api/tour/$aTournamentID/pair/1", Json.Array("all")).asArray()
|
||||
aTournamentGameID = (games[0] as Json.Object).getInt("id")
|
||||
val possibleResults = setOf(
|
||||
"""[{"id":$aTournamentGameID,"w":$aPlayerID,"b":$anotherPlayerID,"h":0,"r":"?","dd":0}]""",
|
||||
"""[{"id":$aTournamentGameID,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"?","dd":0}]"""
|
||||
"""[{"id":$aTournamentGameID,"t":1,"w":$aPlayerID,"b":$anotherPlayerID,"h":0,"r":"?","dd":0}]""",
|
||||
"""[{"id":$aTournamentGameID,"t":1,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"?","dd":0}]"""
|
||||
)
|
||||
assertTrue(possibleResults.contains(games.toString()), "pairing differs")
|
||||
games = TestAPI.get("/api/tour/$aTournamentID/res/1").asObject().getArray("games")!!
|
||||
games = TestAPI.get("/api/tour/$aTournamentID/res/1").asArray()!!
|
||||
assertTrue(possibleResults.contains(games.toString()), "results differs")
|
||||
val empty = TestAPI.get("/api/tour/$aTournamentID/pair/1").asArray()
|
||||
val empty = TestAPI.get("/api/tour/$aTournamentID/pair/1").asObject().getArray("pairables")
|
||||
assertEquals("[]", empty.toString(), "no more pairables for round 1")
|
||||
}
|
||||
|
||||
@@ -192,8 +192,8 @@ class BasicTests: TestBase() {
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
val games = TestAPI.get("/api/tour/$aTournamentID/res/1")
|
||||
val possibleResults = setOf(
|
||||
"""[{"id":$aTournamentGameID,"w":$aPlayerID,"b":$anotherPlayerID,"h":0,"r":"b","dd":0}]""",
|
||||
"""[{"id":$aTournamentGameID,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"b","dd":0}]"""
|
||||
"""[{"id":$aTournamentGameID,"t":1,"w":$aPlayerID,"b":$anotherPlayerID,"h":0,"r":"b","dd":0}]""",
|
||||
"""[{"id":$aTournamentGameID,"t":1,"w":$anotherPlayerID,"b":$aPlayerID,"h":0,"r":"b","dd":0}]"""
|
||||
)
|
||||
assertTrue(possibleResults.contains(games.toString()), "results differ")
|
||||
}
|
||||
|
@@ -4,22 +4,26 @@ import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.model.Game
|
||||
import org.jeudego.pairgoth.model.ID
|
||||
import org.jeudego.pairgoth.model.fromJson
|
||||
import org.jeudego.pairgoth.pairing.solver.BaseSolver
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.MethodOrderer.MethodName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.TestMethodOrder
|
||||
import java.io.File
|
||||
import java.io.FileWriter
|
||||
import java.io.PrintWriter
|
||||
import java.nio.charset.StandardCharsets
|
||||
import kotlin.math.abs
|
||||
import kotlin.reflect.typeOf
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@TestMethodOrder(MethodName::class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@Disabled("pairings differ")
|
||||
class PairingTests: TestBase() {
|
||||
|
||||
fun compare_weights(file1:String, file2:String):Boolean {
|
||||
|
||||
fun compare_weights(file1: File, file2: File):Boolean {
|
||||
BaseSolver.weightsLogger!!.flush()
|
||||
// Maps to store name pairs and costs
|
||||
val map1 = HashMap<Pair<String, String>, List<Double>>()
|
||||
val map2 = HashMap<Pair<String, String>, List<Double>>()
|
||||
@@ -28,7 +32,7 @@ class PairingTests: TestBase() {
|
||||
for (file in listOf(file1, file2)) {
|
||||
|
||||
// Read lines
|
||||
val lines = getTestFile(file).readLines()
|
||||
val lines = file.readLines()
|
||||
|
||||
// Store headers
|
||||
val header1 = lines[0]
|
||||
@@ -97,9 +101,13 @@ class PairingTests: TestBase() {
|
||||
val gamesPair = mutableSetOf<Pair<ID,ID>>()
|
||||
val openGothaPair = mutableSetOf<Pair<ID,ID>>()
|
||||
for (i in 0 until opengotha.size) {
|
||||
val tmp = Game.fromJson(games.getJson(i)!!.asObject())
|
||||
val tmp = Game.fromJson(games.getJson(i)!!.asObject().let {
|
||||
Json.MutableObject(it).set("t", 0) // hack to fill the table to make fromJson() happy
|
||||
})
|
||||
gamesPair.add(Pair(tmp.white, tmp.black))
|
||||
val tmpOG = Game.fromJson(opengotha.getJson(i)!!.asObject())
|
||||
val tmpOG = Game.fromJson(opengotha.getJson(i)!!.asObject().let {
|
||||
Json.MutableObject(it).set("t", 0) // hack to fill the table to make fromJson() happy
|
||||
})
|
||||
openGothaPair.add(Pair(tmpOG.white, tmpOG.black))
|
||||
}
|
||||
return gamesPair==openGothaPair
|
||||
@@ -173,10 +181,10 @@ class PairingTests: TestBase() {
|
||||
var firstGameID: Int
|
||||
|
||||
for (round in 1..7) {
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
logger.info("games for round $round: {}", games.toString())
|
||||
|
||||
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weights_R$round.txt"), "Not matching opengotha weights for round $round")
|
||||
assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/simpleswiss_weights_R$round.txt")), "Not matching opengotha weights for round $round")
|
||||
assertTrue(compare_games(games, Json.parse(pairings[round - 1])!!.asArray()),"pairings for round $round differ")
|
||||
logger.info("Pairings for round $round match OpenGotha")
|
||||
|
||||
@@ -263,7 +271,7 @@ class PairingTests: TestBase() {
|
||||
|
||||
for (round in 1..7) {
|
||||
//games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array(playersList.filter{it != byePlayerList[round-1]})).asArray()
|
||||
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
if (round in forcedPairingList){
|
||||
// games must be created and then modified by PUT
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
@@ -280,7 +288,7 @@ class PairingTests: TestBase() {
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
logger.info("games for round $round: {}", games.toString())
|
||||
|
||||
assertTrue(compare_weights("weights.txt", "opengotha/notsosimpleswiss_weights_R$round.txt"), "Not matching opengotha weights for round $round")
|
||||
assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/notsosimpleswiss_weights_R$round.txt")), "Not matching opengotha weights for round $round")
|
||||
assertTrue(compare_games(games, Json.parse(pairings[round - 1])!!.asArray()),"pairings for round $round differ")
|
||||
logger.info("Pairings for round $round match OpenGotha")
|
||||
}
|
||||
@@ -349,9 +357,10 @@ class PairingTests: TestBase() {
|
||||
var game: Json
|
||||
|
||||
for (round in 1..5) {
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
// games must be created and then modified by PUT
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
assertTrue(compare_weights("weights.txt", "opengotha/simplemm/simplemm_weights_R$round.txt"), "Not matching opengotha weights for round $round")
|
||||
assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/simplemm/simplemm_weights_R$round.txt")), "Not matching opengotha weights for round $round")
|
||||
logger.info("Weights for round $round match OpenGotha")
|
||||
|
||||
forcedGames = Json.parse(pairings[round-1])!!.asArray()
|
||||
|
@@ -21,20 +21,20 @@ class TeamTest {
|
||||
resp = TestAPI.post("/api/tour/$aTeamTournamentID/part", anotherPlayer).asObject()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
val anotherTeamPlayerID = resp.getInt("id") ?: fail("id cannot be null")
|
||||
var arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asArray()
|
||||
var arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asObject().getArray("pairables")
|
||||
assertEquals("[]", arr.toString(), "expecting an empty array")
|
||||
resp = TestAPI.post("/api/tour/$aTeamTournamentID/team", Json.parse("""{ "name":"The Buffallos", "players":[$aTeamPlayerID, $anotherTeamPlayerID] }""")?.asObject() ?: fail("no null allowed here")).asObject()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
val aTeamID = resp.getInt("id") ?: error("no null allowed here")
|
||||
resp = TestAPI.get("/api/tour/$aTeamTournamentID/team/$aTeamID").asObject()
|
||||
assertEquals("""{"id":$aTeamID,"name":"The Buffallos","players":[$aTeamPlayerID,$anotherTeamPlayerID]}""", resp.toString(), "expecting team description")
|
||||
arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asArray()
|
||||
arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asObject().getArray("pairables")
|
||||
assertEquals("[$aTeamID]", arr.toString(), "expecting a singleton array")
|
||||
// nothing stops us in reusing players in different teams, at least for now...
|
||||
resp = TestAPI.post("/api/tour/$aTeamTournamentID/team", Json.parse("""{ "name":"The Billies", "players":[$aTeamPlayerID, $anotherTeamPlayerID] }""")?.asObject() ?: fail("no null here")).asObject()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
val anotherTeamID = resp.getInt("id") ?: fail("no null here")
|
||||
arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asArray()
|
||||
arr = TestAPI.get("/api/tour/$aTeamTournamentID/pair/1").asObject().getArray("pairables")
|
||||
assertEquals("[$aTeamID,$anotherTeamID]", arr.toString(), "expecting two pairables")
|
||||
arr = TestAPI.post("/api/tour/$aTeamTournamentID/pair/1", Json.parse("""["all"]""")).asArray()
|
||||
assertTrue(resp.getBoolean("success") == true, "expecting success")
|
||||
|
@@ -82,6 +82,8 @@ object TestAPI {
|
||||
|
||||
// Get a list of resources
|
||||
|
||||
fun getTestResources(path: String) = File("${System.getProperty("user.dir")}/src/test/resources/$path").listFiles()
|
||||
fun getTestResources(path: String) = getTestFile(path).listFiles()
|
||||
|
||||
fun getTestFile(path: String) = File("${System.getProperty("user.dir")}/src/test/resources/$path")
|
||||
fun getTestFile(path: String) = File("${System.getProperty("user.dir")}/src/test/resources/$path")
|
||||
|
||||
fun getOutputFile(path: String) = File("${System.getProperty("test.build.dir")}/$path")
|
Reference in New Issue
Block a user