From 540929e8930ec8da34335c177c5f3139e1ec5c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 2 Mar 2021 11:37:50 +0100 Subject: [PATCH] =?UTF-8?q?Eine=20Klasse=20f=C3=BCr=20das=20HSV-Farbmodel?= =?UTF-8?q?=20hinzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ColorModels/HueSaturationValue.php | 77 +++++++++++++++ .../ColorModels/HueSaturationValueTest.php | 97 +++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 src/ColorModels/HueSaturationValue.php create mode 100644 tests/unit/ColorModels/HueSaturationValueTest.php diff --git a/src/ColorModels/HueSaturationValue.php b/src/ColorModels/HueSaturationValue.php new file mode 100644 index 0000000..ccd8634 --- /dev/null +++ b/src/ColorModels/HueSaturationValue.php @@ -0,0 +1,77 @@ +hue; + } + + /** + * @param float $hue + * @return HueSaturationValue + */ + public function setHue(float $hue): HueSaturationValue + { + $this->checkValue($hue); + $this->hue = $hue; + return $this; + } + + /** + * @return float + */ + public function getSaturation(): float + { + return $this->saturation; + } + + /** + * @param float $saturation + * @return HueSaturationValue + */ + public function setSaturation(float $saturation): HueSaturationValue + { + $this->checkValue($saturation); + $this->saturation = $saturation; + return $this; + } + + /** + * @return float + */ + public function getValue(): float + { + return $this->value; + } + + /** + * @param float $value + * @return HueSaturationValue + */ + public function setValue(float $value): HueSaturationValue + { + $this->checkValue($value); + $this->value = $value; + return $this; + } + + +} \ No newline at end of file diff --git a/tests/unit/ColorModels/HueSaturationValueTest.php b/tests/unit/ColorModels/HueSaturationValueTest.php new file mode 100644 index 0000000..7a57300 --- /dev/null +++ b/tests/unit/ColorModels/HueSaturationValueTest.php @@ -0,0 +1,97 @@ +assertEquals(0.0, $color->getHue()); + $this->assertEquals(0.0, $color->getSaturation()); + $this->assertEquals(1.0, $color->getValue()); + } + + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetHueWithValidValue(float $value) + { + $color = new HueSaturationValue(); + + $color->setHue($value); + $this->assertEquals($value, $color->getHue()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetHueWithInvalidValue(float $value) + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setHue($value); + } + + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetSaturationWithValidValue(float $value) + { + $color = new HueSaturationValue(); + + $color->setSaturation($value); + $this->assertEquals($value, $color->getSaturation()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetSaturationWithInvalidValue(float $value) + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setSaturation($value); + } + + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetValueWithValidValue(float $value) + { + $color = new HueSaturationValue(); + + $color->setValue($value); + $this->assertEquals($value, $color->getValue()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetValueWithInvalidValue(float $value) + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setValue($value); + } +}