Erweiterung der Farbmodel-Tests. Dabei wurden mehrfach verwendete Methoden in eine eigene Klasse ausgelagert.
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\ColorModels;
|
||||
|
||||
/**
|
||||
* Definition des allgemeinen CMYK-Farbraumes. Die Werte für die eigenschaften sind reelle Zahlen von 0 bis einschließlich 1.
|
||||
* Ohne Änderung der Eigenschaften wird die Farbe *weiß* dargestellt.
|
||||
*/
|
||||
class CyanMagentaYellowKey extends AbstractColorModel
|
||||
{
|
||||
/** @var float : Definition des Cyan-Anteil */
|
||||
protected float $cyan = 0.0;
|
||||
/** @var float : Definition des Magenta-Anteil */
|
||||
protected float $magenta = 0.0;
|
||||
/** @var float : Definition des Gelbanteil */
|
||||
protected float $yellow = 0.0;
|
||||
/** @var float : Definition des Schwarzanteil */
|
||||
protected float $key = 0.0;
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCyan(): float
|
||||
{
|
||||
return $this->cyan;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $cyan
|
||||
* @return CyanMagentaYellowKey
|
||||
*/
|
||||
public function setCyan(float $cyan): CyanMagentaYellowKey
|
||||
{
|
||||
$this->checkValue($cyan);
|
||||
$this->cyan = $cyan;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getMagenta(): float
|
||||
{
|
||||
return $this->magenta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $magenta
|
||||
* @return CyanMagentaYellowKey
|
||||
*/
|
||||
public function setMagenta(float $magenta): CyanMagentaYellowKey
|
||||
{
|
||||
$this->checkValue($magenta);
|
||||
$this->magenta = $magenta;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getYellow(): float
|
||||
{
|
||||
return $this->yellow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $yellow
|
||||
* @return CyanMagentaYellowKey
|
||||
*/
|
||||
public function setYellow(float $yellow): CyanMagentaYellowKey
|
||||
{
|
||||
$this->checkValue($yellow);
|
||||
$this->yellow = $yellow;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getKey(): float
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $key
|
||||
* @return CyanMagentaYellowKey
|
||||
*/
|
||||
public function setKey(float $key): CyanMagentaYellowKey
|
||||
{
|
||||
$this->checkValue($key);
|
||||
$this->key = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
|
||||
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
|
||||
abstract class AbstractColorModelUnit extends Unit
|
||||
{
|
||||
|
||||
abstract public function testConstruct();
|
||||
|
||||
/**
|
||||
* @return float[][]
|
||||
*/
|
||||
public function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'zu klein' => [-0.1],
|
||||
'zu gross' => [1.1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[][]
|
||||
*/
|
||||
public function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'niedrigster Wert' => [0.0],
|
||||
'mittlerer Wert' => [0.45],
|
||||
'maximaler Wert' => [1.0],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
|
||||
class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->assertEquals(0.0, $color->getCyan());
|
||||
$this->assertEquals(0.0, $color->getMagenta());
|
||||
$this->assertEquals(0.0, $color->getYellow());
|
||||
$this->assertEquals(0.0, $color->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetCyanWithValidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setCyan($value);
|
||||
$this->assertEquals($value, $color->getCyan());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithValidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setMagenta($value);
|
||||
$this->assertEquals($value, $color->getMagenta());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetYellowWithValidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setYellow($value);
|
||||
$this->assertEquals($value, $color->getYellow());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetKeyWithValidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setKey($value);
|
||||
$this->assertEquals($value, $color->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetCyanWithInvalidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setCyan($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithInvalidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setMagenta($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetYellowWithInvalidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setYellow($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetKeyWithInvalidValue(float $value)
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setKey($value);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueTest extends Unit
|
||||
class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
@@ -18,29 +17,6 @@ class RedGreenBlueTest extends Unit
|
||||
$this->assertEquals(1.0, $color->getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[][]
|
||||
*/
|
||||
public function invalidValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'zu klein' => [-0.1],
|
||||
'zu gross' => [1.1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[][]
|
||||
*/
|
||||
public function validValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'niedrigster Wert' => [0.0],
|
||||
'mittlerer Wert' => [0.45],
|
||||
'maximaler Wert' => [1.0],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user