Add tests for WTC compression

This commit is contained in:
Stedoss 2025-02-23 20:40:51 +00:00
parent 5e770a0f2c
commit cc10fa221e
13 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package com.nisemoe.nise.osu
import com.nisemoe.nise.replays.wtcCompress
import com.nisemoe.nise.replays.wtcDecompress
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.junit.jupiter.api.Assertions
import org.testcontainers.shaded.org.bouncycastle.util.Arrays
import java.nio.file.Paths
import kotlin.test.assertEquals
class WtcTest {
private val resourcesPath = Paths.get("src", "test", "resources", "wtc")
/**
* Compares the bytes produced from the `wtcCompress()` function with bytes produced from the Python implementation of WTC.
*/
@ParameterizedTest
@ValueSource(strings = ["replay_1", "replay_2", "replay_3", "replay_4"])
fun wtcCompressReturnsCorrectBytes(replayName: String) {
val expected = resourcesPath.resolve("${replayName}_compressed.dat").toFile().readBytes()
val replayEvents = resourcesPath.resolve("${replayName}_events.txt").toFile().readText()
val wtcCompressed = wtcCompress(replayEvents)
// We include a version header at the start of the compressed byte array - create a new array excluding these
// so we can compare just the raw data with the Python WTC implementation's output.
// (remove the first two bytes since the version header is a Short)
val wtcCompressedWithoutVersionHeader = Arrays.copyOfRange(wtcCompressed, 2, wtcCompressed.size)
Assertions.assertArrayEquals(expected, wtcCompressedWithoutVersionHeader)
}
@ParameterizedTest
@ValueSource(strings = ["replay_1", "replay_2", "replay_3", "replay_4"])
fun wtcDecompressReturnsCorrectReplayFrames(replayName: String) {
val expected = resourcesPath.resolve("${replayName}_decompressed.txt").toFile().readText()
val compressedReplay = resourcesPath.resolve("${replayName}_compressed.dat").toFile().readBytes()
val wtcDecompressed = wtcDecompress(compressedReplay, false)
assertEquals(expected, wtcDecompressed)
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long