1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-11 15:54:04 +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:
Daniel St. Jules
2013-08-24 11:19:33 -04:00
parent 454e8e2f87
commit 11f961cae6
2 changed files with 24 additions and 4 deletions

View File

@@ -292,10 +292,20 @@ class StaticStringyTestCase extends CommonTest
*/
public function testShuffle($str, $encoding = null)
{
// We'll just make sure that the chars are present before/after shuffle
$result = S::shuffle($str, $encoding);
$encoding = $encoding ?: mb_internal_encoding();
$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);
}
}
/**

View File

@@ -347,12 +347,22 @@ class StringyTestCase extends CommonTest
*/
public function testShuffle($str, $encoding = null)
{
// We'll just make sure that the chars are present before/after shuffle
$stringy = S::create($str, $encoding);
$encoding = $encoding ?: mb_internal_encoding();
$result = $stringy->shuffle();
$this->assertInstanceOf('Stringy\Stringy', $result);
$this->assertEquals(count_chars($str), count_chars($result));
$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);
}
}
/**