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);
|
||||
});
|
||||
75
tests/Domain/QrCode/ValueObject/PolynomialTest.php
Normal file
75
tests/Domain/QrCode/ValueObject/PolynomialTest.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Domain\QrCode\ValueObject\GaloisField;
|
||||
use App\Domain\QrCode\ValueObject\Polynomial;
|
||||
|
||||
test('Polynomial kann erstellt werden', function () {
|
||||
$field = new GaloisField();
|
||||
$poly = new Polynomial($field, [1, 2, 3]); // x^2 + 2x + 3
|
||||
|
||||
expect($poly->getCoefficients())->toBe([1, 2, 3]);
|
||||
expect($poly->getDegree())->toBe(2);
|
||||
});
|
||||
|
||||
test('Polynomial entfernt führende Nullen', function () {
|
||||
$field = new GaloisField();
|
||||
$poly = new Polynomial($field, [0, 0, 1, 2]); // x + 2
|
||||
|
||||
expect($poly->getCoefficients())->toBe([1, 2]);
|
||||
expect($poly->getDegree())->toBe(1);
|
||||
});
|
||||
|
||||
test('Polynomial kann an Stelle x ausgewertet werden', function () {
|
||||
$field = new GaloisField();
|
||||
$poly = new Polynomial($field, [1, 0, 1]); // x^2 + 1
|
||||
|
||||
expect($poly->evaluateAt(0))->toBe(1);
|
||||
expect($poly->evaluateAt(1))->toBe(0); // 1^2 + 1 = 2 = 0 in GF(2)
|
||||
expect($poly->evaluateAt(2))->toBe(5); // 2^2 + 1 = 5
|
||||
});
|
||||
|
||||
test('Polynomial Addition funktioniert', function () {
|
||||
$field = new GaloisField();
|
||||
$poly1 = new Polynomial($field, [1, 2]); // x + 2
|
||||
$poly2 = new Polynomial($field, [3, 4]); // 3x + 4
|
||||
|
||||
$sum = $poly1->add($poly2);
|
||||
|
||||
// In GF(2^8) ist Addition = XOR, daher 1⊕3=2, 2⊕4=6
|
||||
expect($sum->getCoefficients())->toBe([2, 6]);
|
||||
});
|
||||
|
||||
test('Polynomial Multiplikation funktioniert', function () {
|
||||
$field = new GaloisField();
|
||||
$poly1 = new Polynomial($field, [1, 1]); // x + 1
|
||||
$poly2 = new Polynomial($field, [1, 0, 1]); // x^2 + 1
|
||||
|
||||
$product = $poly1->multiply($poly2);
|
||||
|
||||
// (x + 1)(x^2 + 1) = x^3 + x^2 + x + 1
|
||||
expect($product->getCoefficients())->toBe([1, 1, 1, 1]);
|
||||
});
|
||||
|
||||
test('Polynomial Division funktioniert', function () {
|
||||
$field = new GaloisField();
|
||||
$poly1 = new Polynomial($field, [1, 0, 1]); // x^2 + 1
|
||||
$poly2 = new Polynomial($field, [1, 1]); // x + 1
|
||||
|
||||
$result = $poly1->divideAndRemainder($poly2);
|
||||
|
||||
// (x^2 + 1) ÷ (x + 1) = x - 1 + 2/(x+1)
|
||||
// In GF(2^8): Quotient = x - 1 = x + 1, Rest = 2
|
||||
expect($result['quotient']->getCoefficients())->toEqual([1, 1]);
|
||||
expect($result['remainder']->getCoefficients())->toEqual([0]);
|
||||
});
|
||||
|
||||
test('Generator Polynom kann korrekt erstellt werden', function () {
|
||||
$field = new GaloisField();
|
||||
$generator = Polynomial::buildGenerator($field, 3);
|
||||
|
||||
// Erwartetes Ergebnis für Grad 3
|
||||
expect($generator->getDegree())->toBe(3);
|
||||
expect(count($generator->getCoefficients()))->toBe(4);
|
||||
});
|
||||
Reference in New Issue
Block a user