quick-find-union-find
Version:
Quick Find Union Find using ES next
27 lines (22 loc) • 737 B
JavaScript
const assert = require('assert');
const QuickFindUF = require('../index.js');
let tinyUF = require('./tinyUF.json');
describe('Quick Find - Union Find', function() {
let uf = new QuickFindUF(tinyUF.count);
before(function() {
for (let [p, q] of tinyUF.connections) {
if (!uf.connected(p,q)) {
uf.union(p, q);
}
}
});
it('should have a path from 0 to 7', function() {
assert.ok(uf.connected(0, 7), '0 and 7 should be connected');
});
it('should not have a path from 5 to 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');
});
});