From abe163d09f0196c175607ee5caffe2fce9afc768 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 21 Jun 2024 10:37:56 +0200 Subject: [PATCH] Added tests (WIP, failing) --- composeApp/build.gradle.kts | 10 +++++- composeApp/proguard-rules.pro | 25 +++++++++++++ .../src/commonMain/kotlin/domain/clues.kt | 6 ++-- .../src/commonMain/kotlin/domain/grid.kt | 10 ++++-- .../src/commonTest/kotlin/domain/GameTest.kt | 6 ++++ .../kotlin/domain/NeighbourClueTest.kt | 36 +++++++++++++++++++ gradle/libs.versions.toml | 2 +- proguard-rules.pro | 13 ------- 8 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 composeApp/proguard-rules.pro create mode 100644 composeApp/src/commonTest/kotlin/domain/NeighbourClueTest.kt delete mode 100644 proguard-rules.pro diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index d2a2369..45bb8ec 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile plugins { + alias(libs.plugins.jetbrainsKotlinJvm) alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsCompose) @@ -20,6 +21,7 @@ kotlin { jvm("desktop") sourceSets { + val androidUnitTest by getting val desktopMain by getting val desktopTest by getting @@ -39,7 +41,7 @@ kotlin { desktopMain.dependencies { implementation(compose.desktop.currentOs) } - androidNativeTest.dependencies { + androidUnitTest.dependencies { implementation(kotlin("test")) implementation(libs.atrium) } @@ -102,6 +104,12 @@ compose.desktop { targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) packageName = "ch.dissem.yaep" packageVersion = "1.0.0" + + buildTypes.release.proguard { + configurationFiles.from(project.file("proguard-rules.pro")) + isEnabled.set(true) + obfuscate.set(true) + } } } } diff --git a/composeApp/proguard-rules.pro b/composeApp/proguard-rules.pro new file mode 100644 index 0000000..9dffddd --- /dev/null +++ b/composeApp/proguard-rules.pro @@ -0,0 +1,25 @@ +-libraryjars /jmods/java.base.jmod(!**.jar;!module-info.class) + +-keepclasseswithmembers public class MainKt { + public static void main(java.lang.String[]); +} + +-dontwarn kotlinx.coroutines.debug.* +-dontwarn kotlinx.datetime.** + +-keep class kotlin.** { *; } +-keep class kotlinx.coroutines.** { *; } +-keep class org.jetbrains.skia.** { *; } +-keep class org.jetbrains.skiko.** { *; } + +-ignorewarnings + +# Windows folders +-keep class com.sun.jna.* { *; } +-keepclassmembers class * extends com.sun.jna.* { public *; } + +-assumenosideeffects public class androidx.compose.runtime.ComposerKt { + void sourceInformation(androidx.compose.runtime.Composer,java.lang.String); + void sourceInformationMarkerStart(androidx.compose.runtime.Composer,int,java.lang.String); + void sourceInformationMarkerEnd(androidx.compose.runtime.Composer); +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/domain/clues.kt b/composeApp/src/commonMain/kotlin/domain/clues.kt index 0ffe13d..dadcabb 100644 --- a/composeApp/src/commonMain/kotlin/domain/clues.kt +++ b/composeApp/src/commonMain/kotlin/domain/clues.kt @@ -60,8 +60,10 @@ class TripletClue>(val a: Item, val b: Item, val c: Item< return false } - if (ia == ib) { - return true + if (ia != -1 && ic != -1) { + if (ia + 2 == ic || ia == ic + 2) { + return true + } } if (isNeighbourRuleViolated(ia, ib) || isNeighbourRuleViolated(ib, ic)) { diff --git a/composeApp/src/commonMain/kotlin/domain/grid.kt b/composeApp/src/commonMain/kotlin/domain/grid.kt index b5f3a2e..b98733d 100644 --- a/composeApp/src/commonMain/kotlin/domain/grid.kt +++ b/composeApp/src/commonMain/kotlin/domain/grid.kt @@ -32,7 +32,13 @@ fun List>>>.toGrid() = Grid( GameRow( category = row.first().itemType.companion, options = row, - cells = row.map { GameCell(selection = null, solution = it, options = row.toMutableList()) } + cells = row.map { + GameCell( + selection = null, + solution = it, + options = row.toMutableList() + ) + } ) } ) @@ -48,7 +54,7 @@ class GameCell>( class Item>( val itemType: C, - val symbol: String + val symbol: String = itemType.symbols.random() ) { constructor(itemType: C) : this(itemType, itemType.symbols.random()) diff --git a/composeApp/src/commonTest/kotlin/domain/GameTest.kt b/composeApp/src/commonTest/kotlin/domain/GameTest.kt index 19e7d21..575f64f 100644 --- a/composeApp/src/commonTest/kotlin/domain/GameTest.kt +++ b/composeApp/src/commonTest/kotlin/domain/GameTest.kt @@ -1,7 +1,10 @@ package domain import ch.tutteli.atrium.api.fluent.en_GB.feature +import ch.tutteli.atrium.api.fluent.en_GB.size +import ch.tutteli.atrium.api.fluent.en_GB.toBeLessThan import ch.tutteli.atrium.api.fluent.en_GB.toEqual +import ch.tutteli.atrium.api.fluent.en_GB.toHaveSize import ch.tutteli.atrium.api.verbs.expect import kotlin.test.Test @@ -13,6 +16,9 @@ class GameTest { expect(game) { feature(Game::areCategoriesValid).toEqual(true) feature(Game::areRulesViolated).toEqual(false) + feature(Game::clues) { + feature(List::size).toBeLessThan(30) + } } } diff --git a/composeApp/src/commonTest/kotlin/domain/NeighbourClueTest.kt b/composeApp/src/commonTest/kotlin/domain/NeighbourClueTest.kt new file mode 100644 index 0000000..c06010f --- /dev/null +++ b/composeApp/src/commonTest/kotlin/domain/NeighbourClueTest.kt @@ -0,0 +1,36 @@ +package domain + +import ch.tutteli.atrium.api.fluent.en_GB.feature +import ch.tutteli.atrium.api.fluent.en_GB.size +import ch.tutteli.atrium.api.fluent.en_GB.toBeLessThan +import ch.tutteli.atrium.api.fluent.en_GB.toEqual +import ch.tutteli.atrium.api.fluent.en_GB.toHaveSize +import ch.tutteli.atrium.api.verbs.expect +import domain.Item +import kotlin.test.Test + +class NeighbourClueTest { + @Test + fun `ensure actual neighbours are valid`() { + val size = 5 + val grid = ItemClass.randomClasses(size) + .map { + it.randomItems(size).map { item -> Item(item) } + } + .map { row -> + GameRow( + category = row.first().itemType.companion, + options = row, + cells = row.map { + GameCell( + selection = it, + solution = it, + options = mutableListOf() + ) + } + ) + } + + NeighbourClue(Item(Animals.ANT), Item(Profession.ASTRONAUT)) + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4bc2f1a..7e9f1dd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.5.0" +agp = "8.3.2" android-compileSdk = "34" android-minSdk = "24" android-targetSdk = "34" diff --git a/proguard-rules.pro b/proguard-rules.pro deleted file mode 100644 index 2345d65..0000000 --- a/proguard-rules.pro +++ /dev/null @@ -1,13 +0,0 @@ --libraryjars /jmods/java.base.jmod(!**.jar;!module-info.class) - --keepclasseswithmembers public class MainKt { - public static void main(java.lang.String[]); -} - --dontwarn kotlinx.coroutines.debug.* - --keep class kotlin.** { *; } --keep class kotlinx.coroutines.** { *; } --keep class org.jetbrains.skia.** { *; } --keep class org.jetbrains.skiko.** { *; } --dontwarn kotlinx.datetime.**