UNPKG

quick-union-union-find

Version:

Quick Union Union Find using ES next

27 lines (22 loc) 760 B
const assert = require('assert'); const QuickUnionUF = require('../index.js'); const tinyUF = require('./tinyUF.json'); describe('Quick Union - Union Find', function() { let uf = new QuickUnionUF(tinyUF.count); before(function() { for (let [p, q] of tinyUF.connections) { if (!uf.connected(p,q)) { uf.union(p, q); } } }); it('should find a connection between 0 and 7', function() { assert.ok(uf.connected(0,7), '0 and 7 should be connected'); }); it('should not find a connection between 5 and 4', function() { assert.ok(!uf.connected(5,4), '5 and 4 should not be connected'); }); it('should have only two connected components', function() { assert.equal(2, uf.count, 'count should be 2'); }); });