mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-08-25 22:20:50 +02:00
Added longestCommonSubstring
This commit is contained in:
@@ -499,6 +499,24 @@ class CommonTest extends PHPUnit_Framework_TestCase
|
||||
return $testData;
|
||||
}
|
||||
|
||||
public function stringsForLongestCommonSubstring()
|
||||
{
|
||||
$testData = array(
|
||||
array('foo', 'foobar', 'foo bar'),
|
||||
array('foo bar', 'foo bar', 'foo bar'),
|
||||
array('oo ', 'foo bar', 'boo far'),
|
||||
array('foo ba', 'foo bad', 'foo bar'),
|
||||
array('', 'foo bar', ''),
|
||||
array('fòô', 'fòôbàř', 'fòô bàř', 'UTF-8'),
|
||||
array('fòô bàř', 'fòô bàř', 'fòô bàř', 'UTF-8'),
|
||||
array(' bàř', 'fòô bàř', 'fòr bàř', 'UTF-8'),
|
||||
array(' ', 'toy car', 'fòô bàř', 'UTF-8'),
|
||||
array('', '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() {
|
||||
|
@@ -288,4 +288,14 @@ class StaticStringyTestCase extends CommonTest
|
||||
$result = S::longestCommonSuffix($str, $otherString, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
*/
|
||||
public function testLongestCommonSubstring($expected, $str, $otherString,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::longestCommonSubstring($str, $otherString, $encoding);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
@@ -281,13 +281,13 @@ class StringyTestCase extends CommonTest
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider stringsForLongestCommonSuffix
|
||||
* @dataProvider stringsForLongestCommonSubstring
|
||||
*/
|
||||
public function testLongestCommonSuffix($expected, $str, $otherString,
|
||||
$encoding = null)
|
||||
public function testLongestCommonSubstring($expected, $str, $otherString,
|
||||
$encoding = null)
|
||||
{
|
||||
$result = S::create($str, $encoding)
|
||||
->longestCommonSuffix($otherString);
|
||||
->longestCommonSubstring($otherString);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user