diff --git a/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/DepthTest.java b/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/DepthTest.java deleted file mode 100644 index 88dd0d50..00000000 --- a/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/DepthTest.java +++ /dev/null @@ -1,101 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Paul Schaub -// -// SPDX-License-Identifier: Apache-2.0 - -package org.pgpainless.wot.dijkstra.sq; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class DepthTest { - - @Test - public void testUnlimitedItem() { - Depth depth = Depth.unconstrained(); - assertTrue(depth.isUnconstrained()); - assertNull(depth.getLimit()); - } - - @Test - public void testLimitedItem() { - Depth limited = Depth.limited(2); - assertFalse(limited.isUnconstrained()); - assertNotNull(limited.getLimit()); - assertEquals(2, limited.getLimit()); - } - - @Test - public void testDecreaseUnconstrainedYieldsUnconstrained() { - Depth unconstrained = Depth.unconstrained(); - Depth decreased = unconstrained.decrease(20); - assertTrue(decreased.isUnconstrained()); - } - - @Test - public void testDecreaseLimitedYieldsDecreasedLimited() { - Depth limited = Depth.limited(1); - Depth decreased = limited.decrease(1); - assertFalse(decreased.isUnconstrained()); - assertEquals(0, decreased.getLimit()); - } - - @Test - public void testDecreaseLimitedTooMuchYieldsException() { - Depth limited = Depth.limited(0); - assertThrows(IllegalArgumentException.class, () -> limited.decrease(1)); - } - - @Test - public void testCompareTo() { - Depth unlimited = Depth.unconstrained(); - Depth unlimited2 = Depth.unconstrained(); - Depth depth2 = Depth.limited(2); - Depth depth2_ = Depth.limited(2); - Depth depth5 = Depth.limited(5); - - assertEquals(0, unlimited.compareTo(unlimited2)); - assertTrue(unlimited.compareTo(depth2) > 0); - assertTrue(unlimited.compareTo(depth5) > 0); - assertTrue(depth2.compareTo(unlimited) < 0); - assertTrue(depth2.compareTo(depth5) < 0); - assertTrue(depth5.compareTo(depth2) > 0); - assertEquals(0, depth2.compareTo(depth2_)); - } - - @Test - public void testAutoUnconstrained() { - Depth depth = Depth.auto(255); - assertTrue(depth.isUnconstrained()); - } - - @Test - public void testAutoLimited() { - Depth depth = Depth.auto(120); - assertFalse(depth.isUnconstrained()); - assertEquals(120, depth.getLimit()); - } - - @Test - public void testOutOfBounds() { - assertThrows(IllegalArgumentException.class, () -> Depth.limited(-1)); - assertThrows(IllegalArgumentException.class, () -> Depth.limited(256)); - assertThrows(IllegalArgumentException.class, () -> Depth.auto(-1)); - assertThrows(IllegalArgumentException.class, () -> Depth.auto(256)); - } - - @Test - public void testToStringUnconstrained() { - assertEquals("unconstrained", Depth.unconstrained().toString()); - } - - @Test - public void testToStringLimited() { - assertEquals("1", Depth.limited(1).toString()); - } -} diff --git a/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/NetworkTest.java b/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/NetworkTest.java deleted file mode 100644 index 14214622..00000000 --- a/wot-dijkstra/src/test/java/org/pgpainless/wot/dijkstra/sq/NetworkTest.java +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Paul Schaub -// -// SPDX-License-Identifier: Apache-2.0 - -package org.pgpainless.wot.dijkstra.sq; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class NetworkTest { - - @Test - public void testEmptyNetworkIsEmpty() { - ReferenceTime referenceTime = ReferenceTime.now(); - Network network = Network.empty(referenceTime); - - assertTrue(network.getNodes().isEmpty()); - assertTrue(network.getEdges().isEmpty()); - assertTrue(network.getReverseEdges().isEmpty()); - assertEquals(referenceTime, network.getReferenceTime()); - } - -} diff --git a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/DepthTest.kt b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/DepthTest.kt new file mode 100644 index 00000000..197849c6 --- /dev/null +++ b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/DepthTest.kt @@ -0,0 +1,98 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.wot.dijkstra + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import org.pgpainless.wot.dijkstra.sq.Depth.Companion.auto +import org.pgpainless.wot.dijkstra.sq.Depth.Companion.limited +import org.pgpainless.wot.dijkstra.sq.Depth.Companion.unconstrained +import kotlin.test.* + +class DepthTest { + + @Test + fun testUnlimitedItem() { + val depth = unconstrained() + assert(depth.isUnconstrained()) + assertNull(depth.limit) + } + + @Test + fun testLimitedItem() { + val limited = limited(2) + assertFalse(limited.isUnconstrained()) + assertNotNull(limited.limit) + assertEquals(2, limited.limit) + } + + @Test + fun testDecreaseUnconstrainedYieldsUnconstrained() { + val unconstrained = unconstrained() + val decreased = unconstrained.decrease(20) + assertTrue(decreased.isUnconstrained()) + } + + @Test + fun testDecreaseLimitedYieldsDecreasedLimited() { + val limited = limited(1) + val decreased = limited.decrease(1) + assertFalse(decreased.isUnconstrained()) + assertEquals(0, decreased.limit) + } + + @Test + fun testDecreaseLimitedTooMuchYieldsException() { + val limited = limited(0) + assertThrows { limited.decrease(1) } + } + + @Test + fun testCompareTo() { + val unlimited = unconstrained() + val unlimited2 = unconstrained() + val depth2 = limited(2) + val depth2_ = limited(2) + val depth5 = limited(5) + assertEquals(0, unlimited.compareTo(unlimited2)) + assertTrue(unlimited.compareTo(depth2) > 0) + assertTrue(unlimited.compareTo(depth5) > 0) + assertTrue(depth2.compareTo(unlimited) < 0) + assertTrue(depth2.compareTo(depth5) < 0) + assertTrue(depth5.compareTo(depth2) > 0) + assertEquals(0, depth2.compareTo(depth2_)) + } + + @Test + fun testAutoUnconstrained() { + val depth = auto(255) + assertTrue(depth.isUnconstrained()) + } + + @Test + fun testAutoLimited() { + val depth = auto(120) + assertFalse(depth.isUnconstrained()) + assertEquals(120, depth.limit) + } + + @Test + fun testOutOfBounds() { + assertThrows { limited(-1) } + assertThrows { limited(256) } + assertThrows { auto(-1) } + assertThrows { auto(256) } + } + + @Test + fun testToStringUnconstrained() { + assertEquals("unconstrained", unconstrained().toString()) + } + + @Test + fun testToStringLimited() { + assertEquals("1", limited(1).toString()) + } +} \ No newline at end of file diff --git a/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/NetworkTest.kt b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/NetworkTest.kt new file mode 100644 index 00000000..a20fe48b --- /dev/null +++ b/wot-dijkstra/src/test/kotlin/org/pgpainless/wot/dijkstra/NetworkTest.kt @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.wot.dijkstra + +import org.junit.jupiter.api.Test +import org.pgpainless.wot.dijkstra.sq.Network.Companion.empty +import org.pgpainless.wot.dijkstra.sq.ReferenceTime.Companion.now +import kotlin.test.assertEquals + +class NetworkTest { + + @Test + fun testEmptyNetworkIsEmpty() { + val referenceTime = now() + val network = empty(referenceTime) + assert(network.nodes.isEmpty()) + assert(network.edges.isEmpty()) + assert(network.reverseEdges.isEmpty()) + assertEquals(referenceTime, network.referenceTime) + } +} \ No newline at end of file