|
| 1 | +package io.github.jadarma.aockt.test.internal |
| 2 | + |
| 3 | +import io.github.jadarma.aockt.core.Solution |
| 4 | +import io.github.jadarma.aockt.test.AdventDay |
| 5 | +import io.github.jadarma.aockt.test.AdventSpec |
| 6 | +import io.kotest.assertions.withClue |
| 7 | +import io.kotest.core.spec.SpecRef |
| 8 | +import io.kotest.core.spec.style.FunSpec |
| 9 | +import io.kotest.matchers.collections.shouldContainInOrder |
| 10 | +import io.kotest.matchers.shouldBe |
| 11 | +import io.kotest.property.Arb |
| 12 | +import io.kotest.property.arbitrary.shuffle |
| 13 | +import io.kotest.property.checkAll |
| 14 | + |
| 15 | +class SpecOrdererTest : FunSpec({ |
| 16 | + |
| 17 | + test("Orders specs correctly") { |
| 18 | + val otherSpecs = listOf(OtherA::class, OtherB::class).map(SpecRef::Reference) |
| 19 | + val adventSpecs = listOf( |
| 20 | + SpecA::class, SpecB::class, SpecC::class, SpecD::class, |
| 21 | + SpecE::class, SpecF::class, SpecG::class, SpecH::class, |
| 22 | + ).map(SpecRef::Reference) |
| 23 | + val allSpecs: List<SpecRef> = adventSpecs + otherSpecs |
| 24 | + |
| 25 | + checkAll(iterations = 128, Arb.shuffle(allSpecs)) { discoveryOrder -> |
| 26 | + val otherOrder = discoveryOrder.filter { it in otherSpecs } |
| 27 | + val sortedOrder = discoveryOrder.sortedWith(SpecOrderer) |
| 28 | + |
| 29 | + withClue("Sorting changed the relative order of non-AdventSpecs") { |
| 30 | + sortedOrder.shouldContainInOrder(otherOrder) |
| 31 | + } |
| 32 | + |
| 33 | + withClue("Final sort order is incorrect.") { |
| 34 | + val expectedOrder = otherOrder + adventSpecs |
| 35 | + sortedOrder.shouldBe(expectedOrder) |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +}) |
| 40 | + |
| 41 | +// Some inactive specs to test with. |
| 42 | +private class OtherA : FunSpec() |
| 43 | +private class OtherB : FunSpec() |
| 44 | + |
| 45 | +@AdventDay(3000, 1) |
| 46 | +private class SpecA : AdventSpec<Solution>() |
| 47 | + |
| 48 | +@AdventDay(3000, 1, variant = "default") |
| 49 | +private class SpecB : AdventSpec<Solution>() |
| 50 | + |
| 51 | +@AdventDay(3000, 1, title = "A") |
| 52 | +private class SpecC : AdventSpec<Solution>() |
| 53 | + |
| 54 | +@AdventDay(3000, 1, title = "A", variant = "custom") |
| 55 | +private class SpecD : AdventSpec<Solution>() |
| 56 | + |
| 57 | +@AdventDay(3000, 1, title = "A", variant = "dumb") |
| 58 | +private class SpecE : AdventSpec<Solution>() |
| 59 | + |
| 60 | +@AdventDay(3000, 1, title = "B") |
| 61 | +private class SpecF : AdventSpec<Solution>() |
| 62 | + |
| 63 | +@AdventDay(3000, 2) |
| 64 | +private class SpecG : AdventSpec<Solution>() |
| 65 | + |
| 66 | +@AdventDay(3001, 1) |
| 67 | +private class SpecH : AdventSpec<Solution>() |
0 commit comments