tests: zcam: Test all combinations of inversion methods
diff --git a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/Comparison.kt b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/Comparison.kt
index 2ab860f..0136a26 100644
--- a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/Comparison.kt
+++ b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/Comparison.kt
@@ -7,6 +7,8 @@
infix fun Double.approx(x: Double) = abs(this - x) <= TEST_EPSILON
-fun assertApprox(actual: Double, expected: Double) {
- assertTrue(actual approx expected, "Expected $expected, got $actual")
+fun assertApprox(actual: Double, expected: Double, comment: String? = null) {
+ val msgBase = "Expected $expected, got $actual"
+ val msg = if (comment != null) "$msgBase ($comment)" else msgBase
+ assertTrue(actual approx expected, msg)
}
diff --git a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/ZcamTests.kt b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/ZcamTests.kt
index 3316519..416a70e 100644
--- a/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/ZcamTests.kt
+++ b/src/commonTest/kotlin/dev/kdrag0n/colorkt/tests/ZcamTests.kt
@@ -48,11 +48,17 @@
assertApprox(Wz, 90.94725313)
}
- // Now invert it
- val inverted = zcam.toXyzAbs(Zcam.LuminanceSource.LIGHTNESS, Zcam.ChromaSource.COLORFULNESS)
- assertApprox(inverted.x, sample.x)
- assertApprox(inverted.y, sample.y)
- assertApprox(inverted.z, sample.z)
+ // Now invert it using all combinations of methods
+ val invertedResults = Zcam.LuminanceSource.values()
+ .flatMap { ls -> Zcam.ChromaSource.values().map { cs -> ls to cs } }
+ .map { (ls, cs) -> Triple(ls, cs, zcam.toXyzAbs(ls, cs)) }
+ invertedResults.forEach { (ls, cs, inverted) ->
+ val comment = "Inverted with $ls, $cs"
+ println("$ls $cs $inverted")
+ assertApprox(inverted.y, sample.y, comment)
+ assertApprox(inverted.x, sample.x, comment)
+ assertApprox(inverted.z, sample.z, comment)
+ }
}
}