Completed
Push — master ( d060d7...4b3449 )
by Siro Díaz
02:14
created

DisjointSetTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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
}