mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-15 17:02:06 +01:00
Atomize DepthTest
This commit is contained in:
parent
423183bece
commit
727f305eda
1 changed files with 63 additions and 29 deletions
|
@ -6,6 +6,7 @@ package org.pgpainless.wot.dijkstra
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import org.pgpainless.wot.dijkstra.sq.Depth
|
||||||
import org.pgpainless.wot.dijkstra.sq.Depth.Companion.auto
|
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.limited
|
||||||
import org.pgpainless.wot.dijkstra.sq.Depth.Companion.unconstrained
|
import org.pgpainless.wot.dijkstra.sq.Depth.Companion.unconstrained
|
||||||
|
@ -14,43 +15,54 @@ import kotlin.test.*
|
||||||
class DepthTest {
|
class DepthTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUnlimitedItem() {
|
fun `verify Depth#unconstrained() is in fact unconstrained`() {
|
||||||
val depth = unconstrained()
|
val depth = unconstrained()
|
||||||
assert(depth.isUnconstrained())
|
assert(depth.isUnconstrained())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify Depth#unconstrained() has null depth`() {
|
||||||
|
val depth = unconstrained()
|
||||||
assertNull(depth.limit)
|
assertNull(depth.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLimitedItem() {
|
fun `verify Depth#limited(2) initializes properly`() {
|
||||||
val limited = limited(2)
|
val limited = limited(2)
|
||||||
assertFalse(limited.isUnconstrained())
|
|
||||||
assertNotNull(limited.limit)
|
assertNotNull(limited.limit)
|
||||||
assertEquals(2, limited.limit)
|
assertEquals(2, limited.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDecreaseUnconstrainedYieldsUnconstrained() {
|
fun `verify Depth#limited(X) is not unconstrained`() {
|
||||||
|
val limited = limited(1)
|
||||||
|
assertFalse(limited.isUnconstrained())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that decrease()ing an unconstrained Depth is an idempotent operation`() {
|
||||||
val unconstrained = unconstrained()
|
val unconstrained = unconstrained()
|
||||||
val decreased = unconstrained.decrease(20)
|
val decreased = unconstrained.decrease(20)
|
||||||
assertTrue(decreased.isUnconstrained())
|
assertTrue(decreased.isUnconstrained())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDecreaseLimitedYieldsDecreasedLimited() {
|
fun `verify that decrease()ing a limited Depth yields a properly decreased result`() {
|
||||||
val limited = limited(1)
|
val limited = limited(3)
|
||||||
val decreased = limited.decrease(1)
|
val decreased = limited.decrease(2)
|
||||||
assertFalse(decreased.isUnconstrained())
|
assertFalse(decreased.isUnconstrained())
|
||||||
assertEquals(0, decreased.limit)
|
assertEquals(1, decreased.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDecreaseLimitedTooMuchYieldsException() {
|
fun `verify that decrease()ing a Depth object by a value greater than its current value fails`() {
|
||||||
val limited = limited(0)
|
assertThrows<IllegalArgumentException> { limited(0).decrease(1) }
|
||||||
assertThrows<IllegalArgumentException> { limited.decrease(1) }
|
assertThrows<IllegalArgumentException> { limited(1).decrease(2) }
|
||||||
|
assertThrows<IllegalArgumentException> { limited(17).decrease(42) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCompareTo() {
|
fun `verify proper function of compareTo()`() {
|
||||||
val unlimited = unconstrained()
|
val unlimited = unconstrained()
|
||||||
val unlimited2 = unconstrained()
|
val unlimited2 = unconstrained()
|
||||||
val depth2 = limited(2)
|
val depth2 = limited(2)
|
||||||
|
@ -66,30 +78,51 @@ class DepthTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMin() {
|
fun `verify that min() of a Depth with itself yields itself`() {
|
||||||
val unlimited = unconstrained()
|
val limit = limited(17)
|
||||||
val limit2 = limited(2)
|
assertEquals(limit, limit.min(limit))
|
||||||
assertEquals(limit2, limit2.min(unlimited))
|
|
||||||
assertEquals(limit2, unlimited.min(limit2))
|
|
||||||
assertEquals(limit2, limit2.min(limit2))
|
|
||||||
assertEquals(unlimited, unlimited.min(unlimited))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAutoUnconstrained() {
|
fun `verify that min() of two limited values returns the smaller one`() {
|
||||||
val depth = auto(255)
|
val limit1 = limited(1)
|
||||||
assertTrue(depth.isUnconstrained())
|
val limit4 = limited(4)
|
||||||
|
|
||||||
|
assertEquals(limit1, limit1.min(limit4))
|
||||||
|
assertEquals(limit1, limit4.min(limit1))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAutoLimited() {
|
fun `verify that min() of a limited and an unconstrained value yields the limited value`() {
|
||||||
val depth = auto(120)
|
val limit0 = limited(0)
|
||||||
assertFalse(depth.isUnconstrained())
|
val limit1 = limited(1)
|
||||||
assertEquals(120, depth.limit)
|
assertEquals(limit0, unconstrained().min(limit0))
|
||||||
|
assertEquals(limit1, limit1.min(unconstrained()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOutOfBounds() {
|
fun `verify that the min() of unconstrained and unconstrained is unconstrained`() {
|
||||||
|
val unconstrained = unconstrained()
|
||||||
|
assertEquals(unconstrained, unconstrained.min(unconstrained))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that Depth#auto(255) yields an unconstrained Depth`() {
|
||||||
|
assertTrue { auto(255).isUnconstrained() }
|
||||||
|
assertNull(auto(255).limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that Depth#auto(X) for values from 0 to 254 yield limited Depth objects`() {
|
||||||
|
assertFalse { auto(0).isUnconstrained() }
|
||||||
|
assertFalse { auto(120).isUnconstrained() }
|
||||||
|
assertFalse { auto(254).isUnconstrained() }
|
||||||
|
|
||||||
|
assertNotNull(auto(42).limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `verify that depth values out of the range from 0 to 255 yield failures`() {
|
||||||
assertThrows<IllegalArgumentException> { limited(-1) }
|
assertThrows<IllegalArgumentException> { limited(-1) }
|
||||||
assertThrows<IllegalArgumentException> { limited(256) }
|
assertThrows<IllegalArgumentException> { limited(256) }
|
||||||
assertThrows<IllegalArgumentException> { auto(-1) }
|
assertThrows<IllegalArgumentException> { auto(-1) }
|
||||||
|
@ -97,12 +130,13 @@ class DepthTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testToStringUnconstrained() {
|
fun `verify that toString() of Depth#unconstrained() returns the String 'unconstrained'`() {
|
||||||
assertEquals("unconstrained", unconstrained().toString())
|
assertEquals("unconstrained", unconstrained().toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testToStringLimited() {
|
fun `verify that toString() of a limited Depth returns the String of its value`() {
|
||||||
assertEquals("1", limited(1).toString())
|
assertEquals("1", limited(1).toString())
|
||||||
|
assertEquals("42", limited(42).toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue