Completed
Push — master ( 738d97...df22b0 )
by Siro Díaz
02:13
created

TrieTreeTest::testClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 11
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
52
    //TODO
53
    public function testWithPrefix() {
54
        $this->tree->add('hello');
55
        $this->tree->add('hell');
56
        $this->tree->add('bye');
57
        $this->tree->withPrefix('he');
58
        $this->assertEquals(3, $this->tree->wordCount());
59
    }
60
61 View Code Duplication
    public function testDelete() {
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...
62
        $this->tree->add('hellou');
63
        $this->tree->add('hell');
64
        $this->tree->add('yellow');
65
        $this->tree->delete('hellou');
66
        $this->assertEquals(2, $this->tree->wordCount());
67
        $this->assertFalse($this->tree->contains('hellou'));
68
        $this->assertTrue($this->tree->contains('hell'));
69
        $this->assertTrue($this->tree->contains('yellow'));
70
        $this->tree->delete('yellow');
71
        $this->assertEquals(4, $this->tree->size());
72
    }
73
74 View Code Duplication
    public function testClear() {
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...
75
        $this->tree->add('hellou');
76
        $this->tree->add('hell');
77
        $this->tree->add('yellow');
78
        $this->assertEquals(3, $this->tree->wordCount());
79
        $this->tree->clear();
80
        var_dump($this->tree);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($this->tree); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
81
        $this->assertFalse($this->tree->contains('hellou'));
82
        $this->assertFalse($this->tree->contains('hell'));
83
        $this->assertFalse($this->tree->contains('yellow'));
84
        $this->assertEquals(0, $this->tree->size());
85
    }
86
}