chore: complete update
This commit is contained in:
59
tests/Domain/QrCode/ValueObject/GaloisFieldTest.php
Normal file
59
tests/Domain/QrCode/ValueObject/GaloisFieldTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\QrCode\ValueObject\GaloisField;
|
||||
|
||||
test('GaloisField Arithmetik funktioniert korrekt', function () {
|
||||
$field = new GaloisField();
|
||||
|
||||
// Addition (XOR) Tests
|
||||
expect($field->add(0, 0))->toBe(0);
|
||||
expect($field->add(0, 1))->toBe(1);
|
||||
expect($field->add(1, 0))->toBe(1);
|
||||
expect($field->add(1, 1))->toBe(0);
|
||||
expect($field->add(15, 32))->toBe(47);
|
||||
|
||||
// Multiplikation Tests
|
||||
expect($field->multiply(0, 5))->toBe(0);
|
||||
expect($field->multiply(5, 0))->toBe(0);
|
||||
expect($field->multiply(1, 1))->toBe(1);
|
||||
expect($field->multiply(2, 3))->toBe(6);
|
||||
|
||||
// Division Tests
|
||||
expect($field->divide(0, 5))->toBe(0);
|
||||
expect($field->divide(5, 1))->toBe(5);
|
||||
expect($field->divide(6, 3))->toBe(2);
|
||||
|
||||
// Division durch Null sollte Exception werfen
|
||||
expect(fn() => $field->divide(5, 0))->toThrow(\DivisionByZeroError::class);
|
||||
|
||||
// Potenzen Tests
|
||||
expect($field->power(2, 0))->toBe(1); // 2^0 = 1
|
||||
expect($field->power(2, 1))->toBe(2); // 2^1 = 2
|
||||
expect($field->power(2, 2))->toBe(4); // 2^2 = 4
|
||||
expect($field->power(2, 3))->toBe(8); // 2^3 = 8
|
||||
});
|
||||
|
||||
test('GaloisField Tabellen sind korrekt initialisiert', function () {
|
||||
$field = new GaloisField();
|
||||
|
||||
$expTable = $field->getExpTable();
|
||||
$logTable = $field->getLogTable();
|
||||
|
||||
// Prüfe grundlegende Eigenschaften der Tabellen
|
||||
expect(count($expTable))->toBe(256);
|
||||
expect(count($logTable))->toBe(256);
|
||||
|
||||
// Prüfe spezifische Werte
|
||||
expect($expTable[0])->toBe(1);
|
||||
expect($expTable[1])->toBe(2);
|
||||
expect($expTable[2])->toBe(4);
|
||||
expect($expTable[3])->toBe(8);
|
||||
|
||||
// Prüfe Log-Tabelle
|
||||
expect($logTable[1])->toBe(0);
|
||||
expect($logTable[2])->toBe(1);
|
||||
expect($logTable[4])->toBe(2);
|
||||
expect($logTable[8])->toBe(3);
|
||||
});
|
||||
Reference in New Issue
Block a user