Skip to content

Commit

Permalink
Add tests for ColorspaceInterface::colorFromNormalized()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 2, 2023
1 parent 5f5cc9e commit 714f514
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/Colors/Cmyk/ColorspaceTest.php
Expand Up @@ -18,6 +18,17 @@
*/
class ColorspaceTest extends TestCase
{
public function testColorFromNormalized(): void
{
$colorspace = new Colorspace();
$result = $colorspace->colorFromNormalized([0, 1, 0, 1]);
$this->assertInstanceOf(CmykColor::class, $result);
$this->assertEquals(0, $result->channel(Cyan::class)->value());
$this->assertEquals(100, $result->channel(Magenta::class)->value());
$this->assertEquals(0, $result->channel(Yellow::class)->value());
$this->assertEquals(100, $result->channel(Key::class)->value());
}

public function testImportRgbColor(): void
{
$colorspace = new Colorspace();
Expand Down
10 changes: 10 additions & 0 deletions tests/Colors/Hsl/ColorspaceTest.php
Expand Up @@ -17,6 +17,16 @@
*/
class ColorspaceTest extends TestCase
{
public function testColorFromNormalized(): void
{
$colorspace = new Colorspace();
$result = $colorspace->colorFromNormalized([1, 0, 1]);
$this->assertInstanceOf(HslColor::class, $result);
$this->assertEquals(360, $result->channel(Hue::class)->value());
$this->assertEquals(0, $result->channel(Saturation::class)->value());
$this->assertEquals(100, $result->channel(Luminance::class)->value());
}

public function testImportRgbColor(): void
{
$colorspace = new Colorspace();
Expand Down
10 changes: 10 additions & 0 deletions tests/Colors/Hsv/ColorspaceTest.php
Expand Up @@ -17,6 +17,16 @@
*/
class ColorspaceTest extends TestCase
{
public function testColorFromNormalized(): void
{
$colorspace = new Colorspace();
$result = $colorspace->colorFromNormalized([1, 0, 1]);
$this->assertInstanceOf(HsvColor::class, $result);
$this->assertEquals(360, $result->channel(Hue::class)->value());
$this->assertEquals(0, $result->channel(Saturation::class)->value());
$this->assertEquals(100, $result->channel(Value::class)->value());
}

public function testImportRgbColor(): void
{
$colorspace = new Colorspace();
Expand Down
13 changes: 13 additions & 0 deletions tests/Colors/Rgb/ColorspaceTest.php
Expand Up @@ -9,6 +9,7 @@
use Intervention\Image\Colors\Rgb\Channels\Red;
use Intervention\Image\Colors\Rgb\Color as RgbColor;
use Intervention\Image\Colors\Hsl\Color as HslColor;
use Intervention\Image\Colors\Rgb\Channels\Alpha;
use Intervention\Image\Colors\Rgb\Colorspace;
use Intervention\Image\Tests\TestCase;

Expand All @@ -17,6 +18,18 @@
*/
class ColorspaceTest extends TestCase
{
public function testColorFromNormalized(): void
{
$colorspace = new Colorspace();

$result = $colorspace->colorFromNormalized([1, 0, 1, 1]);
$this->assertInstanceOf(RgbColor::class, $result);
$this->assertEquals(255, $result->channel(Red::class)->value());
$this->assertEquals(0, $result->channel(Green::class)->value());
$this->assertEquals(255, $result->channel(Blue::class)->value());
$this->assertEquals(255, $result->channel(Alpha::class)->value());
}

public function testImportCmykColor(): void
{
$colorspace = new Colorspace();
Expand Down

0 comments on commit 714f514

Please sign in to comment.