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

DisjointSetTest::testUnion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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