Initial commit
This commit is contained in:
commit
3304b53c41
38 changed files with 6573 additions and 0 deletions
27
tests/Unit/Picture/DoomPaletteTest.php
Normal file
27
tests/Unit/Picture/DoomPaletteTest.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Doom\Picture\DoomPalette;
|
||||
|
||||
test('provides a valid default doom palette', function (): void {
|
||||
$palette = DoomPalette::default();
|
||||
|
||||
expect($palette->toArray())->toHaveCount(256);
|
||||
expect($palette->colorAt(0))->toBe([0, 0, 0]);
|
||||
expect($palette->colorAt(1))->toBe([31, 23, 11]);
|
||||
});
|
||||
|
||||
test('extracts palette data from PLAYPAL bytes', function (): void {
|
||||
$palette0 = str_repeat("\x00\x00\x00", 256);
|
||||
$palette1 = str_repeat("\x10\x20\x30", 256);
|
||||
|
||||
$palette = DoomPalette::fromPlaypal($palette0 . $palette1, 1);
|
||||
|
||||
expect($palette->toArray())->toHaveCount(256);
|
||||
expect($palette->colorAt(0))->toBe([16, 32, 48]);
|
||||
expect($palette->colorAt(255))->toBe([16, 32, 48]);
|
||||
});
|
||||
|
||||
test('rejects invalid PLAYPAL palette selection', function (): void {
|
||||
expect(fn () => DoomPalette::fromPlaypal("\x00", 0))->toThrow(RuntimeException::class);
|
||||
expect(fn () => DoomPalette::fromPlaypal(str_repeat("\x00", 768), -1))->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
16
tests/Unit/Picture/PaletteTest.php
Normal file
16
tests/Unit/Picture/PaletteTest.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
use Doom\Picture\Palette;
|
||||
|
||||
test('creates palette from bytes and roundtrips', function (): void {
|
||||
$bytes = str_repeat("\x01\x02\x03", 256);
|
||||
$palette = Palette::fromBytes($bytes);
|
||||
|
||||
expect($palette->colorAt(0))->toBe([1, 2, 3]);
|
||||
expect($palette->colorAt(255))->toBe([1, 2, 3]);
|
||||
expect($palette->toBytes())->toBe($bytes);
|
||||
});
|
||||
|
||||
test('rejects invalid palette byte length', function (): void {
|
||||
expect(fn () => Palette::fromBytes("\x00"))->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue