Skip to content

Commit

Permalink
added coarse grained builder/tree test
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink0r committed Oct 9, 2016
1 parent 6b2efca commit f3cc7a8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Unit/InternalNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class InternalNodeTest extends TestCase
{
private $internal_node;

protected function setUp()
{
$this->internal_node = new InternalNode(3, 5);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/LeafNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class LeafNodeTest extends TestCase
{
private $leaf_node;

protected function setUp()
{
$this->leaf_node = new LeafNode(7, 8, 2);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/RootNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class RootNodeTest extends TestCase
{
private $root_node;

protected function setUp()
{
$this->root_node = new RootNode;
Expand Down
56 changes: 56 additions & 0 deletions tests/Unit/SuffixTreeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Shrink0r\SuffixTree\Tests\Unit;

use Shrink0r\SuffixTree\Builder\SuffixTreeBuilder;
use Shrink0r\SuffixTree\Tests\Unit\TestCase;

class SuffixTreeTest extends TestCase
{
private $tree_builder;

protected function setUp()
{
$this->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' ]
]
];
}
}

0 comments on commit f3cc7a8

Please sign in to comment.