package com.nisemoe.nise.osu

import com.nisemoe.nise.konata.tools.getEvents
import com.nisemoe.nise.service.CompressReplay
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
import kotlin.test.assertEquals

@Disabled
class Whatever {

    private val logger = LoggerFactory.getLogger(javaClass)

    private val replayString = "[encoded data, 66460 characters]"

    @Test
    fun compressNativeReplay() {
        val compressed = CompressReplay.compressReplay(replayString)

        logger.info("Compressed replay collection from ${replayString.length} bytes to ${compressed.size} bytes")
        val spaceSaved = (1 - compressed.size.toDouble() / replayString.length) * 100
        logger.info("Space saved: %.2f%%".format(spaceSaved))

        val decompressed = CompressReplay.decompressReplay(compressed)

        val replayString2 = String(decompressed, Charsets.UTF_8).trimEnd(',')

        val replayEvents = getEvents(replayString)
        val decompressedEvents = getEvents(replayString2)

        assert(replayEvents.size == decompressedEvents.size)
    }

    @Test
    fun compressAlreadyCompressedReplay() {
        val compressed = CompressReplay.compressReplay(replayString)
        val compressed2 = CompressReplay.compressReplay(compressed)

        assertEquals(compressed, compressed2)
    }

    @Test
    fun decompressNativeReplay() {
        val decompressed = CompressReplay.decompressReplayToString(replayString.toByteArray())

        val replayEvents = getEvents(replayString)
        val decompressedEvents = getEvents(decompressed)

        assert(replayEvents.size == decompressedEvents.size)
    }

    @Test
    fun decompressAlreadyDecompressedReplay() {
        val decompressed = CompressReplay.decompressReplay(replayString.toByteArray())
        val decompressed2 = CompressReplay.decompressReplay(decompressed)

        assertEquals(decompressed, decompressed2)
    }

}