Code cleaning: fix previous commit, simplify HistoryHelper creation
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package org.jeudego.pairgoth.test
|
||||
|
||||
import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.pairing.solver.BaseSolver
|
||||
import org.jeudego.pairgoth.model.Game
|
||||
import org.jeudego.pairgoth.pairing.solver.Solver
|
||||
import org.jeudego.pairgoth.test.PairingTests.Companion.compare_weights
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.FileWriter
|
||||
import java.io.PrintWriter
|
||||
import java.nio.charset.StandardCharsets
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
@@ -22,16 +20,16 @@ class BOSP2024Test: TestBase() {
|
||||
)!!.asObject()
|
||||
val resp = TestAPI.post("/api/tour", tournament).asObject()
|
||||
val tourId = resp.getInt("id")
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("bosp2024-weights.txt")))
|
||||
Solver.weightsLogger = PrintWriter(FileWriter(getOutputFile("bosp2024-weights.txt")))
|
||||
|
||||
BaseSolver.legacy_mode = true
|
||||
Solver.legacy_mode = true
|
||||
TestAPI.post("/api/tour/$tourId/pair/3", Json.Array("all")).asArray()
|
||||
|
||||
// compare weights
|
||||
assertTrue(compare_weights(getOutputFile("bosp2024-weights.txt"), getTestFile("opengotha/bosp2024/bosp2024_weights_R3.txt")), "Not matching opengotha weights for BOSP test")
|
||||
TestAPI.delete("/api/tour/$tourId/pair/3", Json.Array("all"))
|
||||
|
||||
BaseSolver.legacy_mode = false
|
||||
Solver.legacy_mode = false
|
||||
val games = TestAPI.post("/api/tour/$tourId/pair/3", Json.Array("all")).asArray()
|
||||
// Aksut Husrev is ID 18
|
||||
val solved = games.map { it as Json.Object }.filter { game ->
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package org.jeudego.pairgoth.test
|
||||
|
||||
import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.pairing.solver.BaseSolver
|
||||
import org.jeudego.pairgoth.pairing.solver.Solver
|
||||
import org.jeudego.pairgoth.test.PairingTests.Companion.compare_weights
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.FileWriter
|
||||
@@ -19,7 +19,7 @@ class MalavasiTest: TestBase() {
|
||||
)!!.asObject()
|
||||
val resp = TestAPI.post("/api/tour", tournament).asObject()
|
||||
val tourId = resp.getInt("id")
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("malavasi-weights.txt")))
|
||||
Solver.weightsLogger = PrintWriter(FileWriter(getOutputFile("malavasi-weights.txt")))
|
||||
val games = TestAPI.post("/api/tour/$tourId/pair/2", Json.Array("all")).asArray()
|
||||
// Oceane is ID 548, Valentine 549
|
||||
val buggy = games.map { it as Json.Object }.filter { game ->
|
||||
|
@@ -2,7 +2,7 @@ package org.jeudego.pairgoth.test
|
||||
|
||||
import com.republicate.kson.Json
|
||||
import org.jeudego.pairgoth.model.*
|
||||
import org.jeudego.pairgoth.pairing.solver.BaseSolver
|
||||
import org.jeudego.pairgoth.pairing.solver.Solver
|
||||
import org.jeudego.pairgoth.store.MemoryStore
|
||||
import org.jeudego.pairgoth.store.lastPlayerId
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
@@ -59,7 +59,7 @@ class PairingTests: TestBase() {
|
||||
}
|
||||
|
||||
fun compare_weights(file1: File, file2: File, skipSeeding: Boolean = false):Boolean {
|
||||
BaseSolver.weightsLogger!!.flush()
|
||||
Solver.weightsLogger!!.flush()
|
||||
// Maps to store name pairs and costs
|
||||
val map1 = create_weights_map(file1)
|
||||
val map2 = create_weights_map(file2)
|
||||
@@ -172,7 +172,7 @@ class PairingTests: TestBase() {
|
||||
|
||||
fun test_from_XML_internal(name: String, forcePairing:List<Int>, legacy: Boolean) {
|
||||
// Let pairgoth use the legacy asymmetric detRandom()
|
||||
BaseSolver.legacy_mode = legacy
|
||||
Solver.legacy_mode = legacy
|
||||
// read tournament with pairing
|
||||
val file = getTestFile("opengotha/pairings/$name.xml")
|
||||
logger.info("read from file $file")
|
||||
@@ -203,7 +203,7 @@ class PairingTests: TestBase() {
|
||||
for (round in 1..tournament.getInt("rounds")!!) {
|
||||
val sumOfWeightsOG = compute_sumOfWeight_OG(getTestFile("opengotha/$name/$name" + "_weights_R$round.txt"), pairingsOG[round-1], players)
|
||||
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
Solver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
// Call Pairgoth pairing solver to generate games
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
logger.info("sumOfWeightOG = " + dec.format(sumOfWeightsOG))
|
||||
@@ -273,7 +273,7 @@ class PairingTests: TestBase() {
|
||||
|
||||
@Test
|
||||
fun `SwissTest simpleSwiss`() {
|
||||
BaseSolver.legacy_mode = true
|
||||
Solver.legacy_mode = true
|
||||
// read tournament with pairing
|
||||
var file = getTestFile("opengotha/pairings/simpleswiss.xml")
|
||||
logger.info("read from file $file")
|
||||
@@ -315,7 +315,7 @@ class PairingTests: TestBase() {
|
||||
var firstGameID: Int
|
||||
|
||||
for (round in 1..7) {
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
Solver.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().slice(0..50) + "...")
|
||||
assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/simpleswiss/simpleswiss_weights_R$round.txt")), "Not matching opengotha weights for round $round")
|
||||
@@ -354,7 +354,7 @@ class PairingTests: TestBase() {
|
||||
@Test
|
||||
fun `SwissTest KPMCSplitbug`() {
|
||||
// Let pairgoth use the legacy asymmetric detRandom()
|
||||
BaseSolver.legacy_mode = true
|
||||
Solver.legacy_mode = true
|
||||
// read tournament with pairing
|
||||
val name = "20240921-KPMC-Splitbug"
|
||||
val file = getTestFile("opengotha/pairings/$name.xml")
|
||||
@@ -391,7 +391,7 @@ class PairingTests: TestBase() {
|
||||
for (round in minRound..maxRound) {
|
||||
val sumOfWeightsOG = compute_sumOfWeight_OG(getTestFile("opengotha/$name/$name" + "_weights_R$round.txt"), pairingsOG[round - minRound], players)
|
||||
|
||||
BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
Solver.weightsLogger = PrintWriter(FileWriter(getOutputFile("weights.txt")))
|
||||
// Call Pairgoth pairing solver to generate games
|
||||
games = TestAPI.post("/api/tour/$id/pair/$round", Json.Array("all")).asArray()
|
||||
|
||||
|
Reference in New Issue
Block a user