1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-25 22:20:50 +02:00

Added longestCommonSubstring

This commit is contained in:
Daniel St. Jules
2013-07-27 02:47:58 -04:00
parent aeef5493c0
commit 332ceb4224
6 changed files with 107 additions and 8 deletions

View File

@@ -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() {

View File

@@ -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);
}
}

View File

@@ -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);
}
}