diff --git a/src/ColorModels/AbstractColorModel.php b/src/ColorModels/AbstractColorModel.php new file mode 100644 index 0000000..5db61f3 --- /dev/null +++ b/src/ColorModels/AbstractColorModel.php @@ -0,0 +1,21 @@ + 1.0) { + throw new InvalidArgumentException('Ein Wert größer als 1 ist nicht definierbar.'); + } + if ($value < 0.0) { + throw new InvalidArgumentException('Ein Wert kleiner als 0 ist nicht definierbar.'); + } + } + +} \ No newline at end of file diff --git a/src/ColorModels/RedGreenBlue.php b/src/ColorModels/RedGreenBlue.php new file mode 100644 index 0000000..f38e7e1 --- /dev/null +++ b/src/ColorModels/RedGreenBlue.php @@ -0,0 +1,75 @@ +red; + } + + /** + * @param float $red + * @return RedGreenBlue + */ + public function setRed(float $red): RedGreenBlue + { + $this->checkValue($red); + $this->red = $red; + return $this; + } + + /** + * @return float + */ + public function getGreen(): float + { + return $this->green; + } + + /** + * @param float $green + * @return RedGreenBlue + */ + public function setGreen(float $green): RedGreenBlue + { + $this->checkValue($green); + $this->green = $green; + return $this; + } + + /** + * @return float + */ + public function getBlue(): float + { + return $this->blue; + } + + /** + * @param float $blue + * @return RedGreenBlue + */ + public function setBlue(float $blue): RedGreenBlue + { + $this->checkValue($blue); + $this->blue = $blue; + return $this; + } + +} \ No newline at end of file diff --git a/tests/unit/ColorModels/RedGreenBlueTest.php b/tests/unit/ColorModels/RedGreenBlueTest.php new file mode 100644 index 0000000..b06e964 --- /dev/null +++ b/tests/unit/ColorModels/RedGreenBlueTest.php @@ -0,0 +1,120 @@ +assertEquals(1.0, $color->getRed()); + $this->assertEquals(1.0, $color->getGreen()); + $this->assertEquals(1.0, $color->getBlue()); + } + + /** + * @return float[][] + */ + public function invalidValueProvider(): array + { + return [ + 'zu klein' => [-0.1], + 'zu gross' => [1.1], + ]; + } + + /** + * @return float[][] + */ + public function validValueProvider(): array + { + return [ + 'niedrigster Wert' => [0.0], + 'mittlerer Wert' => [0.45], + 'maximaler Wert' => [1.0], + ]; + } + + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetRedWithValidValue(float $value) + { + $color = new RedGreenBlue(); + + $color->setRed($value); + $this->assertEquals($value, $color->getRed()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetRedWithInvalidValue(float $value) + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setRed($value); + } + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetGreenWithValidValue(float $value) + { + $color = new RedGreenBlue(); + + $color->setGreen($value); + $this->assertEquals($value, $color->getGreen()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetGreenWithInvalidValue(float $value) + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setGreen($value); + } + + /** + * @param float $value + * + * @dataProvider validValueProvider + */ + public function testSetBlueWithValidValue(float $value) + { + $color = new RedGreenBlue(); + + $color->setBlue($value); + $this->assertEquals($value, $color->getBlue()); + } + + /** + * @param float $value + * + * @dataProvider invalidValueProvider + */ + public function testSetBlueWithInvalidValue(float $value) + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setBlue($value); + } +}