Completed
Push — master ( 1b9d88...babdb1 )
by Siro Díaz
02:14
created

TrieTreeTest::testStartsWith()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use DataStructures\Trees\TrieTree;
5
6
7
class TrieTreeTest extends TestCase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
    private $tree;
9
10
    public function setUp() {
11
        $this->tree = new TrieTree();
12
    }
13
14 View Code Duplication
    public function testAdd() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
        $this->tree->add('hello');
16
        $this->tree->add('bye');
17
        $this->assertEquals(8, $this->tree->size());
18
        $this->tree->add('hello');
19
        $this->assertEquals(8, $this->tree->size());
20
        $this->tree->add('hell');
21
        $this->assertEquals(8, $this->tree->size());
22
    }
23
24 View Code Duplication
    public function testWordCount() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
        $this->tree->add('hello');
26
        $this->assertEquals(1, $this->tree->wordCount());
27
        $this->tree->add('bye');
28
        $this->assertEquals(2, $this->tree->wordCount());
29
        $this->tree->add('hello');
30
        $this->assertEquals(2, $this->tree->wordCount());
31
        $this->tree->add('hell');
32
        $this->assertEquals(3, $this->tree->wordCount());
33
    }
34
35
    public function testContains() {
36
        $this->tree->add('hello');
37
        $this->assertTrue($this->tree->contains('hello'));
38
        $this->tree->add('bye');
39
        $this->assertTrue($this->tree->contains('bye'));
40
        $this->assertFalse($this->tree->contains('what'));
41
    }
42
43
    public function testStartsWith() {
44
        $this->assertFalse($this->tree->startsWith('hello'));
45
        $this->tree->add('hello');
46
        $this->tree->add('bye');
47
        $this->assertTrue($this->tree->startsWith('b'));
48
        $this->assertTrue($this->tree->startsWith('hel'));
49
        $this->assertFalse($this->tree->startsWith('hellooo'));
50
    }
51
}