Tests für die erweiterten Umwandlung-Klassen geschrieben.

This commit is contained in:
2021-03-09 13:59:28 +01:00
parent c832f0344c
commit 692b8fa1c8
2 changed files with 207 additions and 0 deletions
@@ -0,0 +1,105 @@
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
namespace TorstenHettstedtUnitTests\Colors\Transformer;
use Codeception\Test\Unit;
use Exception;
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\Transformer\HueSaturationValueTransformer;
class HueSaturationValueTransformerTest extends Unit
{
const FLOAT_DELTA = 0.001;
protected HueSaturationValue $color;
/**
* @return float[][][]
*/
public function validCmykValuesProvider(): array
{
return (new ValidColorValuesProvider())->getValidColorValues([
ValidColorValuesProvider::HSV,
ValidColorValuesProvider::CMYK,
]);
}
/**
* @return float[][][]
*/
public function validRgbValuesProvider(): array
{
return (new ValidColorValuesProvider())->getValidColorValues([
ValidColorValuesProvider::HSV,
ValidColorValuesProvider::RGB,
]);
}
/**
* @param array $hsv
* @param array $rgb
*
* @dataProvider validRgbValuesProvider
*
* @throws Exception
*/
public function testToRedGreenBlue(array $hsv, array $rgb)
{
$this->color = $this->make(HueSaturationValue::class, $hsv);
$transformer = new HueSaturationValueTransformer($this->color);
$color = $transformer->toRedGreenBlue();
$this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA);
}
/**
* @param array $hsv
* @param array $cmyk
*
* @throws Exception
* @dataProvider validCmykValuesProvider
*
*/
public function testToCyanMagentaYellowKey(array $hsv, array $cmyk)
{
$this->color = $this->make(HueSaturationValue::class, $hsv);
$transformer = new HueSaturationValueTransformer($this->color);
$color = $transformer->toCyanMagentaYellowKey();
$this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA);
}
/**
* @param array $hsv
* @param array $cmyk
*
* @throws Exception
*
* @dataProvider validCmykValuesProvider
*
*/
public function testToHueSaturationValue(array $hsv, array $cmyk)
{
$this->color = $this->make(HueSaturationValue::class, $hsv);
$transformer = new HueSaturationValueTransformer($this->color);
$color = $transformer->toHueSaturationValue();
$this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA);
}
}
@@ -0,0 +1,102 @@
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
namespace TorstenHettstedtUnitTests\Colors\Transformer;
use Codeception\Test\Unit;
use Exception;
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
use TorstenHettstedt\Colors\Transformer\RedGreenBlueTransformer;
class RedGreenBlueTransformerTest extends Unit
{
const FLOAT_DELTA = 0.001;
protected RedGreenBlue $color;
/**
* @return float[][][]
*/
public function validCmykValuesProvider(): array
{
return (new ValidColorValuesProvider())->getValidColorValues([
ValidColorValuesProvider::RGB,
ValidColorValuesProvider::CMYK,
]);
}
/**
* @return float[][][]
*/
public function validHsvValuesProvider(): array
{
return (new ValidColorValuesProvider())->getValidColorValues([
ValidColorValuesProvider::RGB,
ValidColorValuesProvider::HSV,
]);
}
/**
* @param array $rgb
*
* @dataProvider validCmykValuesProvider
*
* @throws Exception
*/
public function testToRedGreenBlue(array $rgb)
{
$this->color = $this->make(RedGreenBlue::class, $rgb);
$transformer = new RedGreenBlueTransformer($this->color);
$color = $transformer->toRedGreenBlue();
$this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA);
}
/**
* @param array $rgb
* @param array $cmyk
*
* @throws Exception
* @dataProvider validCmykValuesProvider
*
*/
public function testToCyanMagentaYellowKey(array $rgb, array $cmyk)
{
$this->color = $this->make(RedGreenBlue::class, $rgb);
$transformer = new RedGreenBlueTransformer($this->color);
$color = $transformer->toCyanMagentaYellowKey();
$this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA);
}
/**
* @param array $rgb
* @param array $hsv
*
* @throws Exception
* @dataProvider validHsvValuesProvider
*/
public function testToHueSaturationValue(array $rgb, array $hsv)
{
$this->color = $this->make(RedGreenBlue::class, $rgb);
$transformer = new RedGreenBlueTransformer($this->color);
$color = $transformer->toHueSaturationValue();
$this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA);
$this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA);
}
}