UNPKG

weighted-quick-union

Version:

Weighted quick union without path compression

25 lines (20 loc) 647 B
const assert = require('assert'); const WeightedQuickUnionUF = require('../index.js'); const tinyUF = require('./tinyUF.json'); describe('Weighted Quick Union - Union Find', function() { let uf = new WeightedQuickUnionUF(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); }); });