From 11f961cae6f224d6892dac90164892823c90d425 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Sat, 24 Aug 2013 11:19:33 -0400 Subject: [PATCH] Fixed testShuffle. It now tests that each mb char has the same number of occurrences before and after --- tests/Stringy/StaticStringyTest.php | 14 ++++++++++++-- tests/Stringy/StringyTest.php | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/Stringy/StaticStringyTest.php b/tests/Stringy/StaticStringyTest.php index 7ceae44..e20f738 100644 --- a/tests/Stringy/StaticStringyTest.php +++ b/tests/Stringy/StaticStringyTest.php @@ -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); + } } /** diff --git a/tests/Stringy/StringyTest.php b/tests/Stringy/StringyTest.php index d6ab75b..0b2ce8e 100644 --- a/tests/Stringy/StringyTest.php +++ b/tests/Stringy/StringyTest.php @@ -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); + } } /**