Fix tests, move weights.txt out of src

This commit is contained in:
Claude Brisson
2023-12-26 13:09:15 +01:00
parent 2629ea9b9d
commit 14a88c1c26
8 changed files with 65 additions and 66 deletions

View File

@@ -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()