From a5cc7e2d41a8a01b823d2461bab619f971d070aa Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 14 Oct 2023 14:42:27 +0200 Subject: [PATCH] Add channel tests --- tests/Colors/Cmyk/ChannelTest.php | 48 +++++++++++++++++++++++++++++++ tests/Colors/Rgb/ChannelTest.php | 47 ++++++++++++++++++++++++++++++ tests/Colors/Rgba/ChannelTest.php | 48 +++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 tests/Colors/Cmyk/ChannelTest.php create mode 100644 tests/Colors/Rgb/ChannelTest.php create mode 100644 tests/Colors/Rgba/ChannelTest.php diff --git a/tests/Colors/Cmyk/ChannelTest.php b/tests/Colors/Cmyk/ChannelTest.php new file mode 100644 index 00000000..44928abf --- /dev/null +++ b/tests/Colors/Cmyk/ChannelTest.php @@ -0,0 +1,48 @@ +assertInstanceOf(Channel::class, $channel); + } + + public function testValue(): void + { + $channel = new Channel(10); + $this->assertEquals(10, $channel->value()); + } + + public function testNormalize(): void + { + $channel = new Channel(100); + $this->assertEquals(1, $channel->normalize()); + $channel = new Channel(0); + $this->assertEquals(0, $channel->normalize()); + $channel = new Channel(20); + $this->assertEquals(.2, $channel->normalize()); + } + + public function testValidate(): void + { + $this->expectException(ColorException::class); + new Channel(101); + + $this->expectException(ColorException::class); + new Channel(-1); + } +} diff --git a/tests/Colors/Rgb/ChannelTest.php b/tests/Colors/Rgb/ChannelTest.php new file mode 100644 index 00000000..4cc2fadb --- /dev/null +++ b/tests/Colors/Rgb/ChannelTest.php @@ -0,0 +1,47 @@ +assertInstanceOf(Channel::class, $channel); + } + + public function testValue(): void + { + $channel = new Channel(10); + $this->assertEquals(10, $channel->value()); + } + + public function testNormalize(): void + { + $channel = new Channel(255); + $this->assertEquals(1, $channel->normalize()); + $channel = new Channel(0); + $this->assertEquals(0, $channel->normalize()); + $channel = new Channel(51); + $this->assertEquals(.2, $channel->normalize()); + } + + public function testValidate(): void + { + $this->expectException(ColorException::class); + new Channel(256); + + $this->expectException(ColorException::class); + new Channel(-1); + } +} diff --git a/tests/Colors/Rgba/ChannelTest.php b/tests/Colors/Rgba/ChannelTest.php new file mode 100644 index 00000000..a1144e40 --- /dev/null +++ b/tests/Colors/Rgba/ChannelTest.php @@ -0,0 +1,48 @@ +assertInstanceOf(Channel::class, $channel); + } + + public function testValue(): void + { + $channel = new Channel(10); + $this->assertEquals(10, $channel->value()); + } + + public function testNormalize(): void + { + $channel = new Channel(255); + $this->assertEquals(1, $channel->normalize()); + $channel = new Channel(0); + $this->assertEquals(0, $channel->normalize()); + $channel = new Channel(51); + $this->assertEquals(.2, $channel->normalize()); + } + + public function testValidate(): void + { + $this->expectException(ColorException::class); + new Channel(256); + + $this->expectException(ColorException::class); + new Channel(-1); + } +}