1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-12 15:32:06 +01:00

Port wot-dijkstra tests

This commit is contained in:
Paul Schaub 2023-06-28 20:15:21 +02:00
parent 1c56bf177b
commit ee5201484c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 121 additions and 126 deletions

View file

@ -1,101 +0,0 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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());
}
}

View file

@ -1,25 +0,0 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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());
}
}

View file

@ -0,0 +1,98 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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<IllegalArgumentException> { 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<IllegalArgumentException> { limited(-1) }
assertThrows<IllegalArgumentException> { limited(256) }
assertThrows<IllegalArgumentException> { auto(-1) }
assertThrows<IllegalArgumentException> { auto(256) }
}
@Test
fun testToStringUnconstrained() {
assertEquals("unconstrained", unconstrained().toString())
}
@Test
fun testToStringLimited() {
assertEquals("1", limited(1).toString())
}
}

View file

@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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)
}
}