From 692b8fa1c8cb75fb25835a9b2665001fc5ddbb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 9 Mar 2021 13:59:28 +0100 Subject: [PATCH] =?UTF-8?q?Tests=20f=C3=BCr=20die=20erweiterten=20Umwandlu?= =?UTF-8?q?ng-Klassen=20geschrieben.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HueSaturationValueTransformerTest.php | 105 ++++++++++++++++++ .../RedGreenBlueTransformerTest.php | 102 +++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 tests/unit/Transformer/HueSaturationValueTransformerTest.php create mode 100644 tests/unit/Transformer/RedGreenBlueTransformerTest.php 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); + } +}