diff --git a/tests/unit/Transformer/HueSaturationValueTransformerTest.php b/tests/unit/Transformer/HueSaturationValueTransformerTest.php new file mode 100644 index 0000000..0c5a7b8 --- /dev/null +++ b/tests/unit/Transformer/HueSaturationValueTransformerTest.php @@ -0,0 +1,105 @@ +getValidColorValues([ + ValidColorValuesProvider::HSV, + ValidColorValuesProvider::CMYK, + ]); + } + + /** + * @return float[][][] + */ + public function validRgbValuesProvider(): array + { + return (new ValidColorValuesProvider())->getValidColorValues([ + ValidColorValuesProvider::HSV, + ValidColorValuesProvider::RGB, + ]); + } + + /** + * @param array $hsv + * @param array $rgb + * + * @dataProvider validRgbValuesProvider + * + * @throws Exception + */ + public function testToRedGreenBlue(array $hsv, array $rgb) + { + $this->color = $this->make(HueSaturationValue::class, $hsv); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toRedGreenBlue(); + + $this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA); + + } + + /** + * @param array $hsv + * @param array $cmyk + * + * @throws Exception + * @dataProvider validCmykValuesProvider + * + */ + public function testToCyanMagentaYellowKey(array $hsv, array $cmyk) + { + + $this->color = $this->make(HueSaturationValue::class, $hsv); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toCyanMagentaYellowKey(); + + $this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA); + } + + /** + * @param array $hsv + * @param array $cmyk + * + * @throws Exception + * + * @dataProvider validCmykValuesProvider + * + */ + public function testToHueSaturationValue(array $hsv, array $cmyk) + { + $this->color = $this->make(HueSaturationValue::class, $hsv); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toHueSaturationValue(); + + $this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA); + } +} diff --git a/tests/unit/Transformer/RedGreenBlueTransformerTest.php b/tests/unit/Transformer/RedGreenBlueTransformerTest.php new file mode 100644 index 0000000..67e2adf --- /dev/null +++ b/tests/unit/Transformer/RedGreenBlueTransformerTest.php @@ -0,0 +1,102 @@ +getValidColorValues([ + ValidColorValuesProvider::RGB, + ValidColorValuesProvider::CMYK, + ]); + } + + /** + * @return float[][][] + */ + public function validHsvValuesProvider(): array + { + return (new ValidColorValuesProvider())->getValidColorValues([ + ValidColorValuesProvider::RGB, + ValidColorValuesProvider::HSV, + ]); + } + + /** + * @param array $rgb + * + * @dataProvider validCmykValuesProvider + * + * @throws Exception + */ + public function testToRedGreenBlue(array $rgb) + { + $this->color = $this->make(RedGreenBlue::class, $rgb); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toRedGreenBlue(); + + $this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA); + + } + + /** + * @param array $rgb + * @param array $cmyk + * + * @throws Exception + * @dataProvider validCmykValuesProvider + * + */ + public function testToCyanMagentaYellowKey(array $rgb, array $cmyk) + { + + $this->color = $this->make(RedGreenBlue::class, $rgb); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toCyanMagentaYellowKey(); + + $this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA); + } + + /** + * @param array $rgb + * @param array $hsv + * + * @throws Exception + * @dataProvider validHsvValuesProvider + */ + public function testToHueSaturationValue(array $rgb, array $hsv) + { + $this->color = $this->make(RedGreenBlue::class, $rgb); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toHueSaturationValue(); + + $this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA); + $this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA); + } +}