Skip to content

Commit 71c6702

Browse files
committed
add TODO for RGBCW JUnit test cases
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent d115ef6 commit 71c6702

1 file changed

Lines changed: 110 additions & 8 deletions

File tree

bundles/org.openhab.core/src/test/java/org/openhab/core/util/LightModelTest.java

Lines changed: 110 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,121 @@ public void testRgbcwDimming() {
584584

585585
/*
586586
* Nota Bene: in this case with rgbLinkedToBrightness == true the round trip setRGBx() followed
587-
* by getRGBx MUST return identical values, and the brightness MUST be adjusted.
587+
* by getRGBx MUST return (nearly) identical values, and the brightness MUST be adjusted.
588588
*/
589589
lsm.setRGBx(new double[] { 0.0, 100.0, 200.0, 20.0, 35.0 });
590590
PercentType brightness = lsm.getBrightness(true);
591591
assertNotNull(brightness);
592592
rgbcw = lsm.getRGBx();
593593
assertEquals(5, rgbcw.length);
594-
// TODO manually calculate the expected values and apply the assertions below
595-
// assertEquals(100.0, brightness.doubleValue(), 0.1);
596-
// assertEquals(0.0, rgbcw[0], 0.1);
597-
// assertEquals(100.0, rgbcw[1], 0.1);
598-
// assertEquals(200.0, rgbcw[2], 0.1);
599-
// assertEquals(20.0, rgbcw[3], 0.1);
600-
// assertEquals(35.0, rgbcw[4], 0.1);
594+
595+
// TODO implement the following test case assertions for brightness (B) and RGBCW (r, g, b, c, w)
596+
/*
597+
* assertEquals(B, brightness.doubleValue(), 0.1);
598+
* assertEquals(r, rgbcw[0], 0.1);
599+
* assertEquals(g, rgbcw[1], 0.1);
600+
* assertEquals(b, rgbcw[2], 0.1);
601+
* assertEquals(c, rgbcw[3], 0.1);
602+
* assertEquals(w, rgbcw[4], 0.1);
603+
*
604+
* RGBCW to HSB test cases
605+
*
606+
* For these tests, we assume RGBCW values are within the range 0–255, and HSB values are within the ranges: Hue
607+
* [0,360), Saturation [0, 100], and Brightness [0, 100].
608+
*
609+
* Standard conversion tests
610+
* These cases cover typical color scenarios, with input values for cool white (CW) and warm white (WW) to be
611+
* converted to HSB.
612+
*
613+
* Case: Primary Red
614+
* Input (RGBCW): (255, 0, 0, 0, 0)
615+
* Expected HSB: (0, 100, 100)
616+
*
617+
* Case: Bright White (warm)
618+
* Input (RGBCW): (0, 0, 0, 0, 255)
619+
* Expected HSB: Depends on implementation. Since it is a warm white, the HSB conversion must reflect its
620+
* position on the color temperature spectrum.
621+
*
622+
* Case: Mixed White (neutral)
623+
* Input (RGBCW): (0, 0, 0, 255, 255)
624+
* Expected HSB: The combined effect of cool and warm white should yield a neutral white, such as (0, 0, 100).
625+
*
626+
* Case: Pastel Color (low saturation)
627+
* Input (RGBCW): (100, 100, 0, 100, 100)
628+
* Expected HSB: The high CW and WW values should lead to a desaturated, brighter version of the yellow from the
629+
* RGB components. The saturation will be lower and the brightness higher than for a pure RGB yellow.
630+
*
631+
* Edge case and boundary tests
632+
* These cases test the limits of the conversion logic.
633+
*
634+
* Case: Black
635+
* Input (RGBCW): (0, 0, 0, 0, 0)
636+
* Expected HSB: (0, 0, 0) (Black). The hue and saturation are undefined, so a value of 0 is standard.
637+
*
638+
* Case: All channels max
639+
* Input (RGBCW): (255, 255, 255, 255, 255)
640+
* Expected HSB: (0, 0, 100) (White). The combination of all channels at full brightness should produce the
641+
* brightest possible white, with zero saturation.
642+
*
643+
* Case: Maximum RGB, zero white
644+
* Input (RGBCW): (255, 255, 255, 0, 0)
645+
* Expected HSB: (0, 0, 100) (White). The RGB channels alone should produce white at full brightness.
646+
*
647+
* Case: Mixed color with white
648+
* Input (RGBCW): (255, 0, 0, 0, 100)
649+
* Expected HSB: A less saturated, brighter red than pure RGB red. The Hue should remain at 0, but saturation
650+
* will decrease, and brightness will be higher.
651+
*
652+
* Case: Non-zero RGB with CW only
653+
* Input (RGBCW): (255, 0, 0, 100, 0)
654+
* Expected HSB: A less saturated, cooler red. Hue remains 0, saturation is lower, and brightness is higher. The
655+
* color temperature of the red will shift towards the cool white.
656+
*
657+
* HSB to RGBCW test cases
658+
* These tests confirm that the reverse conversion correctly determines the appropriate mix of RGB, CW, and WW
659+
* channels to produce the desired HSB color.
660+
*
661+
* Standard conversion tests
662+
*
663+
* Case: Primary Blue
664+
* Input (HSB): (240, 100, 100)
665+
* Expected RGBCW: (0, 0, 255, 0, 0). A pure, saturated color should only use the RGB channels.
666+
*
667+
* Case: Gray
668+
* Input (HSB): (0, 0, 50)
669+
* Expected RGBCW: Assuming the system uses white channels for brightness and desaturation, the gray should be
670+
* produced by a mix of CW and WW, with no RGB active: (0, 0, 0, 128, 128).
671+
*
672+
* Case: Pastel Green
673+
* Input (HSB): (120, 50, 75)
674+
* Expected RGBCW: The conversion should calculate a mix of green and white to achieve the desired brightness
675+
* and saturation. For instance, (0, 191, 0, 64, 64).
676+
*
677+
* Edge case and boundary tests
678+
*
679+
* Case: Full Bright White
680+
* Input (HSB): (0, 0, 100)
681+
* Expected RGBCW: (0, 0, 0, 255, 255). Maximum brightness and zero saturation should be achieved by using only
682+
* the white channels.
683+
*
684+
* Case: Black
685+
* Input (HSB): (0, 0, 0)
686+
* Expected RGBCW: (0, 0, 0, 0, 0). Black should result in all channels off.
687+
*
688+
* Case: Low Brightness, High Saturation
689+
* Input (HSB): (60, 100, 25)
690+
* Expected RGBCW: (64, 64, 0, 0, 0). The low brightness should mean the white channels are not used at all, and
691+
* only the RGB channels are used at a scaled-down value.
692+
*
693+
* Case: HSB with Cool White preference
694+
* Input (HSB): A color with a blue tint, e.g., (240, 50, 75).
695+
* Expected RGBCW: The conversion might be designed to leverage the cool white LED to create a cooler white
696+
* component, resulting in a higher CW value and lower WW. For example, a result like (0, 0, 191, 128, 0).
697+
*
698+
* Case: HSB with Warm White preference
699+
* Input (HSB): A color with a yellow/red tint, e.g., (30, 50, 75).
700+
* Expected RGBCW: Similarly, this conversion would prioritize the warm white LED to maintain the warmer color
701+
* temperature, possibly leading to a result like (191, 64, 0, 0, 128).
702+
*/
601703
}
602704
}

0 commit comments

Comments
 (0)