Tests für HSV hinzugefügt.

This commit is contained in:
2021-03-02 12:05:47 +01:00
parent 540929e893
commit e85c57c628
2 changed files with 125 additions and 0 deletions
@@ -5,6 +5,7 @@ namespace TorstenHettstedt\Colors\Transformer;
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
interface ColorModelTransformInterface
@@ -12,4 +13,6 @@ interface ColorModelTransformInterface
public function toRedGreenBlue(): RedGreenBlue;
public function toCyanMagentaYellowKey(): CyanMagentaYellowKey;
public function toHueSaturationValue(): HueSaturationValue;
}
@@ -112,6 +112,106 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
];
}
/**
* @return float[][][]
*/
public function validHsvValuesProvider(): array
{
return [
'weiß' => [
[
'cyan' => 0.0,
'magenta' => 0.0,
'yellow' => 0.0,
'key' => 0.0,
],
[
'hue' => 0.0,
'saturation' => 0.0,
'value' => 1.0,
]
],
'schwarz' => [
[
'cyan' => 0.0,
'magenta' => 0.0,
'yellow' => 0.0,
'key' => 1.0,
],
[
'hue' => 0.0,
'saturation' => 0.0,
'value' => 0.0,
]
],
'cyan' => [
[
'cyan' => 1.0,
'magenta' => 0.0,
'yellow' => 0.0,
'key' => 0.0,
],
[
'hue' => 0.5,
'saturation' => 1.0,
'value' => 1.0,
]
],
'magenta' => [
[
'cyan' => 0.0,
'magenta' => 1.0,
'yellow' => 0.0,
'key' => 0.0,
],
[
'hue' => 0.833,
'saturation' => 1.0,
'value' => 1.0,
]
],
'gelb' => [
[
'cyan' => 0.0,
'magenta' => 0.0,
'yellow' => 1.0,
'key' => 0.0,
],
[
'hue' => 0.167,
'saturation' => 1.0,
'value' => 1.0,
]
],
'gold' => [
[
'cyan' => 0.0,
'magenta' => 0.13,
'yellow' => 0.76,
'key' => 0.13,
],
[
'hue' => 0.139,
'saturation' => 0.76,
'value' => 0.87,
]
],
'violet' => [
[
'cyan' => 0.19,
'magenta' => 0.32,
'yellow' => 0.0,
'key' => 0.29,
],
[
'hue' => 0.733,
'saturation' => 0.32,
'value' => 0.71,
]
],
];
}
/**
* @param array $cmyk
* @param array $rgb
@@ -157,4 +257,26 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
$this->assertEquals($cmyk['yellow'], $color->getYellow());
$this->assertEquals($cmyk['key'], $color->getKey());
}
/**
* @param array $cmyk
* @param array $hsv
*
* @throws Exception
*
* @dataProvider validHsvValuesProvider
*
*/
public function testToHueSaturationValue(array $cmyk, array $hsv)
{
$this->color = $this->make(CyanMagentaYellowKey::class, $cmyk);
$transformer = new CyanMagentaYellowKeyTransformer($this->color);
$color = $transformer->toHueSaturationValue();
$this->assertEquals($hsv['hue'], $color->getHue());
$this->assertEquals($hsv['saturation'], $color->getSaturation());
$this->assertEquals($hsv['value'], $color->getValue());
}
}