From 6033021b07332c231c9b5e6056cd2b57212a2d08 Mon Sep 17 00:00:00 2001 From: Amin Bouzerda Date: Thu, 27 Jun 2024 13:15:20 +0200 Subject: [PATCH] Re-added BidirectionalMap tests. --- .../tools/aqua/bgw/core/HexOrientation.kt} | 17 ++-- .../BidirectionalMapTestBase.kt | 34 ++++++++ .../bgw/util/bidirectionalmap/LookupTest.kt | 80 +++++++++++++++++++ .../aqua/bgw/util/bidirectionalmap/PutTest.kt | 0 4 files changed, 120 insertions(+), 11 deletions(-) rename bgw-gui/src/{main/kotlin/tools/aqua/bgw/style/BorderStyle.kt => jvmMain/kotlin/tools/aqua/bgw/core/HexOrientation.kt} (60%) create mode 100644 bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/BidirectionalMapTestBase.kt create mode 100644 bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/LookupTest.kt rename bgw-gui/src/{test => jvmTest}/kotlin/tools/aqua/bgw/util/bidirectionalmap/PutTest.kt (100%) diff --git a/bgw-gui/src/main/kotlin/tools/aqua/bgw/style/BorderStyle.kt b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/core/HexOrientation.kt similarity index 60% rename from bgw-gui/src/main/kotlin/tools/aqua/bgw/style/BorderStyle.kt rename to bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/core/HexOrientation.kt index 9b767d6d2..c2f885872 100644 --- a/bgw-gui/src/main/kotlin/tools/aqua/bgw/style/BorderStyle.kt +++ b/bgw-gui/src/jvmMain/kotlin/tools/aqua/bgw/core/HexOrientation.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 The BoardGameWork Authors + * Copyright 2024 The BoardGameWork Authors * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,15 +15,10 @@ * limitations under the License. */ -package tools.aqua.bgw.style +package tools.aqua.bgw.core -open class BorderStyle internal constructor(override val value: String = "") : StyleAttribute() { - override val key: String = "-fx-border-style" - - companion object { - val NONE = BorderStyle("none") - val DOTTED = BorderStyle("dotted") - val DASHED = BorderStyle("dashed") - val SOLID = BorderStyle("solid") - } +/** Enumeration class representing the orientation options for hexagonal grids and views. */ +enum class HexOrientation { + POINTY_TOP, + FLAT_TOP } diff --git a/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/BidirectionalMapTestBase.kt b/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/BidirectionalMapTestBase.kt new file mode 100644 index 000000000..1ce9bfffd --- /dev/null +++ b/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/BidirectionalMapTestBase.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2021-2024 The BoardGameWork Authors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tools.aqua.bgw.util.bidirectionalmap + +import org.junit.jupiter.api.BeforeEach +import tools.aqua.bgw.util.BidirectionalMap + +/** Test base for in BidirectionalMap. */ +open class BidirectionalMapTestBase { + + /** BidirectionalMap initially filled with pairs (0,1) and (2,3). */ + protected lateinit var map: BidirectionalMap + + /** Fills BidirectionalMap with pairs (0,1) and (2,3) before tests. */ + @BeforeEach + fun setUp() { + map = BidirectionalMap(Pair(0, 1), Pair(2, 3)) + } +} \ No newline at end of file diff --git a/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/LookupTest.kt b/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/LookupTest.kt new file mode 100644 index 000000000..e2ff3097d --- /dev/null +++ b/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/LookupTest.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2021-2023 The BoardGameWork Authors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tools.aqua.bgw.util.bidirectionalmap + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +/** Test lookup function in BidirectionalMap. */ +class LookupTest : BidirectionalMapTestBase() { + + /** Test forward lookup on existing element. */ + @Test + @DisplayName("Test forward lookup on existing element") + fun testForwardExisting() { + assertEquals(1, map.forward(0)) + assertEquals(1, map.forwardOrNull(0)) + } + + /** Test backward lookup on existing element. */ + @Test + @DisplayName("Test backward lookup on existing element") + fun testBackwardExisting() { + assertEquals(0, map.backward(1)) + assertEquals(0, map.backwardOrNull(1)) + } + + /** Test forward lookup on non-existing element. */ + @Test + @DisplayName("Test forward lookup on non-existing element") + fun testForwardNonExisting() { + assertThrows { map.forward(5) } + assertEquals(null, map.forwardOrNull(5)) + } + + /** Test backward lookup on non-existing element. */ + @Test + @DisplayName("Test backward lookup on non-existing element") + fun testBackwardNonExisting() { + assertThrows { map.backward(5) } + assertEquals(null, map.backwardOrNull(5)) + } + + /** Test keysForward of map. */ + @Test + @DisplayName("Test keysForward of map") + fun testKeysForward() { + val keys = map.keysForward + assertEquals(2, keys.size) + assertTrue(keys.contains(0)) + assertTrue(keys.contains(2)) + } + + /** Test keysBackward of map. */ + @Test + @DisplayName("Test keysBackward of map") + fun testKeysBackward() { + val keys = map.keysBackward + assertEquals(2, keys.size) + assertTrue(keys.contains(1)) + assertTrue(keys.contains(3)) + } +} diff --git a/bgw-gui/src/test/kotlin/tools/aqua/bgw/util/bidirectionalmap/PutTest.kt b/bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/PutTest.kt similarity index 100% rename from bgw-gui/src/test/kotlin/tools/aqua/bgw/util/bidirectionalmap/PutTest.kt rename to bgw-gui/src/jvmTest/kotlin/tools/aqua/bgw/util/bidirectionalmap/PutTest.kt