Move weights test before pairings test

This commit is contained in:
Quentin Rendu
2023-09-28 18:38:50 +02:00
parent e5d65847f2
commit 40be83f31c

View File

@@ -206,6 +206,50 @@ class BasicTests: TestBase() {
// val expected = """"["id":1,"w":5,"b":6,"h":3,"r":"?"]""" // val expected = """"["id":1,"w":5,"b":6,"h":3,"r":"?"]"""
} }
fun compare_weights(file1:String, file2:String):Boolean {
// Maps to store name pairs and costs
val map1 = HashMap<Pair<String, String>, List<Double>>()
val map2 = HashMap<Pair<String, String>, List<Double>>()
for (file in listOf(file1, file2)) {
// Read lines
val lines = getTestFile(file).readLines()
// Store headers
val header1 = lines[0]
val header2 = lines[1]
logger.info("Reading weights file "+file)
// Loop through sections
for (i in 2..lines.size-1 step 12) {
// Get name pair
val name1 = lines[i].split("=")[1]
val name2 = lines[i+1].split("=")[1]
// Nested loop over costs
val costs = mutableListOf<Double>()
for (j in i + 2..i + 11) {
val parts = lines[j].split("=")
costs.add(parts[1].toDouble())
}
// Add to map
if (file == "weights.txt") {
map1[Pair(name1, name2)] = costs
} else {
map2[Pair(name1, name2)] = costs
}
}
}
return map1==map2
}
@Test @Test
fun `008 simple swiss tournament`() { fun `008 simple swiss tournament`() {
@@ -223,6 +267,11 @@ class BasicTests: TestBase() {
var games_np = TestAPI.post("/api/tour/$id_np/pair/1", Json.Array("all")).asArray() 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("games for round 1: {}", games_np.toString())
logger.info("Compare weights with itself")
assertTrue(compare_weights("weights.txt", "weights.txt"), "expecting success")
logger.info("Compare weights with opengotha")
assertTrue(compare_weights("weights.txt", "opengotha/simpleswiss_weightsonly_R1.txt"), "expecting success")
val pairings_R1 = """[{"id":283,"w":195,"b":201,"h":0,"r":"?","dd":0}, val pairings_R1 = """[{"id":283,"w":195,"b":201,"h":0,"r":"?","dd":0},
|{"id":284,"w":186,"b":184,"h":0,"r":"?","dd":0},{"id":285,"w":200,"b":194,"h":0,"r":"?","dd":0}, |{"id":284,"w":186,"b":184,"h":0,"r":"?","dd":0},{"id":285,"w":200,"b":194,"h":0,"r":"?","dd":0},
|{"id":286,"w":179,"b":187,"h":0,"r":"?","dd":0},{"id":287,"w":203,"b":178,"h":0,"r":"?","dd":0}, |{"id":286,"w":179,"b":187,"h":0,"r":"?","dd":0},{"id":287,"w":203,"b":178,"h":0,"r":"?","dd":0},
@@ -257,61 +306,4 @@ class BasicTests: TestBase() {
} }
@Test
fun `009 compare weigths`() {
// Maps to store name pairs and costs
val map1 = HashMap<Pair<String, String>, List<Double>>()
val map2 = HashMap<Pair<String, String>, List<Double>>()
for (file in listOf("weights.txt", "opengotha/simpleswiss_weightsonly_R1.txt")) {
// Read lines
val lines = getTestFile(file).readLines()
// Store headers
val header1 = lines[0]
val header2 = lines[1]
logger.info(file)
logger.info(header1.toString())
logger.info(header2.toString())
// Loop through sections
for (i in 2..lines.size-1 step 12) {
logger.info(i.toString())
// Get name pair
val name1 = lines[i].split("=")[1]
val name2 = lines[i+1].split("=")[1]
// Nested loop over costs
val costs = mutableListOf<Double>()
for (j in i + 2..i + 11) {
val parts = lines[j].split("=")
costs.add(parts[1].toDouble())
}
if (i==2){
logger.info(name1)
logger.info(name2)
logger.info(costs.toString())
}
// Add to map
if (file == "weights.txt") {
map1[Pair(name1, name2)] = costs
} else {
map2[Pair(name1, name2)] = costs
}
}
}
println(map1)
println(map1==map2)
}
} }