From dbd6f7006c4cd14699aba643832cbc429c2b36f1 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Sat, 20 Feb 2021 10:33:18 -0800 Subject: [PATCH] Start of a spec for layout panel arrangement validation. --- .../kotlin/baaahs/show/LayoutValidator.kt | 5 ++ .../kotlin/baaahs/show/LayoutValidatorSpec.kt | 63 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/commonMain/kotlin/baaahs/show/LayoutValidator.kt create mode 100644 src/commonTest/kotlin/baaahs/show/LayoutValidatorSpec.kt diff --git a/src/commonMain/kotlin/baaahs/show/LayoutValidator.kt b/src/commonMain/kotlin/baaahs/show/LayoutValidator.kt new file mode 100644 index 000000000..ccd1c9a39 --- /dev/null +++ b/src/commonMain/kotlin/baaahs/show/LayoutValidator.kt @@ -0,0 +1,5 @@ +package baaahs.show + +class LayoutValidator { + fun findInvalidRegions(tab: Tab): Set = TODO("not implemented") +} \ No newline at end of file diff --git a/src/commonTest/kotlin/baaahs/show/LayoutValidatorSpec.kt b/src/commonTest/kotlin/baaahs/show/LayoutValidatorSpec.kt new file mode 100644 index 000000000..9f5e05d65 --- /dev/null +++ b/src/commonTest/kotlin/baaahs/show/LayoutValidatorSpec.kt @@ -0,0 +1,63 @@ +package baaahs.show + +import baaahs.describe +import baaahs.gl.override +import baaahs.toBeSpecified +import ch.tutteli.atrium.api.fluent.en_GB.containsExactly +import ch.tutteli.atrium.api.fluent.en_GB.isEmpty +import ch.tutteli.atrium.api.verbs.expect +import org.spekframework.spek2.Spek + +object LayoutValidatorSpec : Spek({ + describe { + val layoutValidator by value { LayoutValidator() } + val tab by value { toBeSpecified() } + val invalidRegions by value { layoutValidator.findInvalidRegions(tab) } + + context("when all regions are single cells") { + override(tab) { tab(3, 3, "ABC DEF GHI") } + it("should return no invalid regions") { + expect(invalidRegions).isEmpty() + } + } + + context("when all regions are rectangular") { + override(tab) { tab(3, 3, "AAB AAC DDC") } + it("should return no invalid regions") { + expect(invalidRegions).isEmpty() + } + } + + context("when a region isn't rectangular") { + override(tab) { tab(3, 3, "AAB AEC DDC") } + it("should return the non-rectangular region") { + expect(invalidRegions).containsExactly("A") + } + } + + context("when multiple regions aren't rectangular") { + override(tab) { tab(3, 3, "AAB ADC DDC") } + it("should return the non-rectangular region") { + expect(invalidRegions).containsExactly("A", "D") + } + } + + context("when a region is non-contiguous") { + override(tab) { tab(3, 3, "AAB AAC DDA") } + it("should return the non-contiguous region") { + expect(invalidRegions).containsExactly("A") + } + } + } +}) + +fun tab(columns: Int, rows: Int, areas: String): Tab { + val areaNames = areas.filter { it != ' ' }.map { it.toString() } + if (areaNames.size != columns * rows) error("should be ${columns * rows} areas") + return Tab( + "Main", + Array(columns) { "1fr" }.toList(), + Array(rows) { "1fr" }.toList(), + areaNames.toList() + ) +} \ No newline at end of file