UNPKG

weighted-quick-union-by-rank-with-path-compression

Version:

Weighted Quick Union by rank with path compression

25 lines (20 loc) 611 B
const assert = require('assert'); const UF = require('../index.js'); const tinyUF = require('./tinyUF.json'); describe('Weighted Quick Union - Union Find', function() { let uf = new UF(tinyUF.count); before(function() { for(let [p, q] of tinyUF.connections) { uf.union(p, q); } }); it('should be able to find a path between 0 and 7', function() { assert.ok(uf.connected(0,7)); }); it('should not have a path between 5 and 4', function() { assert.ok(!uf.connected(5,4)); }); it('should have 2 connected components', function() { assert.equal(2, uf.count); }); });