Feature: natuerliche Werte #8
@@ -0,0 +1,82 @@
|
||||
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
|
||||
abstract class AbstractColorModelUnit extends Unit
|
||||
{
|
||||
|
||||
abstract public function testConstruct(): void;
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function invalidPercentValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'zu klein' => [-1],
|
||||
'zu gross' => [101],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function validPercentValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'niedrigster Wert' => [0],
|
||||
'mittlerer Wert' => [45],
|
||||
'maximaler Wert' => [100],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function invalidGradValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'zu klein' => [-1],
|
||||
'zu gross' => [361],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function validGradValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'niedrigster Wert' => [0],
|
||||
'mittlerer Wert' => [45],
|
||||
'maximaler Wert' => [360],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function invalidHexadecimalValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'zu klein' => [-0x1],
|
||||
'zu gross' => [0x100],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[][]
|
||||
*/
|
||||
public function validHexadecimalValueProvider(): array
|
||||
{
|
||||
return [
|
||||
'niedrigster Wert' => [0x0],
|
||||
'mittlerer Wert' => [0xD9],
|
||||
'maximaler Wert' => [0xFF],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
|
||||
|
||||
class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->assertIsInt($color->getCyan());
|
||||
$this->assertEquals(0, $color->getCyan());
|
||||
$this->assertIsInt($color->getMagenta());
|
||||
$this->assertEquals(0, $color->getMagenta());
|
||||
$this->assertIsInt($color->getCyan());
|
||||
$this->assertEquals(0, $color->getYellow());
|
||||
$this->assertIsInt($color->getKey());
|
||||
$this->assertEquals(0, $color->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetCyanWithValidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setCyan($value);
|
||||
$this->assertEquals($value, $color->getCyan());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithValidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setMagenta($value);
|
||||
$this->assertEquals($value, $color->getMagenta());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetYellowWithValidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setYellow($value);
|
||||
$this->assertEquals($value, $color->getYellow());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetKeyWithValidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$color->setKey($value);
|
||||
$this->assertEquals($value, $color->getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetCyanWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setCyan($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setMagenta($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetYellowWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setYellow($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetKeyWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setKey($value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
|
||||
|
||||
class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$this->assertIsInt($color->getHue());
|
||||
$this->assertEquals(0, $color->getHue());
|
||||
$this->assertIsInt($color->getSaturation());
|
||||
$this->assertEquals(0, $color->getSaturation());
|
||||
$this->assertIsInt($color->getValue());
|
||||
$this->assertEquals(100, $color->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validGradValueProvider
|
||||
*/
|
||||
public function testSetHueWithValidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$color->setHue($value);
|
||||
$this->assertEquals($value, $color->getHue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidGradValueProvider
|
||||
*/
|
||||
public function testSetHueWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setHue($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetSaturationWithValidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$color->setSaturation($value);
|
||||
$this->assertEquals($value, $color->getSaturation());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetSaturationWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setSaturation($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validPercentValueProvider
|
||||
*/
|
||||
public function testSetValueWithValidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$color->setValue($value);
|
||||
$this->assertEquals($value, $color->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidPercentValueProvider
|
||||
*/
|
||||
public function testSetValueWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setValue($value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$this->assertEquals(0xFF, $color->getRed());
|
||||
$this->assertEquals(0xFF, $color->getGreen());
|
||||
$this->assertEquals(0xFF, $color->getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetRedWithValidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$color->setRed($value);
|
||||
$this->assertEquals($value, $color->getRed());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetRedWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setRed($value);
|
||||
}
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetGreenWithValidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$color->setGreen($value);
|
||||
$this->assertEquals($value, $color->getGreen());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetGreenWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setGreen($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider validHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetBlueWithValidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$color->setBlue($value);
|
||||
$this->assertEquals($value, $color->getBlue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @dataProvider invalidHexadecimalValueProvider
|
||||
*/
|
||||
public function testSetBlueWithInvalidValue(int $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$color->setBlue($value);
|
||||
}
|
||||
|
||||
public function testHtmlNotation(): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
$color->setRed(0xA1);
|
||||
$color->setGreen(0xB2);
|
||||
$color->setBlue(0xC3);
|
||||
|
||||
$html = $color->asHtmlNotation();
|
||||
|
||||
$this->assertIsString($html);
|
||||
$this->assertEquals('#A1B2C3', $html);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user