1 | <?php |
||
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 | } |