32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Purchase;
|
|
|
|
use App\Domains\Purchase\Services\DniDistanceService;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DniDistanceServiceTest extends TestCase
|
|
{
|
|
/** @return iterable<string, array{string, string, int}> */
|
|
public static function distances(): iterable
|
|
{
|
|
yield 'exact' => ['40123456', '40123456', 0];
|
|
yield 'leading transposition' => ['40123456', '04123456', 1];
|
|
yield 'trailing transposition' => ['40123456', '40123465', 1];
|
|
yield 'single substitution' => ['40123456', '40123856', 1];
|
|
yield 'substitution and transposition' => ['12345678', '12345087', 2];
|
|
yield 'seven digits normalized with leading zero' => ['04123456', '4123456', 0];
|
|
yield 'more than two edits' => ['40123456', '87654321', 7];
|
|
}
|
|
|
|
#[DataProvider('distances')]
|
|
public function test_it_calculates_damerau_levenshtein_distance(
|
|
string $left,
|
|
string $right,
|
|
int $expected,
|
|
): void {
|
|
$this->assertSame($expected, (new DniDistanceService)->distance($left, $right));
|
|
}
|
|
}
|