From ffe9bcb9a88162526e8d67db0337641f00da0f45 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Sat, 14 May 2022 12:22:47 +0200 Subject: [PATCH] bump versions - kotlinx js wrappers - kotest also fix kotest dependencies --- gradle/libs.versions.toml | 11 ++- .../common/MapChunkPositionBoundsTest.kt | 98 +++++++++++++++++++ .../schema/common/MapChunkPositionTest.kt | 81 +++++++++++++++ .../schema/common/MapTilePositionTest.kt | 43 ++++++++ 4 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt create mode 100644 modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionTest.kt create mode 100644 modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTilePositionTest.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c112b5e..e8d0aab 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,8 @@ scrimage = "4.0.31" kotlinx-serialization = "1.3.2" kxs-yaml = "0.43.0" -kotlinJsWrappers = "0.0.1-pre.331-kotlin-1.6.20" +#kotlinJsWrappers = "0.0.1-pre.331-kotlin-1.6.20" +kotlinJsWrappers = "0.0.1-pre.334" kotlinx-html = "0.7.5" kotlinx-nodejs = "0.0.7" kotlinx-coroutines = "1.6.1" @@ -32,7 +33,7 @@ ktor = "2.0.1" ## test ## junit = "5.8.2" -kotest = "5.2.3" +kotest = "5.3.0" ## infra ## factorio = "1.1.57" @@ -144,10 +145,10 @@ junit-launcher = { group = "org.junit.platform", name = "junit-platform-launcher ## kotest ## kotest-bom = { group = "io.kotest", name = "kotest-bom", version.ref = "kotest" } -kotest-core = { group = "io.kotest", name = "kotest-assertions-core-jvm", version.ref = "kotest" } +kotest-core = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" } kotest-datatest = { group = "io.kotest", name = "kotest-framework-datatest", version.ref = "kotest" } -kotest-runner = { group = "io.kotest", name = "kotest-runner-junit5-jvm", version.ref = "kotest" } -kotest-prop = { group = "io.kotest", name = "kotest-property-jvm", version.ref = "kotest" } +kotest-runner = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" } +kotest-prop = { group = "io.kotest", name = "kotest-property", version.ref = "kotest" } kotest-json = { group = "io.kotest", name = "kotest-assertions-json", version.ref = "kotest" } ## http4k ## diff --git a/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt new file mode 100644 index 0000000..6a2a044 --- /dev/null +++ b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionBoundsTest.kt @@ -0,0 +1,98 @@ +package dev.adamko.kafkatorio.schema.common + +import io.kotest.assertions.asClue +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.ints.shouldBeExactly + +class MapChunkPositionBoundsTest : FunSpec({ + + context("create bounds") { + + context("MapChunkPosition(0, 0)") { + + context("chunk size 32") { + + val chunkPos = MapChunkPosition(0, 0) + val bounds = MapChunkPositionBounds(chunkPos, ChunkSize.CHUNK_032) + + test("leftTop should be 0,0") { + bounds.leftTop.asClue { + it.x shouldBeExactly 0 + it.y shouldBeExactly 0 + } + } + + test("rightBottom should be 31,31") { + bounds.rightBottom.asClue { + it.x shouldBeExactly 31 + it.y shouldBeExactly 31 + } + } + } + } + + context("chunk size 256") { + + val chunkPos = MapChunkPosition(0, 0) + val bounds = MapChunkPositionBounds(chunkPos, ChunkSize.CHUNK_256) + + test("leftTop should be 0,0") { + bounds.leftTop.asClue { + it.x shouldBeExactly 0 + it.y shouldBeExactly 0 + } + } + + test("rightBottom should be 255,255") { + bounds.rightBottom.asClue { + it.x shouldBeExactly 255 + it.y shouldBeExactly 255 + } + } + } + } + + context("MapChunkPosition(-10, -10)") { + + context("chunk size 32") { + + val chunkPos = MapChunkPosition(-10, -10) + val bounds = MapChunkPositionBounds(chunkPos, ChunkSize.CHUNK_032) + + test("leftTop should be -320,-320") { + bounds.leftTop.asClue { + it.x shouldBeExactly -320 + it.y shouldBeExactly -320 + } + } + + test("rightBottom should be -289,-289") { + bounds.rightBottom.asClue { + it.x shouldBeExactly -289 + it.y shouldBeExactly -289 + } + } + } + + context("chunk size 256") { + + val chunkPos = MapChunkPosition(-10, -10) + val bounds = MapChunkPositionBounds(chunkPos, ChunkSize.CHUNK_256) + + test("leftTop should be -2560") { + bounds.leftTop.asClue { + it.x shouldBeExactly -2560 + it.y shouldBeExactly -2560 + } + } + + test("rightBottom should be (-2560 + 255)") { + bounds.rightBottom.asClue { + it.x shouldBeExactly (-2560 + 255) + it.y shouldBeExactly (-2560 + 255) + } + } + } + } + +}) diff --git a/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionTest.kt b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionTest.kt new file mode 100644 index 0000000..99cfdc7 --- /dev/null +++ b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapChunkPositionTest.kt @@ -0,0 +1,81 @@ +package dev.adamko.kafkatorio.schema.common + +import io.kotest.core.spec.style.FunSpec +import io.kotest.datatest.withData +import io.kotest.matchers.shouldBe +import io.kotest.property.Arb +import io.kotest.property.arbitrary.arbitrary +import io.kotest.property.arbitrary.int +import io.kotest.property.checkAll + +class MapChunkPositionTest : FunSpec({ + + context("check MapChunkPosition.contains()") { + + context("MapChunkPosition(0, 0)") { + + val chunkPos = MapChunkPosition(0, 0) + + test("should contain tiles from (0,0) to (31,31)") { + checkAll(mapTilePositionArb(0..31)) { tilePos -> + (tilePos in chunkPos) shouldBe true + } + } + + test("should not contain tiles below (0,0)") { + checkAll( + mapTilePositionArb(-1000..-1) + ) { tilePos -> + (tilePos in chunkPos) shouldBe false + } + } + + test("should not contain tiles above (31,31)") { + checkAll( + mapTilePositionArb(32..100) + ) { tilePos -> + (tilePos in chunkPos) shouldBe false + } + } + } + context("MapChunkPosition(-10, -10)") { + + val chunkPos = MapChunkPosition(-10, -10) + + test("should contain tiles from (-320,-320) to (-289,-289)") { + checkAll(mapTilePositionArb(-320..-289)) { tilePos -> + (tilePos in chunkPos) shouldBe true + } + } + + test("should not contain tiles below (-320,-320)") { + checkAll( + mapTilePositionArb(-400..-321) + ) { tilePos -> + (tilePos in chunkPos) shouldBe false + } + } + + test("should not contain tiles above (-289,-289)") { + checkAll( + mapTilePositionArb(-288..100) + ) { tilePos -> + (tilePos in chunkPos) shouldBe false + } + } + } + } + + +}) { + companion object { + fun mapTilePositionArb( + range: IntRange = -1000..1000 + ) = arbitrary { + MapTilePosition( + Arb.int(range).bind(), + Arb.int(range).bind(), + ) + } + } +} diff --git a/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTilePositionTest.kt b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTilePositionTest.kt new file mode 100644 index 0000000..15dfddc --- /dev/null +++ b/modules/events-schema/src/commonTest/kotlin/dev/adamko/kafkatorio/schema/common/MapTilePositionTest.kt @@ -0,0 +1,43 @@ +package dev.adamko.kafkatorio.schema.common + +import dev.adamko.kafkatorio.schema.common.MapChunkPositionTest.Companion.mapTilePositionArb +import io.kotest.core.spec.style.FunSpec +import io.kotest.property.forAll + +class MapTilePositionTest : FunSpec({ + + context("comparison") { + + test("less than <") { + forAll( + mapTilePositionArb(), + mapTilePositionArb(1..100), + ) { tilePos, delta -> + tilePos < (tilePos + delta) + } + } + + test("less than or equal to <=") { + forAll(mapTilePositionArb()) { tilePos -> + tilePos <= (tilePos) + } + } + + test("greater than or equal to >=") { + forAll(mapTilePositionArb()) { tilePos -> + tilePos >= (tilePos) + } + } + + test("greater than >") { + forAll( + mapTilePositionArb(), + mapTilePositionArb(1..100), + ) { tilePos, delta -> + tilePos > (tilePos - delta) + } + } + + } + +})