Skip to content

Commit

Permalink
Re-added BidirectionalMap tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
abouzerda committed Jun 27, 2024
1 parent dd10d46 commit 6033021
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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<Int, Int>

/** Fills BidirectionalMap with pairs (0,1) and (2,3) before tests. */
@BeforeEach
fun setUp() {
map = BidirectionalMap(Pair(0, 1), Pair(2, 3))
}
}
Original file line number Diff line number Diff line change
@@ -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<NoSuchElementException> { 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<NoSuchElementException> { 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))
}
}

0 comments on commit 6033021

Please sign in to comment.