2019-01-19 14:00:38 +02:00
|
|
|
import {expect} from 'chai';
|
2019-12-10 11:44:35 +02:00
|
|
|
import {Utils} from '../../../src/common/Utils';
|
2019-01-19 14:00:38 +02:00
|
|
|
|
|
|
|
describe('Utils', () => {
|
|
|
|
it('should concat urls', () => {
|
2020-01-07 23:17:54 +02:00
|
|
|
expect(Utils.concatUrls('\\')).to.be.equal('.');
|
|
|
|
expect(Utils.concatUrls('\\*')).to.be.equal('/*');
|
2019-01-19 14:00:38 +02:00
|
|
|
expect(Utils.concatUrls('abc', 'cde')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc/', 'cde')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc\\', 'cde')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc/', 'cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('./abc\\', 'cde/')).to.be.equal('./abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc/', '\\cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc\\', '\\cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc\\', '/cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc/', '/cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc\\/', '/cde/')).to.be.equal('abc/cde');
|
|
|
|
expect(Utils.concatUrls('abc\\/', '/cde/', 'fgh')).to.be.equal('abc/cde/fgh');
|
|
|
|
});
|
2019-12-14 18:27:01 +02:00
|
|
|
|
|
|
|
it('should find closest number', () => {
|
|
|
|
|
|
|
|
expect(Utils.findClosest(10, [10, 13, 4, 20])).to.be.equal(10);
|
|
|
|
expect(Utils.findClosest(10, [13, 4, 20])).to.be.equal(13);
|
|
|
|
expect(Utils.findClosest(10, [4, 20])).to.be.equal(4);
|
|
|
|
expect(Utils.findClosest(10, [20])).to.be.equal(20);
|
|
|
|
});
|
|
|
|
it('should find closest number in sorted array', () => {
|
|
|
|
|
|
|
|
expect(Utils.findClosestinSorted(10, [3, 5, 8, 10, 15, 20])).to.be.equal(10);
|
|
|
|
expect(Utils.findClosestinSorted(10, [3, 5, 8, 15, 20])).to.be.equal(8);
|
|
|
|
expect(Utils.findClosestinSorted(10, [3, 5, 15, 20])).to.be.equal(15);
|
|
|
|
expect(Utils.findClosestinSorted(10, [3, 5, 20])).to.be.equal(5);
|
|
|
|
expect(Utils.findClosestinSorted(10, [3, 20])).to.be.equal(3);
|
|
|
|
expect(Utils.findClosestinSorted(10, [20])).to.be.equal(20);
|
|
|
|
});
|
2019-01-19 14:00:38 +02:00
|
|
|
});
|