Completed
Push — master ( 4b3449...8131a6 )
by Siro Díaz
01:20
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
lcom 1
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DataStructures\Tests\Sets;
4
5
use DataStructures\Sets\{DisjointNode, DisjointSet};
6
use PHPUnit\Framework\TestCase;
7
8
class DisjointSetTest extends TestCase {
9
    private $set;
10
11
    public function setUp() {
12
        $this->set = new DisjointSet();
13
    }
14
15
    public function testMakeSet() {
16
        $sets = [];
17
        $sets[] = $this->set->makeSet('hello');
18
        $sets[] = $this->set->makeSet('goodbye');
19
        $this->assertEquals($sets[0], $this->set->makeSet('hello'));
20
        $this->assertEquals($sets[1], $this->set->makeSet('goodbye'));
21
    }
22
23
    public function testUnion() {
24
        $sets = [];
25
        $sets[] = $this->set->makeSet('hello');
26
        $sets[] = $this->set->makeSet('goodbye');
27
        $sets[] = $this->set->makeSet([true, 3.14]);
28
29
        $this->set->union($sets[0], $sets[1]);
30
        $this->set->union($sets[0], $sets[0]);
31
        $this->assertEquals($sets[1], $this->set->find($sets[0]));
32
        $this->set->union($sets[0], $sets[2]);
33
        $this->assertEquals($sets[1], $this->set->find($sets[2]));
34
    }
35
}