From 79447b5936f3c8688f5a55f21a381f7e845defc0 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Sat, 2 Jul 2022 10:20:32 +0200 Subject: [PATCH] fix tests after events-lib & events-server refactor --- .../events/schema/MapChunkUpdateTest.kt | 2 +- .../events/schema/PrototypesTest.kt | 2 +- .../events/schema/UpdatePacketsTest.kt | 3 +- .../common/MapChunkPositionBoundsTest.kt | 39 ++++++++++++++++++ .../schema/packets/EntityUpdateTest.kt | 2 +- .../schema/common/MapTileDictionaryTest.kt | 40 ------------------- 6 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 modules/events-library/src/jvmTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTileDictionaryTest.kt diff --git a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/MapChunkUpdateTest.kt b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/MapChunkUpdateTest.kt index 0039a91..9a3aaf9 100644 --- a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/MapChunkUpdateTest.kt +++ b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/MapChunkUpdateTest.kt @@ -1,12 +1,12 @@ package dev.adamko.kafkatorio.events.schema +import dev.adamko.kafkatorio.library.jsonMapperKafkatorio import dev.adamko.kafkatorio.schema.common.EventName import dev.adamko.kafkatorio.schema.common.MapChunkPosition import dev.adamko.kafkatorio.schema.common.MapTileDictionary import dev.adamko.kafkatorio.schema.common.PrototypeName import dev.adamko.kafkatorio.schema.common.SurfaceIndex import dev.adamko.kafkatorio.schema.common.tick -import dev.adamko.kafkatorio.schema.jsonMapperKafkatorio import dev.adamko.kafkatorio.schema.packets.KafkatorioPacket import dev.adamko.kafkatorio.schema.packets.MapChunkUpdate import dev.adamko.kafkatorio.schema.packets.MapChunkUpdateKey diff --git a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/PrototypesTest.kt b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/PrototypesTest.kt index e4b4387..17387a2 100644 --- a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/PrototypesTest.kt +++ b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/PrototypesTest.kt @@ -1,9 +1,9 @@ package dev.adamko.kafkatorio.events.schema +import dev.adamko.kafkatorio.library.jsonMapperKafkatorio import dev.adamko.kafkatorio.schema.common.Colour import dev.adamko.kafkatorio.schema.common.FactorioPrototype import dev.adamko.kafkatorio.schema.common.PrototypeName -import dev.adamko.kafkatorio.schema.jsonMapperKafkatorio import dev.adamko.kafkatorio.schema.packets.KafkatorioPacket import dev.adamko.kafkatorio.schema.packets.PrototypesUpdate import io.kotest.core.spec.style.BehaviorSpec diff --git a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/UpdatePacketsTest.kt b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/UpdatePacketsTest.kt index 787c75d..b6249c6 100644 --- a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/UpdatePacketsTest.kt +++ b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/events/schema/UpdatePacketsTest.kt @@ -1,5 +1,6 @@ package dev.adamko.kafkatorio.events.schema +import dev.adamko.kafkatorio.library.jsonMapperKafkatorio import dev.adamko.kafkatorio.schema.common.Colour import dev.adamko.kafkatorio.schema.common.EntityIdentifiersData import dev.adamko.kafkatorio.schema.common.EventName @@ -10,8 +11,6 @@ import dev.adamko.kafkatorio.schema.common.SurfaceIndex import dev.adamko.kafkatorio.schema.common.Tick import dev.adamko.kafkatorio.schema.common.UnitNumber import dev.adamko.kafkatorio.schema.common.tick -import dev.adamko.kafkatorio.schema.jsonMapperKafkatorio -import dev.adamko.kafkatorio.schema.packets.KafkatorioKeyedPacketData import dev.adamko.kafkatorio.schema.packets.KafkatorioPacket import dev.adamko.kafkatorio.schema.packets.PlayerUpdate import dev.adamko.kafkatorio.schema.packets.PlayerUpdateKey diff --git a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt index 6a2a044..565818b 100644 --- a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt +++ b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt @@ -1,8 +1,13 @@ package dev.adamko.kafkatorio.schema.common +import dev.adamko.kafkatorio.library.kxsBinary import io.kotest.assertions.asClue import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.ints.shouldBeExactly +import io.kotest.matchers.maps.shouldContainExactly +import kotlinx.serialization.decodeFromByteArray +import kotlinx.serialization.encodeToByteArray class MapChunkPositionBoundsTest : FunSpec({ @@ -95,4 +100,38 @@ class MapChunkPositionBoundsTest : FunSpec({ } } + + context("encode MapTileDictionary") { + val actual = MapTileDictionary( + tilesXY = mapOf( + "-192" to mapOf("-65" to MapTileDictionary.PrototypeKey(2)), + "161" to mapOf( + "-96" to MapTileDictionary.PrototypeKey(1), + "-95" to MapTileDictionary.PrototypeKey(2), + "94" to MapTileDictionary.PrototypeKey(2), + "93" to MapTileDictionary.PrototypeKey(32), + ), + + // unknown prototype + "44" to mapOf("1" to MapTileDictionary.PrototypeKey(44)), + ), + protos = mapOf( + PrototypeName("water") to MapTileDictionary.PrototypeKey(1), + PrototypeName("grass-4") to MapTileDictionary.PrototypeKey(2), + PrototypeName("grass-3") to MapTileDictionary.PrototypeKey(32), + + PrototypeName("not-used") to MapTileDictionary.PrototypeKey(99), + ) + ) + + test("binary round trip") { + val encoded: ByteArray = kxsBinary.encodeToByteArray(actual) + val decoded: MapTileDictionary = kxsBinary.decodeFromByteArray(encoded) + + decoded.tilesXY shouldContainExactly actual.tilesXY + decoded.protos shouldContainExactly actual.protos + + decoded.toMapTileList() shouldContainExactly actual.toMapTileList() + } + } }) diff --git a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/packets/EntityUpdateTest.kt b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/packets/EntityUpdateTest.kt index 7ab5c32..47c3552 100644 --- a/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/packets/EntityUpdateTest.kt +++ b/modules/events-library/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/packets/EntityUpdateTest.kt @@ -1,6 +1,6 @@ package dev.adamko.kafkatorio.schema.packets -import dev.adamko.kafkatorio.schema.jsonMapperKafkatorio +import dev.adamko.kafkatorio.library.jsonMapperKafkatorio import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.types.shouldBeInstanceOf import kotlinx.serialization.decodeFromString diff --git a/modules/events-library/src/jvmTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTileDictionaryTest.kt b/modules/events-library/src/jvmTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTileDictionaryTest.kt deleted file mode 100644 index fdf6545..0000000 --- a/modules/events-library/src/jvmTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTileDictionaryTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package dev.adamko.kafkatorio.schema.common - -import dev.adamko.kafkatorio.library.kxsBinary -import io.kotest.core.spec.style.FunSpec -import io.kotest.matchers.equality.shouldBeEqualToComparingFields -import kotlinx.serialization.decodeFromByteArray -import kotlinx.serialization.encodeToByteArray - -class MapTileDictionaryTest : FunSpec({ - - context("encode MapTileDictionary") { - val actual = MapTileDictionary( - tilesXY = mapOf( - "-192" to mapOf("-65" to MapTileDictionary.PrototypeKey(2)), - "161" to mapOf( - "-96" to MapTileDictionary.PrototypeKey(1), - "-95" to MapTileDictionary.PrototypeKey(2), - "94" to MapTileDictionary.PrototypeKey(2), - "93" to MapTileDictionary.PrototypeKey(32), - ), - - // unknown prototype - "44" to mapOf("1" to MapTileDictionary.PrototypeKey(44)), - ), - protos = mapOf( - PrototypeName("water") to MapTileDictionary.PrototypeKey(1), - PrototypeName("grass-4") to MapTileDictionary.PrototypeKey(2), - PrototypeName("grass-3") to MapTileDictionary.PrototypeKey(32), - - PrototypeName("not-used") to MapTileDictionary.PrototypeKey(99), - ) - ) - - test("binary round trip") { - val encoded: ByteArray = kxsBinary.encodeToByteArray(actual) - val decoded: MapTileDictionary = kxsBinary.decodeFromByteArray(encoded) - decoded.shouldBeEqualToComparingFields(actual) - } - } -})