diff --git a/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php b/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php new file mode 100644 index 0000000..844f0bc --- /dev/null +++ b/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php @@ -0,0 +1,82 @@ + [-1], + 'zu gross' => [101], + ]; + } + + /** + * @return int[][] + */ + public function validPercentValueProvider(): array + { + return [ + 'niedrigster Wert' => [0], + 'mittlerer Wert' => [45], + 'maximaler Wert' => [100], + ]; + } + + /** + * @return int[][] + */ + public function invalidGradValueProvider(): array + { + return [ + 'zu klein' => [-1], + 'zu gross' => [361], + ]; + } + + /** + * @return int[][] + */ + public function validGradValueProvider(): array + { + return [ + 'niedrigster Wert' => [0], + 'mittlerer Wert' => [45], + 'maximaler Wert' => [360], + ]; + } + + /** + * @return int[][] + */ + public function invalidHexadecimalValueProvider(): array + { + return [ + 'zu klein' => [-0x1], + 'zu gross' => [0x100], + ]; + } + + /** + * @return int[][] + */ + public function validHexadecimalValueProvider(): array + { + return [ + 'niedrigster Wert' => [0x0], + 'mittlerer Wert' => [0xD9], + 'maximaler Wert' => [0xFF], + ]; + } + +} \ No newline at end of file diff --git a/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php new file mode 100644 index 0000000..5c2a8a5 --- /dev/null +++ b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php @@ -0,0 +1,128 @@ +assertIsInt($color->getCyan()); + $this->assertEquals(0, $color->getCyan()); + $this->assertIsInt($color->getMagenta()); + $this->assertEquals(0, $color->getMagenta()); + $this->assertIsInt($color->getCyan()); + $this->assertEquals(0, $color->getYellow()); + $this->assertIsInt($color->getKey()); + $this->assertEquals(0, $color->getKey()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetCyanWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setCyan($value); + $this->assertEquals($value, $color->getCyan()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetMagentaWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setMagenta($value); + $this->assertEquals($value, $color->getMagenta()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetYellowWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setYellow($value); + $this->assertEquals($value, $color->getYellow()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetKeyWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setKey($value); + $this->assertEquals($value, $color->getKey()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetCyanWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setCyan($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetMagentaWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setMagenta($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetYellowWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setYellow($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetKeyWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setKey($value); + } +} diff --git a/tests/unit/NaturallyColorModels/HueSaturationValueTest.php b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php new file mode 100644 index 0000000..614e254 --- /dev/null +++ b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php @@ -0,0 +1,100 @@ +assertIsInt($color->getHue()); + $this->assertEquals(0, $color->getHue()); + $this->assertIsInt($color->getSaturation()); + $this->assertEquals(0, $color->getSaturation()); + $this->assertIsInt($color->getValue()); + $this->assertEquals(100, $color->getValue()); + } + + /** + * @param int $value + * + * @dataProvider validGradValueProvider + */ + public function testSetHueWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setHue($value); + $this->assertEquals($value, $color->getHue()); + } + + /** + * @param int $value + * + * @dataProvider invalidGradValueProvider + */ + public function testSetHueWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setHue($value); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetSaturationWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setSaturation($value); + $this->assertEquals($value, $color->getSaturation()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetSaturationWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setSaturation($value); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetValueWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setValue($value); + $this->assertEquals($value, $color->getValue()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetValueWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setValue($value); + } +} diff --git a/tests/unit/NaturallyColorModels/RedGreenBlueTest.php b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php new file mode 100644 index 0000000..f33cb1a --- /dev/null +++ b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php @@ -0,0 +1,109 @@ +assertEquals(0xFF, $color->getRed()); + $this->assertEquals(0xFF, $color->getGreen()); + $this->assertEquals(0xFF, $color->getBlue()); + } + + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetRedWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setRed($value); + $this->assertEquals($value, $color->getRed()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetRedWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setRed($value); + } + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetGreenWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setGreen($value); + $this->assertEquals($value, $color->getGreen()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetGreenWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setGreen($value); + } + + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetBlueWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setBlue($value); + $this->assertEquals($value, $color->getBlue()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetBlueWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setBlue($value); + } + + public function testHtmlNotation(): void + { + $color = new RedGreenBlue(); + $color->setRed(0xA1); + $color->setGreen(0xB2); + $color->setBlue(0xC3); + + $html = $color->asHtmlNotation(); + + $this->assertIsString($html); + $this->assertEquals('#A1B2C3', $html); + } +}