1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-20 12:01:27 +02:00

Added length()

This commit is contained in:
Daniel St. Jules
2013-07-27 11:53:48 -04:00
parent 332ceb4224
commit 95e706fe31
6 changed files with 126 additions and 55 deletions

View File

@@ -517,6 +517,18 @@ class CommonTest extends PHPUnit_Framework_TestCase
return $testData;
}
public function stringsForLength()
{
$testData = array(
array(11, ' foo bar '),
array(1, 'f'),
array(0, ''),
array(7, 'fòô bàř', 'UTF-8')
);
return $testData;
}
// A test is required so as not to throw an error
// This is a lot cleaner than using PHPUnit's mocks to spy
public function test() {

View File

@@ -272,30 +272,39 @@ class StaticStringyTestCase extends CommonTest
/**
* @dataProvider stringsForLongestCommonPrefix
*/
public function testLongestCommonPrefix($expected, $str, $otherString,
public function testLongestCommonPrefix($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonPrefix($str, $otherString, $encoding);
$result = S::longestCommonPrefix($str, $otherStr, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForLongestCommonSuffix
*/
public function testLongestCommonSuffix($expected, $str, $otherString,
public function testLongestCommonSuffix($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonSuffix($str, $otherString, $encoding);
$result = S::longestCommonSuffix($str, $otherStr, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForLongestCommonSubstring
*/
public function testLongestCommonSubstring($expected, $str, $otherString,
public function testLongestCommonSubstring($expected, $str, $otherStr,
$encoding = null)
{
$result = S::longestCommonSubstring($str, $otherString, $encoding);
$result = S::longestCommonSubstring($str, $otherStr, $encoding);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForLength
*/
public function testLength($expected, $str, $encoding = null)
{
$result = S::length($str, $encoding);
$this->assertEquals($expected, $result);
}
}

View File

@@ -272,22 +272,31 @@ class StringyTestCase extends CommonTest
/**
* @dataProvider stringsForLongestCommonPrefix
*/
public function testLongestCommonPrefix($expected, $str, $otherString,
public function testLongestCommonPrefix($expected, $str, $otherStr,
$encoding = null)
{
$result = S::create($str, $encoding)
->longestCommonPrefix($otherString);
->longestCommonPrefix($otherStr);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForLongestCommonSubstring
*/
public function testLongestCommonSubstring($expected, $str, $otherString,
public function testLongestCommonSubstring($expected, $str, $otherStr,
$encoding = null)
{
$result = S::create($str, $encoding)
->longestCommonSubstring($otherString);
->longestCommonSubstring($otherStr);
$this->assertEquals($expected, $result);
}
/**
* @dataProvider stringsForLength
*/
public function testLength($expected, $str, $encoding = null)
{
$result = S::create($str, $encoding)->length();
$this->assertEquals($expected, $result);
}
}