From beeb57a54948a1c684e4a84f8e31b9a190cc7a85 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Wed, 4 Sep 2024 13:33:02 +0200 Subject: [PATCH] Fixing tests (wip) --- .../kotlin/org/jeudego/pairgoth/pairing/Random.kt | 7 +++++-- .../org/jeudego/pairgoth/pairing/solver/BaseSolver.kt | 11 ++++++++++- api-webapp/src/test/kotlin/PairingTests.kt | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt index 7f4925e..0a0af21 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt @@ -1,6 +1,7 @@ package org.jeudego.pairgoth.pairing import org.jeudego.pairgoth.model.Pairable +import org.jeudego.pairgoth.pairing.solver.BaseSolver fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double { var inverse = false @@ -13,8 +14,10 @@ fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double { var nR = "$name1$name2".mapIndexed { i, c -> c.code.toDouble() * (i + 1) }.sum() * 1234567 % (max + 1) - // we want the symmetry - // if (inverse) nR = max - nR + // we want the symmetry, except when explicitly asked for a legacy asymmetric detRandom, for tests + if (inverse && BaseSolver.asymmetricDetRandom) { + nR = max - nR + } return nR } diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt index 7ad769c..6d01d1b 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt @@ -30,7 +30,9 @@ sealed class BaseSolver( companion object { val rand = Random(/* seed from properties - TODO */) + // Used in tests var weightsLogger: PrintWriter? = null + var asymmetricDetRandom = false } open fun openGothaWeight(p1: Pairable, p2: Pairable) = @@ -367,7 +369,14 @@ sealed class BaseSolver( SPLIT_AND_RANDOM -> { if ((2 * cla1 < groupSize && 2 * cla2 >= groupSize) || (2 * cla1 >= groupSize && 2 * cla2 < groupSize)) { val randRange = maxSeedingWeight * 0.2 - val rand = detRandom(randRange, p2, p1) + // for old tests to pass + val rand = + if (asymmetricDetRandom && p1.fullName() > p2.fullName()) { + // for old tests to pass + detRandom(randRange, p2, p1) + } else { + detRandom(randRange, p1, p2) + } maxSeedingWeight - rand } else { 0.0 diff --git a/api-webapp/src/test/kotlin/PairingTests.kt b/api-webapp/src/test/kotlin/PairingTests.kt index a87dbf8..b98f94d 100644 --- a/api-webapp/src/test/kotlin/PairingTests.kt +++ b/api-webapp/src/test/kotlin/PairingTests.kt @@ -140,6 +140,8 @@ class PairingTests: TestBase() { } fun test_from_XML(name:String){ + // Let pairgoth use the legacy asymmetric detRandom() + BaseSolver.asymmetricDetRandom = true // read tournament with pairing val file = getTestFile("opengotha/pairings/$name.xml") logger.info("read from file $file") @@ -219,6 +221,7 @@ class PairingTests: TestBase() { @Test fun `SwissTest simpleSwiss`() { + BaseSolver.asymmetricDetRandom = true // read tournament with pairing var file = getTestFile("opengotha/pairings/simpleswiss.xml") logger.info("read from file $file")