Fixing tests (wip)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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")
|
||||
|
Reference in New Issue
Block a user