1: <?php
2: 3: 4: 5:
6: class QStringTest extends QUnitTestCaseBase {
7:
8: public function testLongestCommonSubsequence() {
9: $this->lcsCheckValueHelper("hello world", "world war 2", "world");
10: $this->lcsCheckValueHelper("what's up people", "what in the world is going on", "what");
11: $this->lcsCheckValueHelper("foo bar", "bar foo", "foo");
12:
13: $this->lcsCheckValueHelper("aaa", "aa", "aa");
14: $this->lcsCheckValueHelper("cc", "bbbbcccccc", "cc");
15: $this->lcsCheckValueHelper("ccc", "bcbb", "c");
16: $this->lcsCheckValueHelper("aaa", "b", null);
17: $this->lcsCheckValueHelper("", "bb", null);
18: $this->lcsCheckValueHelper("aa", "", null);
19: $this->lcsCheckValueHelper("", null, null);
20: $this->lcsCheckValueHelper(null, null, null);
21: }
22:
23: public function testEndsWithStartsWith() {
24: $this->assertTrue(QString::StartsWith("This is a test", "This"));
25: $this->assertFalse(QString::StartsWith("This is a test", "this"));
26: $this->assertTrue(QString::StartsWith("This is a test", "Thi"));
27: $this->assertFalse(QString::StartsWith("This is a test", "is a"));
28: $this->assertFalse(QString::StartsWith("This is a test", "X"));
29: $this->assertTrue(QString::StartsWith("This is a test", ""));
30:
31: $this->assertTrue(QString::EndsWith("This is a test", "test"));
32: $this->assertFalse(QString::EndsWith("This is a test", "Test"));
33: $this->assertTrue(QString::EndsWith("This is a test", "est"));
34: $this->assertFalse(QString::EndsWith("This is a test", "is a"));
35: $this->assertFalse(QString::EndsWith("This is a test", "X"));
36: $this->assertTrue(QString::EndsWith("This is a test", ""));
37: }
38:
39: private function lcsCheckValueHelper($str1, $str2, $strExpectedResult) {
40: $strResult = QString::LongestCommonSubsequence($str1, $str2);
41: $this->assertEquals($strExpectedResult, $strResult, "Longest common subsequence of '" . $str1 .
42: "' and '" . $str2 . "' is '" . $strResult . "'");
43: }
44: }