Fixing tests (wip)

This commit is contained in:
Claude Brisson
2024-09-04 13:33:02 +02:00
parent 06ecd3e27b
commit beeb57a549
3 changed files with 18 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package org.jeudego.pairgoth.pairing package org.jeudego.pairgoth.pairing
import org.jeudego.pairgoth.model.Pairable import org.jeudego.pairgoth.model.Pairable
import org.jeudego.pairgoth.pairing.solver.BaseSolver
fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double { fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double {
var inverse = false var inverse = false
@@ -13,8 +14,10 @@ fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double {
var nR = "$name1$name2".mapIndexed { i, c -> var nR = "$name1$name2".mapIndexed { i, c ->
c.code.toDouble() * (i + 1) c.code.toDouble() * (i + 1)
}.sum() * 1234567 % (max + 1) }.sum() * 1234567 % (max + 1)
// we want the symmetry // we want the symmetry, except when explicitly asked for a legacy asymmetric detRandom, for tests
// if (inverse) nR = max - nR if (inverse && BaseSolver.asymmetricDetRandom) {
nR = max - nR
}
return nR return nR
} }

View File

@@ -30,7 +30,9 @@ sealed class BaseSolver(
companion object { companion object {
val rand = Random(/* seed from properties - TODO */) val rand = Random(/* seed from properties - TODO */)
// Used in tests
var weightsLogger: PrintWriter? = null var weightsLogger: PrintWriter? = null
var asymmetricDetRandom = false
} }
open fun openGothaWeight(p1: Pairable, p2: Pairable) = open fun openGothaWeight(p1: Pairable, p2: Pairable) =
@@ -367,7 +369,14 @@ sealed class BaseSolver(
SPLIT_AND_RANDOM -> { SPLIT_AND_RANDOM -> {
if ((2 * cla1 < groupSize && 2 * cla2 >= groupSize) || (2 * cla1 >= groupSize && 2 * cla2 < groupSize)) { if ((2 * cla1 < groupSize && 2 * cla2 >= groupSize) || (2 * cla1 >= groupSize && 2 * cla2 < groupSize)) {
val randRange = maxSeedingWeight * 0.2 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 maxSeedingWeight - rand
} else { } else {
0.0 0.0

View File

@@ -140,6 +140,8 @@ class PairingTests: TestBase() {
} }
fun test_from_XML(name:String){ fun test_from_XML(name:String){
// Let pairgoth use the legacy asymmetric detRandom()
BaseSolver.asymmetricDetRandom = true
// read tournament with pairing // read tournament with pairing
val file = getTestFile("opengotha/pairings/$name.xml") val file = getTestFile("opengotha/pairings/$name.xml")
logger.info("read from file $file") logger.info("read from file $file")
@@ -219,6 +221,7 @@ class PairingTests: TestBase() {
@Test @Test
fun `SwissTest simpleSwiss`() { fun `SwissTest simpleSwiss`() {
BaseSolver.asymmetricDetRandom = true
// read tournament with pairing // read tournament with pairing
var file = getTestFile("opengotha/pairings/simpleswiss.xml") var file = getTestFile("opengotha/pairings/simpleswiss.xml")
logger.info("read from file $file") logger.info("read from file $file")