Add test for unsorted pairings (not matching default table number with OpenGotha)

This commit is contained in:
Quentin Rendu
2023-10-21 11:42:33 +02:00
parent 31f37a63ff
commit c4f9281faf
2 changed files with 48 additions and 23 deletions

View File

@@ -125,10 +125,6 @@ sealed class Solver(
abstract val mainLimits: Pair<Double, Double>
// SOS and variants will be computed based on this score
fun pair(): List<Game> {
if (round>1){
println("Solver.kt Games played before round "+round.toString()+" :")
println(history[0])
}
weightLogs.clear()
// check that at this stage, we have an even number of pairables
if (pairables.size % 2 != 0) throw Error("expecting an even number of pairables")
@@ -173,7 +169,7 @@ sealed class Solver(
val graph = builder.build()
val matching = KolmogorovWeightedPerfectMatching(graph, ObjectiveSense.MAXIMIZE)
val solution = matching.matching
val sorted = solution.map{
listOf(graph.getEdgeSource(it), graph.getEdgeTarget(it))
}.sortedWith(compareBy({ min(it[0].place, it[1].place) }))

View File

@@ -2,7 +2,9 @@ package org.jeudego.pairgoth.test
import com.republicate.kson.Json
import com.republicate.kson.toJsonObject
import org.jeudego.pairgoth.model.Game
import org.jeudego.pairgoth.model.ID
import org.jeudego.pairgoth.model.fromJson
import org.junit.jupiter.api.MethodOrderer.MethodName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
@@ -278,9 +280,17 @@ class BasicTests: TestBase() {
return identical
}
fun compare_games(games:String, pairings:String): Boolean{
println("Compare games ")
return false
fun compare_games(games:Json.Array, opengotha:Json.Array): Boolean{
if (games.size != opengotha.size) return false
val gamesPair = mutableSetOf<Pair<ID,ID>>()
val openGothaPair = mutableSetOf<Pair<ID,ID>>()
for (i in 0 until games.size) {
val tmp = Game.fromJson(games.getJson(i)!!.asObject())
gamesPair.add(Pair(tmp.white, tmp.black))
val tmpOG = Game.fromJson(opengotha.getJson(i)!!.asObject())
openGothaPair.add(Pair(tmpOG.white, tmpOG.black))
}
return gamesPair==openGothaPair
}
fun compare_string(string1:String, string2:String): String{
@@ -315,6 +325,13 @@ class BasicTests: TestBase() {
//logger.info(players.toString().slice(0..500) + "...")
}*/
val pairings_R1 = """[{"id":843,"w":525,"b":530,"h":0,"r":"?","dd":0},{"id":844,"w":516,"b":514,"h":0,"r":"?","dd":0},{"id":845,"w":532,"b":524,"h":0,"r":"?","dd":0},{"id":846,"w":513,"b":509,"h":0,"r":"?","dd":0},{"id":847,"w":533,"b":508,"h":0,"r":"?","dd":0},{"id":848,"w":504,"b":517,"h":0,"r":"?","dd":0},{"id":849,"w":507,"b":506,"h":0,"r":"?","dd":0},{"id":850,"w":523,"b":529,"h":0,"r":"?","dd":0},{"id":851,"w":503,"b":518,"h":0,"r":"?","dd":0},{"id":852,"w":512,"b":528,"h":0,"r":"?","dd":0},{"id":853,"w":515,"b":510,"h":0,"r":"?","dd":0},{"id":854,"w":502,"b":531,"h":0,"r":"?","dd":0},{"id":855,"w":505,"b":519,"h":0,"r":"?","dd":0},{"id":856,"w":522,"b":511,"h":0,"r":"?","dd":0},{"id":857,"w":521,"b":526,"h":0,"r":"?","dd":0},{"id":858,"w":527,"b":520,"h":0,"r":"?","dd":0}]"""
val pairings_R2 = """[{"id":859,"w":526,"b":530,"h":0,"r":"?","dd":0},{"id":860,"w":524,"b":514,"h":0,"r":"?","dd":0},{"id":861,"w":509,"b":517,"h":0,"r":"?","dd":0},{"id":862,"w":508,"b":518,"h":0,"r":"?","dd":0},{"id":863,"w":510,"b":506,"h":0,"r":"?","dd":0},{"id":864,"w":531,"b":529,"h":0,"r":"?","dd":0},{"id":865,"w":511,"b":528,"h":0,"r":"?","dd":0},{"id":866,"w":520,"b":519,"h":0,"r":"?","dd":0},{"id":867,"w":532,"b":516,"h":0,"r":"?","dd":0},{"id":868,"w":513,"b":504,"h":0,"r":"?","dd":0},{"id":869,"w":503,"b":533,"h":0,"r":"?","dd":0},{"id":870,"w":515,"b":507,"h":0,"r":"?","dd":0},{"id":871,"w":523,"b":502,"h":0,"r":"?","dd":0},{"id":872,"w":522,"b":512,"h":0,"r":"?","dd":0},{"id":873,"w":527,"b":505,"h":0,"r":"?","dd":0},{"id":874,"w":521,"b":525,"h":0,"r":"?","dd":0}]"""
val pairings_R3 = """[{"id":875,"w":519,"b":530,"h":0,"r":"?","dd":0},{"id":876,"w":514,"b":517,"h":0,"r":"?","dd":0},{"id":877,"w":529,"b":506,"h":0,"r":"?","dd":0},{"id":878,"w":518,"b":528,"h":0,"r":"?","dd":0},{"id":879,"w":507,"b":508,"h":0,"r":"?","dd":0},{"id":880,"w":531,"b":512,"h":0,"r":"?","dd":0},{"id":881,"w":510,"b":509,"h":0,"r":"?","dd":0},{"id":882,"w":505,"b":504,"h":0,"r":"?","dd":0},{"id":883,"w":526,"b":511,"h":0,"r":"?","dd":0},{"id":884,"w":525,"b":520,"h":0,"r":"?","dd":0},{"id":885,"w":516,"b":502,"h":0,"r":"?","dd":0},{"id":886,"w":524,"b":533,"h":0,"r":"?","dd":0},{"id":887,"w":522,"b":503,"h":0,"r":"?","dd":0},{"id":888,"w":527,"b":523,"h":0,"r":"?","dd":0},{"id":889,"w":513,"b":532,"h":0,"r":"?","dd":0},{"id":890,"w":521,"b":515,"h":0,"r":"?","dd":0}]"""
val pairings_R4 = """[{"id":891,"w":506,"b":528,"h":0,"r":"?","dd":0},{"id":892,"w":517,"b":530,"h":0,"r":"?","dd":0},{"id":893,"w":518,"b":512,"h":0,"r":"?","dd":0},{"id":894,"w":511,"b":519,"h":0,"r":"?","dd":0},{"id":895,"w":508,"b":504,"h":0,"r":"?","dd":0},{"id":896,"w":533,"b":514,"h":0,"r":"?","dd":0},{"id":897,"w":529,"b":502,"h":0,"r":"?","dd":0},{"id":898,"w":520,"b":509,"h":0,"r":"?","dd":0},{"id":899,"w":531,"b":516,"h":0,"r":"?","dd":0},{"id":900,"w":507,"b":503,"h":0,"r":"?","dd":0},{"id":901,"w":510,"b":505,"h":0,"r":"?","dd":0},{"id":902,"w":523,"b":524,"h":0,"r":"?","dd":0},{"id":903,"w":532,"b":526,"h":0,"r":"?","dd":0},{"id":904,"w":515,"b":525,"h":0,"r":"?","dd":0},{"id":905,"w":522,"b":527,"h":0,"r":"?","dd":0},{"id":906,"w":513,"b":521,"h":0,"r":"?","dd":0}]"""
val pairings_R5 = """[{"id":907,"w":528,"b":530,"h":0,"r":"?","dd":0},{"id":908,"w":512,"b":517,"h":0,"r":"?","dd":0},{"id":909,"w":504,"b":519,"h":0,"r":"?","dd":0},{"id":910,"w":514,"b":509,"h":0,"r":"?","dd":0},{"id":911,"w":506,"b":502,"h":0,"r":"?","dd":0},{"id":912,"w":516,"b":518,"h":0,"r":"?","dd":0},{"id":913,"w":511,"b":505,"h":0,"r":"?","dd":0},{"id":914,"w":520,"b":526,"h":0,"r":"?","dd":0},{"id":915,"w":525,"b":533,"h":0,"r":"?","dd":0},{"id":916,"w":524,"b":508,"h":0,"r":"?","dd":0},{"id":917,"w":503,"b":529,"h":0,"r":"?","dd":0},{"id":918,"w":531,"b":532,"h":0,"r":"?","dd":0},{"id":919,"w":527,"b":510,"h":0,"r":"?","dd":0},{"id":920,"w":523,"b":515,"h":0,"r":"?","dd":0},{"id":921,"w":507,"b":521,"h":0,"r":"?","dd":0},{"id":922,"w":513,"b":522,"h":0,"r":"?","dd":0}]"""
// read tournament without pairings
var file_np = getTestFile("opengotha/tournamentfiles/simpleswiss_nopairings.xml")
logger.info("read from file $file_np")
@@ -326,38 +343,30 @@ class BasicTests: TestBase() {
logger.info(tournament_np.toString().slice(0..50) + "...")
val players_np = TestAPI.get("/api/tour/$id_np/part").asArray()
logger.info(players_np.toString().slice(0..50) + "...")
// *** Test Round 1 ***
var games_np = TestAPI.post("/api/tour/$id_np/pair/1", Json.Array("all")).asArray()
logger.info("games for round 1: {}", games_np.toString())
// logger.info("Compare weights with itself")
assertTrue(compare_weights("weights.txt", "weights.txt"), "Weights not equal to itselft")
// logger.info("Compare weights with opengotha")
assertTrue(compare_weights("weights.txt", "weights.txt"), "Weights not equal to itself")
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weightsonly_R1.txt"), "Not matching opengotha weights for round 1")
val pairings_R1 = """[{"id":843,"w":525,"b":530,"h":0,"r":"?","dd":0},{"id":844,"w":516,"b":514,"h":0,"r":"?","dd":0},{"id":845,"w":532,"b":524,"h":0,"r":"?","dd":0},{"id":846,"w":513,"b":509,"h":0,"r":"?","dd":0},{"id":847,"w":533,"b":508,"h":0,"r":"?","dd":0},{"id":848,"w":504,"b":517,"h":0,"r":"?","dd":0},{"id":849,"w":507,"b":506,"h":0,"r":"?","dd":0},{"id":850,"w":523,"b":529,"h":0,"r":"?","dd":0},{"id":851,"w":503,"b":518,"h":0,"r":"?","dd":0},{"id":852,"w":512,"b":528,"h":0,"r":"?","dd":0},{"id":853,"w":515,"b":510,"h":0,"r":"?","dd":0},{"id":854,"w":502,"b":531,"h":0,"r":"?","dd":0},{"id":855,"w":505,"b":519,"h":0,"r":"?","dd":0},{"id":856,"w":522,"b":511,"h":0,"r":"?","dd":0},{"id":857,"w":521,"b":526,"h":0,"r":"?","dd":0},{"id":858,"w":527,"b":520,"h":0,"r":"?","dd":0}]"""
val pairings_R2 = """[{"id":859,"w":526,"b":530,"h":0,"r":"?","dd":0},{"id":860,"w":524,"b":514,"h":0,"r":"?","dd":0},{"id":861,"w":509,"b":517,"h":0,"r":"?","dd":0},{"id":862,"w":508,"b":518,"h":0,"r":"?","dd":0},{"id":863,"w":510,"b":506,"h":0,"r":"?","dd":0},{"id":864,"w":531,"b":529,"h":0,"r":"?","dd":0},{"id":865,"w":511,"b":528,"h":0,"r":"?","dd":0},{"id":866,"w":520,"b":519,"h":0,"r":"?","dd":0},{"id":867,"w":532,"b":516,"h":0,"r":"?","dd":0},{"id":868,"w":513,"b":504,"h":0,"r":"?","dd":0},{"id":869,"w":503,"b":533,"h":0,"r":"?","dd":0},{"id":870,"w":515,"b":507,"h":0,"r":"?","dd":0},{"id":871,"w":523,"b":502,"h":0,"r":"?","dd":0},{"id":872,"w":522,"b":512,"h":0,"r":"?","dd":0},{"id":873,"w":527,"b":505,"h":0,"r":"?","dd":0},{"id":874,"w":521,"b":525,"h":0,"r":"?","dd":0}]"""
val pairings_R3 = """[{"id":875,"w":519,"b":530,"h":0,"r":"?","dd":0},{"id":876,"w":514,"b":517,"h":0,"r":"?","dd":0},{"id":877,"w":529,"b":506,"h":0,"r":"?","dd":0},{"id":878,"w":518,"b":528,"h":0,"r":"?","dd":0},{"id":879,"w":507,"b":508,"h":0,"r":"?","dd":0},{"id":880,"w":531,"b":512,"h":0,"r":"?","dd":0},{"id":881,"w":510,"b":509,"h":0,"r":"?","dd":0},{"id":882,"w":505,"b":504,"h":0,"r":"?","dd":0},{"id":883,"w":526,"b":511,"h":0,"r":"?","dd":0},{"id":884,"w":525,"b":520,"h":0,"r":"?","dd":0},{"id":885,"w":516,"b":502,"h":0,"r":"?","dd":0},{"id":886,"w":524,"b":533,"h":0,"r":"?","dd":0},{"id":887,"w":522,"b":503,"h":0,"r":"?","dd":0},{"id":888,"w":527,"b":523,"h":0,"r":"?","dd":0},{"id":889,"w":513,"b":532,"h":0,"r":"?","dd":0},{"id":890,"w":521,"b":515,"h":0,"r":"?","dd":0}]"""
val pairings_R4 = """[{"id":891,"w":506,"b":528,"h":0,"r":"?","dd":0},{"id":892,"w":517,"b":530,"h":0,"r":"?","dd":0},{"id":893,"w":518,"b":512,"h":0,"r":"?","dd":0},{"id":894,"w":511,"b":519,"h":0,"r":"?","dd":0},{"id":895,"w":508,"b":504,"h":0,"r":"?","dd":0},{"id":896,"w":533,"b":514,"h":0,"r":"?","dd":0},{"id":897,"w":529,"b":502,"h":0,"r":"?","dd":0},{"id":898,"w":520,"b":509,"h":0,"r":"?","dd":0},{"id":899,"w":531,"b":516,"h":0,"r":"?","dd":0},{"id":900,"w":507,"b":503,"h":0,"r":"?","dd":0},{"id":901,"w":510,"b":505,"h":0,"r":"?","dd":0},{"id":902,"w":523,"b":524,"h":0,"r":"?","dd":0},{"id":903,"w":532,"b":526,"h":0,"r":"?","dd":0},{"id":904,"w":515,"b":525,"h":0,"r":"?","dd":0},{"id":905,"w":522,"b":527,"h":0,"r":"?","dd":0},{"id":906,"w":513,"b":521,"h":0,"r":"?","dd":0}]"""
val pairings_R5 = """[{"id":907,"w":528,"b":530,"h":0,"r":"?","dd":0},{"id":908,"w":512,"b":517,"h":0,"r":"?","dd":0},{"id":909,"w":504,"b":519,"h":0,"r":"?","dd":0},{"id":910,"w":514,"b":509,"h":0,"r":"?","dd":0},{"id":911,"w":506,"b":502,"h":0,"r":"?","dd":0},{"id":912,"w":516,"b":518,"h":0,"r":"?","dd":0},{"id":913,"w":511,"b":505,"h":0,"r":"?","dd":0},{"id":914,"w":520,"b":526,"h":0,"r":"?","dd":0},{"id":915,"w":525,"b":533,"h":0,"r":"?","dd":0},{"id":916,"w":524,"b":508,"h":0,"r":"?","dd":0},{"id":917,"w":503,"b":529,"h":0,"r":"?","dd":0},{"id":918,"w":531,"b":532,"h":0,"r":"?","dd":0},{"id":919,"w":527,"b":510,"h":0,"r":"?","dd":0},{"id":920,"w":523,"b":515,"h":0,"r":"?","dd":0},{"id":921,"w":507,"b":521,"h":0,"r":"?","dd":0},{"id":922,"w":513,"b":522,"h":0,"r":"?","dd":0}]"""
//logger.info(compare_string(pairings_R1, games_np.toString()))
// val games = TestAPI.get("/api/tour/$id/res/1").asArray()
//logger.info("Compare pairings for round 1")
assertTrue(compare_games(games_np, Json.parse(pairings_R1.toString())!!.asArray()), "pairings for round 1 differ")
assertEquals(pairings_R1, games_np.toString(), "pairings for round 1 differ")
logger.info("Pairings for round 1 match OpenGotha")
//val results_R1 = ["""{"id":843,"result":"b"}""", """{"id":844,"result":"b"}"""]//,{"id":846,"w":513,"b":509,"h":0,"r":"?","dd":0},{"id":847,"w":533,"b":508,"h":0,"r":"?","dd":0},{"id":848,"w":504,"b":517,"h":0,"r":"?","dd":0},{"id":849,"w":507,"b":506,"h":0,"r":"?","dd":0},{"id":850,"w":523,"b":529,"h":0,"r":"?","dd":0},{"id":851,"w":503,"b":518,"h":0,"r":"?","dd":0},{"id":852,"w":512,"b":528,"h":0,"r":"?","dd":0},{"id":853,"w":515,"b":510,"h":0,"r":"?","dd":0},{"id":854,"w":502,"b":531,"h":0,"r":"?","dd":0},{"id":855,"w":505,"b":519,"h":0,"r":"?","dd":0},{"id":856,"w":522,"b":511,"h":0,"r":"?","dd":0},{"id":857,"w":521,"b":526,"h":0,"r":"?","dd":0},{"id":858,"w":527,"b":520,"h":0,"r":"?","dd":0}]"""
for (game_id in 843..858) {
resp_np = TestAPI.put("/api/tour/$id_np/res/1", Json.parse("""{"id":$game_id,"result":"b"}""")).asObject()
assertTrue(resp_np.getBoolean("success") == true, "expecting success")
}
logger.info("Results succesfully entered for round 1")
// *** Test Round 2 ***
games_np = TestAPI.post("/api/tour/$id_np/pair/2", Json.Array("all")).asArray()
logger.info("games for round 2: {}", games_np.toString())
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weights_R2.txt"), "Not matching opengotha weights for round 2")
assertTrue(compare_games(games_np, Json.parse(pairings_R2.toString())!!.asArray()), "pairings for round 2 differ")
assertEquals(pairings_R2, games_np.toString(), "pairings for round 2 differ")
logger.info("Pairings for round 2 match OpenGotha")
@@ -367,15 +376,35 @@ class BasicTests: TestBase() {
}
logger.info("Results succesfully entered for round 2")
// *** Test Round 3 ***
games_np = TestAPI.post("/api/tour/$id_np/pair/3", Json.Array("all")).asArray()
logger.info("games for round 3: {}", games_np.toString())
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weights_R3.txt"), "Not matching opengotha weights for round 3")
assertTrue(compare_games(games_np, Json.parse(pairings_R3.toString())!!.asArray()), "pairings for round 3 differ")
assertEquals(pairings_R3, games_np.toString(), "pairings for round 3 differ")
logger.info("Pairings for round 3 match OpenGotha")
for (game_id in 875..890) {
resp_np = TestAPI.put("/api/tour/$id_np/res/3", Json.parse("""{"id":$game_id,"result":"b"}""")).asObject()
assertTrue(resp_np.getBoolean("success") == true, "expecting success")
}
logger.info("Results succesfully entered for round 3")
// *** Test Round 4 ***
games_np = TestAPI.post("/api/tour/$id_np/pair/4", Json.Array("all")).asArray()
logger.info("games for round 4: {}", games_np.toString())
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weights_R4.txt"), "Not matching opengotha weights for round 4")
assertTrue(compare_games(games_np, Json.parse(pairings_R4.toString())!!.asArray()), "pairings for round 4 differ")
//assertEquals(pairings_R4, games_np.toString(), "pairings for round 3 differ")
logger.info("Pairings for round 4 match OpenGotha")
for (game_id in 891..906) {
resp_np = TestAPI.put("/api/tour/$id_np/res/4", Json.parse("""{"id":$game_id,"result":"b"}""")).asObject()
assertTrue(resp_np.getBoolean("success") == true, "expecting success")
}
logger.info("Results succesfully entered for round 4")
}