Add tests for WTC compression
This commit is contained in:
parent
5e770a0f2c
commit
cc10fa221e
44
nise-backend/src/test/kotlin/com/nisemoe/nise/osu/WtcTest.kt
Normal file
44
nise-backend/src/test/kotlin/com/nisemoe/nise/osu/WtcTest.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
nise-backend/src/test/resources/wtc/replay_1_compressed.dat
Normal file
BIN
nise-backend/src/test/resources/wtc/replay_1_compressed.dat
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
1
nise-backend/src/test/resources/wtc/replay_1_events.txt
Normal file
1
nise-backend/src/test/resources/wtc/replay_1_events.txt
Normal file
File diff suppressed because one or more lines are too long
BIN
nise-backend/src/test/resources/wtc/replay_2_compressed.dat
Normal file
BIN
nise-backend/src/test/resources/wtc/replay_2_compressed.dat
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
1
nise-backend/src/test/resources/wtc/replay_2_events.txt
Normal file
1
nise-backend/src/test/resources/wtc/replay_2_events.txt
Normal file
File diff suppressed because one or more lines are too long
BIN
nise-backend/src/test/resources/wtc/replay_3_compressed.dat
Normal file
BIN
nise-backend/src/test/resources/wtc/replay_3_compressed.dat
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
1
nise-backend/src/test/resources/wtc/replay_3_events.txt
Normal file
1
nise-backend/src/test/resources/wtc/replay_3_events.txt
Normal file
File diff suppressed because one or more lines are too long
BIN
nise-backend/src/test/resources/wtc/replay_4_compressed.dat
Normal file
BIN
nise-backend/src/test/resources/wtc/replay_4_compressed.dat
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
1
nise-backend/src/test/resources/wtc/replay_4_events.txt
Normal file
1
nise-backend/src/test/resources/wtc/replay_4_events.txt
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user