run service_node in the browser instead of as a nodejs module
parent
61145b6e99
commit
583a10628a
@ -1,22 +0,0 @@
|
|||||||
// For reference: https://github.com/airbnb/javascript
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
env: {
|
|
||||||
mocha: true,
|
|
||||||
browser: false,
|
|
||||||
},
|
|
||||||
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module',
|
|
||||||
},
|
|
||||||
|
|
||||||
rules: {
|
|
||||||
// We still get the value of this rule, it just allows for dev deps
|
|
||||||
'import/no-extraneous-dependencies': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
devDependencies: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,58 +1,57 @@
|
|||||||
const ServiceNode = require('../../service_nodes');
|
/* global libloki, chai */
|
||||||
const { expect } = require('chai');
|
|
||||||
|
|
||||||
describe('ServiceNodes', () => {
|
describe('ServiceNodes', () => {
|
||||||
describe('#consolidateLists', () => {
|
describe('#consolidateLists', () => {
|
||||||
it('should throw when provided a non-iterable list', () => {
|
it('should throw when provided a non-iterable list', () => {
|
||||||
expect(() => ServiceNode.consolidateLists(null, 1)).to.throw();
|
chai.expect(() => libloki.serviceNodes.consolidateLists(null, 1)).to.throw();
|
||||||
});
|
});
|
||||||
it('should throw when provided a non-iterable item in the list', () => {
|
it('should throw when provided a non-iterable item in the list', () => {
|
||||||
expect(() => ServiceNode.consolidateLists([1, 2, 3], 1)).to.throw();
|
chai.expect(() => libloki.serviceNodes.consolidateLists([1, 2, 3], 1)).to.throw();
|
||||||
});
|
});
|
||||||
it('should throw when provided a non-number threshold', () => {
|
it('should throw when provided a non-number threshold', () => {
|
||||||
expect(() => ServiceNode.consolidateLists([], 'a')).to.throw();
|
chai.expect(() => libloki.serviceNodes.consolidateLists([], 'a')).to.throw();
|
||||||
});
|
});
|
||||||
it('should return an empty array when the input is an empty array', () => {
|
it('should return an empty array when the input is an empty array', () => {
|
||||||
const result = ServiceNode.consolidateLists([]);
|
const result = libloki.serviceNodes.consolidateLists([]);
|
||||||
expect(result).to.deep.equal([]);
|
chai.expect(result).to.deep.equal([]);
|
||||||
});
|
});
|
||||||
it('should return the input when only 1 list is provided', () => {
|
it('should return the input when only 1 list is provided', () => {
|
||||||
const result = ServiceNode.consolidateLists([['a', 'b', 'c']]);
|
const result = libloki.serviceNodes.consolidateLists([['a', 'b', 'c']]);
|
||||||
expect(result).to.deep.equal(['a', 'b', 'c']);
|
chai.expect(result).to.deep.equal(['a', 'b', 'c']);
|
||||||
});
|
});
|
||||||
it('should return the union of all lists when threshold is 0', () => {
|
it('should return the union of all lists when threshold is 0', () => {
|
||||||
const result = ServiceNode.consolidateLists([
|
const result = libloki.serviceNodes.consolidateLists([
|
||||||
['a', 'b', 'c', 'h'],
|
['a', 'b', 'c', 'h'],
|
||||||
['d', 'e', 'f', 'g'],
|
['d', 'e', 'f', 'g'],
|
||||||
['g', 'h'],
|
['g', 'h'],
|
||||||
], 0);
|
], 0);
|
||||||
expect(result.sort()).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
chai.expect(result.sort()).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']);
|
||||||
});
|
});
|
||||||
it('should return the intersection of all lists when threshold is 1', () => {
|
it('should return the intersection of all lists when threshold is 1', () => {
|
||||||
const result = ServiceNode.consolidateLists([
|
const result = libloki.serviceNodes.consolidateLists([
|
||||||
['a', 'b', 'c', 'd'],
|
['a', 'b', 'c', 'd'],
|
||||||
['a', 'e', 'f', 'g'],
|
['a', 'e', 'f', 'g'],
|
||||||
['a', 'h'],
|
['a', 'h'],
|
||||||
], 1);
|
], 1);
|
||||||
expect(result).to.deep.equal(['a']);
|
chai.expect(result).to.deep.equal(['a']);
|
||||||
});
|
});
|
||||||
it('should return the elements that have an occurence >= the provided threshold', () => {
|
it('should return the elements that have an occurence >= the provided threshold', () => {
|
||||||
const result = ServiceNode.consolidateLists([
|
const result = libloki.serviceNodes.consolidateLists([
|
||||||
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
||||||
['a', 'b', 'c', 'd', 'e', 'f', 'h'],
|
['a', 'b', 'c', 'd', 'e', 'f', 'h'],
|
||||||
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
['a', 'b', 'c', 'd', 'e', 'f', 'g'],
|
||||||
['a', 'b', 'c', 'd', 'e', 'g', 'h'],
|
['a', 'b', 'c', 'd', 'e', 'g', 'h'],
|
||||||
], 3/4);
|
], 3/4);
|
||||||
expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
chai.expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
||||||
});
|
});
|
||||||
it('should work with sets as well', () => {
|
it('should work with sets as well', () => {
|
||||||
const result = ServiceNode.consolidateLists(new Set([
|
const result = libloki.serviceNodes.consolidateLists(new Set([
|
||||||
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
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', 'h']),
|
||||||
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
new Set(['a', 'b', 'c', 'd', 'e', 'f', 'g']),
|
||||||
new Set(['a', 'b', 'c', 'd', 'e', 'g', 'h']),
|
new Set(['a', 'b', 'c', 'd', 'e', 'g', 'h']),
|
||||||
]), 3/4);
|
]), 3/4);
|
||||||
expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
chai.expect(result).to.deep.equal(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue