You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.4 KiB
JavaScript
58 lines
2.4 KiB
JavaScript
6 years ago
|
/* global libloki, chai */
|
||
6 years ago
|
|
||
|
describe('ServiceNodes', () => {
|
||
|
describe('#consolidateLists', () => {
|
||
|
it('should throw when provided a non-iterable list', () => {
|
||
6 years ago
|
chai.expect(() => libloki.serviceNodes.consolidateLists(null, 1)).to.throw();
|
||
6 years ago
|
});
|
||
|
it('should throw when provided a non-iterable item in the list', () => {
|
||
6 years ago
|
chai.expect(() => libloki.serviceNodes.consolidateLists([1, 2, 3], 1)).to.throw();
|
||
6 years ago
|
});
|
||
|
it('should throw when provided a non-number threshold', () => {
|
||
6 years ago
|
chai.expect(() => libloki.serviceNodes.consolidateLists([], 'a')).to.throw();
|
||
6 years ago
|
});
|
||
|
it('should return an empty array when the input is an empty array', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists([]);
|
||
|
chai.expect(result).to.deep.equal([]);
|
||
6 years ago
|
});
|
||
|
it('should return the input when only 1 list is provided', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists([['a', 'b', 'c']]);
|
||
|
chai.expect(result).to.deep.equal(['a', 'b', 'c']);
|
||
6 years ago
|
});
|
||
|
it('should return the union of all lists when threshold is 0', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists([
|
||
6 years ago
|
['a', 'b', 'c', 'h'],
|
||
|
['d', 'e', 'f', 'g'],
|
||
|
['g', 'h'],
|
||
|
], 0);
|
||
6 years ago
|
chai.expect(result.sort()).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||
6 years ago
|
});
|
||
|
it('should return the intersection of all lists when threshold is 1', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists([
|
||
6 years ago
|
['a', 'b', 'c', 'd'],
|
||
|
['a', 'e', 'f', 'g'],
|
||
|
['a', 'h'],
|
||
|
], 1);
|
||
6 years ago
|
chai.expect(result).to.deep.equal(['a']);
|
||
6 years ago
|
});
|
||
|
it('should return the elements that have an occurence >= the provided threshold', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists([
|
||
6 years ago
|
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
||
|
['a', 'b', 'c', 'd', 'e', 'f', 'h'],
|
||
|
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
||
|
['a', 'b', 'c', 'd', 'e', 'g', 'h'],
|
||
|
], 3/4);
|
||
6 years ago
|
chai.expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
||
6 years ago
|
});
|
||
|
it('should work with sets as well', () => {
|
||
6 years ago
|
const result = libloki.serviceNodes.consolidateLists(new Set([
|
||
6 years ago
|
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
||
|
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'h']),
|
||
|
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
||
|
new Set(['a', 'b', 'c', 'd', 'e', 'g', 'h']),
|
||
|
]), 3/4);
|
||
6 years ago
|
chai.expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
||
6 years ago
|
});
|
||
|
});
|
||
|
});
|