Completed
Push — master ( b56f02...42e858 )
by Siro Díaz
07:58
created

DisjointSetTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testMakeSet() 0 7 1
A testUnion() 0 12 1
1
<?php
2
3
use DataStructures\Sets\{DisjointNode, DisjointSet};
4
use PHPUnit\Framework\TestCase;
5
6
class DisjointSetTest 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...
7
    private $set;
8
9
    public function setUp() {
10
        $this->set = new DisjointSet();
11
    }
12
13
    public function testMakeSet() {
14
        $sets = [];
15
        $sets[] = $this->set->makeSet('hello');
16
        $sets[] = $this->set->makeSet('goodbye');
17
        $this->assertEquals($sets[0], $this->set->makeSet('hello'));
18
        $this->assertEquals($sets[1], $this->set->makeSet('goodbye'));
19
    }
20
21
    public function testUnion() {
22
        $sets = [];
23
        $sets[] = $this->set->makeSet('hello');
24
        $sets[] = $this->set->makeSet('goodbye');
25
        $sets[] = $this->set->makeSet([true, 3.14]);
26
27
        $this->set->union($sets[0], $sets[1]);
28
        $this->set->union($sets[0], $sets[0]);
29
        $this->assertEquals($sets[1], $this->set->find($sets[0]));
30
        $this->set->union($sets[0], $sets[2]);
31
        $this->assertEquals($sets[1], $this->set->find($sets[2]));
32
    }
33
}