diff --git a/tests/Unit/InternalNodeTest.php b/tests/Unit/InternalNodeTest.php index dbf9273..ee30ae1 100644 --- a/tests/Unit/InternalNodeTest.php +++ b/tests/Unit/InternalNodeTest.php @@ -7,6 +7,8 @@ class InternalNodeTest extends TestCase { + private $internal_node; + protected function setUp() { $this->internal_node = new InternalNode(3, 5); diff --git a/tests/Unit/LeafNodeTest.php b/tests/Unit/LeafNodeTest.php index 339e31f..8707804 100644 --- a/tests/Unit/LeafNodeTest.php +++ b/tests/Unit/LeafNodeTest.php @@ -7,6 +7,8 @@ class LeafNodeTest extends TestCase { + private $leaf_node; + protected function setUp() { $this->leaf_node = new LeafNode(7, 8, 2); diff --git a/tests/Unit/RootNodeTest.php b/tests/Unit/RootNodeTest.php index 654146b..9a1e691 100644 --- a/tests/Unit/RootNodeTest.php +++ b/tests/Unit/RootNodeTest.php @@ -7,6 +7,8 @@ class RootNodeTest extends TestCase { + private $root_node; + protected function setUp() { $this->root_node = new RootNode; diff --git a/tests/Unit/SuffixTreeTest.php b/tests/Unit/SuffixTreeTest.php new file mode 100644 index 0000000..60d1700 --- /dev/null +++ b/tests/Unit/SuffixTreeTest.php @@ -0,0 +1,56 @@ +tree_builder = new SuffixTreeBuilder; + } + + /** + * @dataProvider provideFlowFixtures + */ + public function testOverallFlow(string $s, string $lrs, array $suffix, array $substring) + { + $suffix_tree = $this->tree_builder->build($s); + $this->assertEquals($lrs, $suffix_tree->findLongestRepetition()); + $this->assertTrue($suffix_tree->hasSuffix($suffix['true'])); + $this->assertFalse($suffix_tree->hasSuffix($suffix['false'])); + $this->assertTrue($suffix_tree->hasSubstring($substring['true'])); + $this->assertFalse($suffix_tree->hasSubstring($substring['false'])); + } + + /** + * @codeCoverageIgnore + */ + public static function provideFlowFixtures() + { + return [ + [ + 's' => 'mississippi$', + 'lrs' => 'issi', + 'suffix' => [ 'true' => 'sippi$', 'false' => 'miss$' ], + 'substring' => [ 'true' => 'iss', 'false' => 'issm' ] + ], + [ + 's' => 'GEEKSFORGEEKS$', + 'lrs' => 'GEEKS', + 'suffix' => [ 'true' => 'EKS$', 'false' => 'GE$' ], + 'substring' => [ 'true' => 'EEK', 'false' => 'SKG' ] + ], + [ + 's' => 'xabxac$', + 'lrs' => 'xa', + 'suffix' => [ 'true' => 'ac$', 'false' => 'xa$' ], + 'substring' => [ 'true' => 'bxa', 'false' => 'cba' ] + ] + ]; + } +}