mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-12 00:04:11 +02:00
Fixed testShuffle. It now tests that each mb char has the same number of occurrences before and after
This commit is contained in:
@@ -292,10 +292,20 @@ class StaticStringyTestCase extends CommonTest
|
|||||||
*/
|
*/
|
||||||
public function testShuffle($str, $encoding = null)
|
public function testShuffle($str, $encoding = null)
|
||||||
{
|
{
|
||||||
// We'll just make sure that the chars are present before/after shuffle
|
|
||||||
$result = S::shuffle($str, $encoding);
|
$result = S::shuffle($str, $encoding);
|
||||||
|
$encoding = $encoding ?: mb_internal_encoding();
|
||||||
|
|
||||||
$this->assertInternalType('string', $result);
|
$this->assertInternalType('string', $result);
|
||||||
$this->assertEquals(count_chars($str), count_chars($result));
|
$this->assertEquals(mb_strlen($str, $encoding),
|
||||||
|
mb_strlen($result, $encoding));
|
||||||
|
|
||||||
|
// We'll make sure that the chars are present after shuffle
|
||||||
|
for ($i = 0; $i < mb_strlen($str, $encoding); $i++) {
|
||||||
|
$char = mb_substr($str, $i, 1, $encoding);
|
||||||
|
$countBefore = mb_substr_count($str, $char, $encoding);
|
||||||
|
$countAfter = mb_substr_count($result, $char, $encoding);
|
||||||
|
$this->assertEquals($countBefore, $countAfter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -347,12 +347,22 @@ class StringyTestCase extends CommonTest
|
|||||||
*/
|
*/
|
||||||
public function testShuffle($str, $encoding = null)
|
public function testShuffle($str, $encoding = null)
|
||||||
{
|
{
|
||||||
// We'll just make sure that the chars are present before/after shuffle
|
|
||||||
$stringy = S::create($str, $encoding);
|
$stringy = S::create($str, $encoding);
|
||||||
|
$encoding = $encoding ?: mb_internal_encoding();
|
||||||
$result = $stringy->shuffle();
|
$result = $stringy->shuffle();
|
||||||
|
|
||||||
$this->assertInstanceOf('Stringy\Stringy', $result);
|
$this->assertInstanceOf('Stringy\Stringy', $result);
|
||||||
$this->assertEquals(count_chars($str), count_chars($result));
|
|
||||||
$this->assertEquals($str, $stringy);
|
$this->assertEquals($str, $stringy);
|
||||||
|
$this->assertEquals(mb_strlen($str, $encoding),
|
||||||
|
mb_strlen($result, $encoding));
|
||||||
|
|
||||||
|
// We'll make sure that the chars are present after shuffle
|
||||||
|
for ($i = 0; $i < mb_strlen($str, $encoding); $i++) {
|
||||||
|
$char = mb_substr($str, $i, 1, $encoding);
|
||||||
|
$countBefore = mb_substr_count($str, $char, $encoding);
|
||||||
|
$countAfter = mb_substr_count($result, $char, $encoding);
|
||||||
|
$this->assertEquals($countBefore, $countAfter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user