| 1 | <?php |
||
| 6 | use PHPUnit\Framework\TestCase; |
||
| 7 | |||
| 8 | class DisjointSetTest extends TestCase { |
||
| 9 | private $set; |
||
| 10 | |||
| 11 | public function setUp() { |
||
| 14 | |||
| 15 | public function testMakeSet() { |
||
| 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 | } |