endtoend-test-psl/tests/Psl/Str/Byte/CompareTest.php

42 lines
992 B
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Str\Byte;
use PHPUnit\Framework\TestCase;
2019-12-26 23:10:57 +01:00
use Psl\Str\Byte;
2019-12-24 01:52:07 +01:00
class CompareTest extends TestCase
{
2019-12-26 23:10:57 +01:00
/**
* @dataProvider provideData
*/
public function testCompare(int $expected, string $str1, string $str2, ?int $length = null): void
{
$diff = Byte\compare($str1, $str2, $length);
if (0 === $expected) {
self::assertSame(0, $diff);
2020-01-02 00:31:28 +01:00
} elseif (0 > $expected) {
2019-12-26 23:10:57 +01:00
self::assertLessThanOrEqual(-1, $diff);
} else {
self::assertGreaterThanOrEqual(1, $diff);
}
}
public function provideData(): array
{
return [
[-1, 'Hello', 'hello'],
[1, 'hello', 'Hello'],
[0, 'Hello', 'Hello'],
[-1, 'Hello', 'helloo'],
[-1, 'Helloo', 'hello'],
[-1, 'Helloo', 'hello', 2],
[-1, 'Helloo', 'hello', 5],
[-1, 'Helloo', 'hello', 6],
];
}
2019-12-24 01:52:07 +01:00
}