Add node tests
This commit is contained in:
41
.github/workflows/test.yml
vendored
41
.github/workflows/test.yml
vendored
@@ -47,8 +47,8 @@ jobs:
|
||||
- name: Run Tests
|
||||
run: npm run pretest
|
||||
|
||||
spec:
|
||||
name: Spec
|
||||
browser:
|
||||
name: Browser
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
@@ -80,7 +80,42 @@ jobs:
|
||||
run: npm ci
|
||||
|
||||
- name: Run Tests
|
||||
run: npm run test-spec
|
||||
run: npm run test-browser
|
||||
|
||||
node:
|
||||
name: Node
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- name: Clone Repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.js Version
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- name: Determine Cache Directory
|
||||
id: npm-cache
|
||||
run: |
|
||||
echo "::set-output name=dir::$(npm config get cache)"
|
||||
|
||||
- name: Configure Job Cache
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ steps.npm-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Tests
|
||||
run: npm run test-node
|
||||
|
||||
build:
|
||||
name: Build
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
"lint": "eslint tasks test src/ol examples config",
|
||||
"pretest": "npm run lint && npm run typecheck",
|
||||
"test-rendering": "node test/rendering/test.js",
|
||||
"test-spec": "npm run karma -- --single-run --log-level error",
|
||||
"test": "npm run test-spec && npm run test-rendering -- --force",
|
||||
"test-browser": "npm run karma -- --single-run --log-level error",
|
||||
"test-node": "mocha --recursive test/node",
|
||||
"test": "npm run test-browser && npm run test-node && npm run test-rendering -- --force",
|
||||
"karma": "karma start test/browser/karma.config.cjs",
|
||||
"start": "npm run serve-examples",
|
||||
"serve-examples": "webpack serve --config examples/webpack/config.js --mode development",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
## Included in this directory
|
||||
|
||||
- browser - Unit/integration tests run in a browser
|
||||
|
||||
- node - Unit tests run with Node.js
|
||||
- rendering - Tests that make assertions about rendered map output
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import {assert} from '../../../../src/ol/asserts.js';
|
||||
|
||||
describe('ol.asserts', function () {
|
||||
describe('ol.asserts.assert', function () {
|
||||
it('throws an exception', function () {
|
||||
expect(function () {
|
||||
assert(false, 42);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,22 +0,0 @@
|
||||
import {getUid} from '../../../../src/ol/util.js';
|
||||
|
||||
describe('getUid()', function () {
|
||||
it('is constant once generated', function () {
|
||||
const a = {};
|
||||
expect(getUid(a)).to.be(getUid(a));
|
||||
});
|
||||
|
||||
it('generates a strictly increasing sequence', function () {
|
||||
const a = {};
|
||||
const b = {};
|
||||
const c = {};
|
||||
getUid(a);
|
||||
getUid(c);
|
||||
getUid(b);
|
||||
|
||||
//uid order should be a < c < b
|
||||
expect(getUid(a)).to.be.lessThan(getUid(c));
|
||||
expect(getUid(c)).to.be.lessThan(getUid(b));
|
||||
expect(getUid(a)).to.be.lessThan(getUid(b));
|
||||
});
|
||||
});
|
||||
@@ -1,162 +0,0 @@
|
||||
import {
|
||||
clamp,
|
||||
cosh,
|
||||
lerp,
|
||||
log2,
|
||||
modulo,
|
||||
solveLinearSystem,
|
||||
toDegrees,
|
||||
toRadians,
|
||||
} from '../../../../src/ol/math.js';
|
||||
|
||||
describe('ol.math.clamp', function () {
|
||||
it('returns the correct value at -Infinity', function () {
|
||||
expect(clamp(-Infinity, 10, 20)).to.eql(10);
|
||||
});
|
||||
|
||||
it('returns the correct value at min', function () {
|
||||
expect(clamp(10, 10, 20)).to.eql(10);
|
||||
});
|
||||
|
||||
it('returns the correct value at mid point', function () {
|
||||
expect(clamp(15, 10, 20)).to.eql(15);
|
||||
});
|
||||
|
||||
it('returns the correct value at max', function () {
|
||||
expect(clamp(20, 10, 20)).to.eql(20);
|
||||
});
|
||||
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(clamp(Infinity, 10, 20)).to.eql(20);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.cosh', function () {
|
||||
it('returns the correct value at -Infinity', function () {
|
||||
expect(cosh(-Infinity)).to.eql(Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at -1', function () {
|
||||
expect(cosh(-1)).to.roughlyEqual(1.5430806348152437, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(cosh(0)).to.eql(1);
|
||||
});
|
||||
|
||||
it('returns the correct value at 1', function () {
|
||||
expect(cosh(1)).to.roughlyEqual(1.5430806348152437, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(cosh(Infinity)).to.eql(Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.log2', function () {
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(log2(Infinity)).to.eql(Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at 3', function () {
|
||||
expect(log2(3)).to.roughlyEqual(1.584962500721156, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at 2', function () {
|
||||
expect(log2(2)).to.eql(1);
|
||||
});
|
||||
|
||||
it('returns the correct value at 1', function () {
|
||||
expect(log2(1)).to.eql(0);
|
||||
});
|
||||
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(log2(0)).to.eql(-Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at -1', function () {
|
||||
expect(log2(-1).toString()).to.eql('NaN');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.solveLinearSystem', function () {
|
||||
it('calculates correctly', function () {
|
||||
const result = solveLinearSystem([
|
||||
[2, 1, 3, 1],
|
||||
[2, 6, 8, 3],
|
||||
[6, 8, 18, 5],
|
||||
]);
|
||||
expect(result[0]).to.roughlyEqual(0.3, 1e-9);
|
||||
expect(result[1]).to.roughlyEqual(0.4, 1e-9);
|
||||
expect(result[2]).to.roughlyEqual(0, 1e-9);
|
||||
});
|
||||
|
||||
it('can handle singular matrix', function () {
|
||||
const result = solveLinearSystem([
|
||||
[2, 1, 3, 1],
|
||||
[2, 6, 8, 3],
|
||||
[2, 1, 3, 1],
|
||||
]);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.toDegrees', function () {
|
||||
it('returns the correct value at -π', function () {
|
||||
expect(toDegrees(-Math.PI)).to.be(-180);
|
||||
});
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(toDegrees(0)).to.be(0);
|
||||
});
|
||||
it('returns the correct value at π', function () {
|
||||
expect(toDegrees(Math.PI)).to.be(180);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.toRadians', function () {
|
||||
it('returns the correct value at -180', function () {
|
||||
expect(toRadians(-180)).to.be(-Math.PI);
|
||||
});
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(toRadians(0)).to.be(0);
|
||||
});
|
||||
it('returns the correct value at 180', function () {
|
||||
expect(toRadians(180)).to.be(Math.PI);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.modulo', function () {
|
||||
it('256 / 8 returns 0', function () {
|
||||
expect(modulo(256, 8)).to.be(0);
|
||||
});
|
||||
it('positive and positive returns a positive ', function () {
|
||||
expect(modulo(7, 8)).to.be(7);
|
||||
});
|
||||
it('same Dividend and Divisor returns 0', function () {
|
||||
expect(modulo(4, 4)).to.be(0);
|
||||
});
|
||||
it('negative and positive returns positive', function () {
|
||||
expect(modulo(-3, 4)).to.be(1);
|
||||
});
|
||||
it('negative and negative returns negative', function () {
|
||||
expect(modulo(-4, -5)).to.be(-4);
|
||||
expect(modulo(-3, -4)).to.be(-3);
|
||||
});
|
||||
it('positive and negative returns negative', function () {
|
||||
expect(modulo(3, -4)).to.be(-1);
|
||||
expect(modulo(1, -5)).to.be(-4);
|
||||
expect(modulo(6, -5)).to.be(-4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.math.lerp', function () {
|
||||
it('correctly interpolated numbers', function () {
|
||||
expect(lerp(0, 0, 0)).to.be(0);
|
||||
expect(lerp(0, 1, 0)).to.be(0);
|
||||
expect(lerp(1, 11, 5)).to.be(51);
|
||||
});
|
||||
it('correctly interpolates floats', function () {
|
||||
expect(lerp(0, 1, 0.5)).to.be(0.5);
|
||||
expect(lerp(0.25, 0.75, 0.5)).to.be(0.5);
|
||||
});
|
||||
});
|
||||
@@ -1,64 +0,0 @@
|
||||
import {assign, clear, getValues, isEmpty} from '../../../../src/ol/obj.js';
|
||||
|
||||
describe('ol.obj.assign()', function () {
|
||||
it('is an alias for Object.assign() where available', function () {
|
||||
if (typeof Object.assign === 'function') {
|
||||
expect(assign).to.be(Object.assign);
|
||||
}
|
||||
});
|
||||
|
||||
it('assigns properties from a source object to a target object', function () {
|
||||
const source = {
|
||||
sourceProp1: 'sourceValue1',
|
||||
sourceProp2: 'sourceValue2',
|
||||
};
|
||||
|
||||
const target = {
|
||||
sourceProp1: 'overridden',
|
||||
targetProp1: 'targetValue1',
|
||||
};
|
||||
|
||||
const assigned = assign(target, source);
|
||||
expect(assigned).to.be(target);
|
||||
expect(assigned.sourceProp1).to.be('sourceValue1');
|
||||
expect(assigned.sourceProp2).to.be('sourceValue2');
|
||||
expect(assigned.targetProp1).to.be('targetValue1');
|
||||
});
|
||||
|
||||
it('throws a TypeError with `undefined` as target', function () {
|
||||
expect(() => assign()).to.throwException(
|
||||
/Cannot convert undefined or null to object/
|
||||
);
|
||||
});
|
||||
|
||||
it('throws a TypeError with `null` as target', function () {
|
||||
expect(() => assign(null)).to.throwException(
|
||||
/Cannot convert undefined or null to object/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.obj.clear()', function () {
|
||||
it('removes all properties from an object', function () {
|
||||
expect(isEmpty(clear({foo: 'bar'}))).to.be(true);
|
||||
expect(isEmpty(clear({foo: 'bar', num: 42}))).to.be(true);
|
||||
expect(isEmpty(clear({}))).to.be(true);
|
||||
expect(isEmpty(clear(null))).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.obj.getValues()', function () {
|
||||
it('gets a list of property values from an object', function () {
|
||||
expect(getValues({foo: 'bar', num: 42}).sort()).to.eql([42, 'bar']);
|
||||
expect(getValues([])).to.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.obj.isEmpty()', function () {
|
||||
it('checks if an object has any properties', function () {
|
||||
expect(isEmpty({})).to.be(true);
|
||||
expect(isEmpty(null)).to.be(true);
|
||||
expect(isEmpty({foo: 'bar'})).to.be(false);
|
||||
expect(isEmpty({foo: false})).to.be(false);
|
||||
});
|
||||
});
|
||||
8
test/node/.eslintrc
Normal file
8
test/node/.eslintrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"mocha": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2017
|
||||
}
|
||||
}
|
||||
36
test/node/expect.js
Normal file
36
test/node/expect.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import expect from 'expect.js';
|
||||
|
||||
/**
|
||||
* Assert value is within some tolerance of a number.
|
||||
* @param {number} n Number.
|
||||
* @param {number} tol Tolerance.
|
||||
* @return {expect.Assertion} The assertion.
|
||||
*/
|
||||
expect.Assertion.prototype.roughlyEqual = function (n, tol) {
|
||||
this.assert(
|
||||
Math.abs(this.obj - n) <= tol,
|
||||
function () {
|
||||
return (
|
||||
'expected ' +
|
||||
expect.stringify(this.obj) +
|
||||
' to be within ' +
|
||||
tol +
|
||||
' of ' +
|
||||
n
|
||||
);
|
||||
},
|
||||
function () {
|
||||
return (
|
||||
'expected ' +
|
||||
expect.stringify(this.obj) +
|
||||
' not to be within ' +
|
||||
tol +
|
||||
' of ' +
|
||||
n
|
||||
);
|
||||
}
|
||||
);
|
||||
return this;
|
||||
};
|
||||
|
||||
export default expect;
|
||||
@@ -1,7 +1,8 @@
|
||||
import AssertionError from '../../../../src/ol/AssertionError.js';
|
||||
import {VERSION} from '../../../../src/ol/util.js';
|
||||
import AssertionError from '../../../src/ol/AssertionError.js';
|
||||
import expect from '../expect.js';
|
||||
import {VERSION} from '../../../src/ol/util.js';
|
||||
|
||||
describe('ol.AssertionError', function () {
|
||||
describe('ol/AssertionError.js', function () {
|
||||
it('generates an error', function () {
|
||||
const error = new AssertionError(42);
|
||||
expect(error).to.be.an(Error);
|
||||
@@ -1,8 +1,10 @@
|
||||
import Collection from '../../../../src/ol/Collection.js';
|
||||
import CollectionEventType from '../../../../src/ol/CollectionEventType.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import Collection from '../../../src/ol/Collection.js';
|
||||
import CollectionEventType from '../../../src/ol/CollectionEventType.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {listen} from '../../../src/ol/events.js';
|
||||
|
||||
describe('ol.collection', function () {
|
||||
describe('ol/Collection.js', function () {
|
||||
let collection;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -1,6 +1,8 @@
|
||||
import Disposable from '../../../../src/ol/Disposable.js';
|
||||
import Disposable from '../../../src/ol/Disposable.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('ol.Disposable', function () {
|
||||
describe('ol/Disposable.js', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates an instance', function () {
|
||||
const disposable = new Disposable();
|
||||
@@ -1,9 +1,11 @@
|
||||
import Feature, {createStyleFunction} from '../../../../src/ol/Feature.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import Style from '../../../../src/ol/style/Style.js';
|
||||
import {isEmpty} from '../../../../src/ol/obj.js';
|
||||
import Feature, {createStyleFunction} from '../../../src/ol/Feature.js';
|
||||
import Point from '../../../src/ol/geom/Point.js';
|
||||
import Style from '../../../src/ol/style/Style.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {isEmpty} from '../../../src/ol/obj.js';
|
||||
|
||||
describe('ol.Feature', function () {
|
||||
describe('ol/Feature.js', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates a new feature', function () {
|
||||
const feature = new Feature();
|
||||
@@ -1,7 +1,9 @@
|
||||
import BaseObject from '../../../../src/ol/Object.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
import BaseObject from '../../../src/ol/Object.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {listen} from '../../../src/ol/events.js';
|
||||
|
||||
describe('ol.Object', function () {
|
||||
describe('ol/Object.js', function () {
|
||||
let o;
|
||||
beforeEach(function () {
|
||||
o = new BaseObject();
|
||||
@@ -1,7 +1,9 @@
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import Observable, {unByKey} from '../../../../src/ol/Observable.js';
|
||||
import EventTarget from '../../../src/ol/events/Target.js';
|
||||
import Observable, {unByKey} from '../../../src/ol/Observable.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('ol.Observable', function () {
|
||||
describe('ol/Observable.js', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates a new observable', function () {
|
||||
const observable = new Observable();
|
||||
612
test/node/ol/array.test.js
Normal file
612
test/node/ol/array.test.js
Normal file
@@ -0,0 +1,612 @@
|
||||
import expect from '../expect.js';
|
||||
import {
|
||||
binarySearch,
|
||||
equals,
|
||||
extend,
|
||||
find,
|
||||
findIndex,
|
||||
isSorted,
|
||||
linearFindNearest,
|
||||
numberSafeCompareFunction,
|
||||
remove,
|
||||
reverseSubArray,
|
||||
stableSort,
|
||||
} from '../../../src/ol/array.js';
|
||||
|
||||
describe('ol/array.js', function () {
|
||||
describe('binarySearch', function () {
|
||||
const insertionPoint = function (position) {
|
||||
return -(position + 1);
|
||||
};
|
||||
const revNumCompare = function (a, b) {
|
||||
return b - a;
|
||||
};
|
||||
|
||||
describe('default comparison on array of String(s)', function () {
|
||||
const a = [
|
||||
'1000',
|
||||
'9',
|
||||
'AB',
|
||||
'ABC',
|
||||
'ABCABC',
|
||||
'ABD',
|
||||
'ABDA',
|
||||
'B',
|
||||
'B',
|
||||
'B',
|
||||
'C',
|
||||
'CA',
|
||||
'CC',
|
||||
'ZZZ',
|
||||
'ab',
|
||||
'abc',
|
||||
'abcabc',
|
||||
'abd',
|
||||
'abda',
|
||||
'b',
|
||||
'c',
|
||||
'ca',
|
||||
'cc',
|
||||
'zzz',
|
||||
];
|
||||
|
||||
it("should find '1000' at index 0", function () {
|
||||
expect(binarySearch(a, '1000')).to.be(0);
|
||||
});
|
||||
it("should find 'zzz' at index " + (a.length - 1), function () {
|
||||
expect(binarySearch(a, 'zzz')).to.be(a.length - 1);
|
||||
});
|
||||
it("should find 'C' at index 10", function () {
|
||||
expect(binarySearch(a, 'C')).to.be(10);
|
||||
});
|
||||
it("should find 'B' at index 7 || 8 || 9", function () {
|
||||
const pos = binarySearch(a, 'B');
|
||||
expect(pos == 7 || pos == 8 || pos == 9).to.be.ok();
|
||||
});
|
||||
it("should not find '100'", function () {
|
||||
const pos = binarySearch(a, '100');
|
||||
expect(pos < 0).to.be.ok();
|
||||
});
|
||||
it("should have an insertion point of 0 for '100'", function () {
|
||||
const pos = binarySearch(a, '100');
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
it("should not find 'zzz0'", function () {
|
||||
const pos = binarySearch(a, 'zzz0');
|
||||
expect(pos < 0).to.be.ok();
|
||||
});
|
||||
it(
|
||||
'should have an insertion point of ' + a.length + " for 'zzz0'",
|
||||
function () {
|
||||
const pos = binarySearch(a, 'zzz0');
|
||||
expect(insertionPoint(pos)).to.be(a.length);
|
||||
}
|
||||
);
|
||||
it("should not find 'BA'", function () {
|
||||
const pos = binarySearch(a, 'zzz0');
|
||||
expect(pos < 0).to.be.ok();
|
||||
});
|
||||
it("should have an insertion point of 10 for 'BA'", function () {
|
||||
const pos = binarySearch(a, 'BA');
|
||||
expect(insertionPoint(pos)).to.be(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('0 length array with default comparison', function () {
|
||||
const b = [];
|
||||
it("should not find 'a'", function () {
|
||||
expect(binarySearch(b, 'a') < 0).to.be.ok();
|
||||
});
|
||||
it("should have an insertion point of 0 for 'a'", function () {
|
||||
const pos = binarySearch(b, 'a');
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('single element array with default lexiographical comparison', function () {
|
||||
const c = ['only item'];
|
||||
it("should find 'only item' at index 0", function () {
|
||||
expect(binarySearch(c, 'only item')).to.be(0);
|
||||
});
|
||||
it("should not find 'a'", function () {
|
||||
expect(binarySearch(c, 'a') < 0).to.be.ok();
|
||||
});
|
||||
it("should have an insertion point of 0 for 'a'", function () {
|
||||
const pos = binarySearch(c, 'a');
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
it("should not find 'z'", function () {
|
||||
expect(binarySearch(c, 'z') < 0).to.be.ok();
|
||||
});
|
||||
it("should have an insertion point of 1 for 'z'", function () {
|
||||
const pos = binarySearch(c, 'z');
|
||||
expect(insertionPoint(pos)).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('default comparison on array of Number(s)', function () {
|
||||
const d = [
|
||||
-897123.9,
|
||||
-321434.58758,
|
||||
-1321.3124,
|
||||
-324,
|
||||
-9,
|
||||
-3,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0.31255,
|
||||
5,
|
||||
142.88888708,
|
||||
334,
|
||||
342,
|
||||
453,
|
||||
54254,
|
||||
];
|
||||
it('should find -897123.9 at index 0', function () {
|
||||
expect(binarySearch(d, -897123.9)).to.be(0);
|
||||
});
|
||||
it('should find 54254 at index ' + (d.length - 1), function () {
|
||||
expect(binarySearch(d, 54254)).to.be(d.length - 1);
|
||||
});
|
||||
it('should find -3 at index 5', function () {
|
||||
expect(binarySearch(d, -3)).to.be(5);
|
||||
});
|
||||
it('should find 0 at index 6 || 7 || 8', function () {
|
||||
const pos = binarySearch(d, 0);
|
||||
expect(pos == 6 || pos == 7 || pos == 8).to.be(true);
|
||||
});
|
||||
it('should not find -900000', function () {
|
||||
const pos = binarySearch(d, -900000);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 0 for -900000', function () {
|
||||
const pos = binarySearch(d, -900000);
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
it('should not find 54255', function () {
|
||||
const pos = binarySearch(d, 54255);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it(
|
||||
'should have an insertion point of ' + d.length + ' for 54255',
|
||||
function () {
|
||||
const pos = binarySearch(d, 54255);
|
||||
expect(insertionPoint(pos)).to.be(d.length);
|
||||
}
|
||||
);
|
||||
it('should not find 1.1', function () {
|
||||
const pos = binarySearch(d, 1.1);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 10 for 1.1', function () {
|
||||
const pos = binarySearch(d, 1.1);
|
||||
expect(insertionPoint(pos)).to.be(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('custom comparison function, which reverse orders numbers', function () {
|
||||
const e = [
|
||||
54254,
|
||||
453,
|
||||
342,
|
||||
334,
|
||||
142.88888708,
|
||||
5,
|
||||
0.31255,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
-3,
|
||||
-9,
|
||||
-324,
|
||||
-1321.3124,
|
||||
-321434.58758,
|
||||
-897123.9,
|
||||
];
|
||||
it('should find 54254 at index 0', function () {
|
||||
const pos = binarySearch(e, 54254, revNumCompare);
|
||||
expect(pos).to.be(0);
|
||||
});
|
||||
it('should find -897123.9 at index ' + (e.length - 1), function () {
|
||||
const pos = binarySearch(e, -897123.9, revNumCompare);
|
||||
expect(pos).to.be(e.length - 1);
|
||||
});
|
||||
it('should find -3 at index 10', function () {
|
||||
const pos = binarySearch(e, -3, revNumCompare);
|
||||
expect(pos).to.be(10);
|
||||
});
|
||||
it('should find 0 at index 7 || 8 || 9', function () {
|
||||
const pos = binarySearch(e, 0, revNumCompare);
|
||||
expect(pos == 7 || pos == 8 || pos == 9).to.be(true);
|
||||
});
|
||||
it('should not find 54254.1', function () {
|
||||
const pos = binarySearch(e, 54254.1, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 0 for 54254.1', function () {
|
||||
const pos = binarySearch(e, 54254.1, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
it('should not find -897124', function () {
|
||||
const pos = binarySearch(e, -897124, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it(
|
||||
'should have an insertion point of ' + e.length + ' for -897124',
|
||||
function () {
|
||||
const pos = binarySearch(e, -897124, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(e.length);
|
||||
}
|
||||
);
|
||||
it('should not find 1.1', function () {
|
||||
const pos = binarySearch(e, 1.1, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 0 for 1.1', function () {
|
||||
const pos = binarySearch(e, 1.1, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('0 length array with custom comparison function', function () {
|
||||
const f = [];
|
||||
it('should not find 0', function () {
|
||||
const pos = binarySearch(f, 0, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 0 for 0', function () {
|
||||
const pos = binarySearch(f, 0, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('single element array with custom comparison function', function () {
|
||||
const g = [1];
|
||||
it('should find 1 at index 0', function () {
|
||||
const pos = binarySearch(g, 1, revNumCompare);
|
||||
expect(pos).to.be(0);
|
||||
});
|
||||
it('should not find 2', function () {
|
||||
const pos = binarySearch(g, 2, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 0 for 2', function () {
|
||||
const pos = binarySearch(g, 2, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(0);
|
||||
});
|
||||
it('should not find 0', function () {
|
||||
const pos = binarySearch(g, 0, revNumCompare);
|
||||
expect(pos < 0).to.be(true);
|
||||
});
|
||||
it('should have an insertion point of 1 for 0', function () {
|
||||
const pos = binarySearch(g, 0, revNumCompare);
|
||||
expect(insertionPoint(pos)).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('finding first index when multiple candidates', function () {
|
||||
it('should find the index of the first 0', function () {
|
||||
expect(binarySearch([0, 0, 1], 0)).to.be(0);
|
||||
});
|
||||
it('should find the index of the first 1', function () {
|
||||
expect(binarySearch([0, 1, 1], 1)).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Don't use Array#slice, Function#apply and Function#call", function () {
|
||||
const a = [1, 5, 7, 11, 13, 16, 19, 24, 28, 31, 33, 36, 40, 50, 52, 55];
|
||||
const calls = {
|
||||
'Array#slice': false,
|
||||
'Function#apply': false,
|
||||
'Function#call': false,
|
||||
};
|
||||
let origArraySlice;
|
||||
let origFunctionApply;
|
||||
let origFunctionCall;
|
||||
|
||||
it('does not use potentially slow methods (default & custom compare)', function () {
|
||||
// Mockup (I failed to use sinon.spy and beforeEach-hooks)
|
||||
origArraySlice = Array.prototype.slice;
|
||||
origFunctionApply = Function.prototype.apply;
|
||||
origFunctionCall = Function.prototype.call;
|
||||
Array.prototype.slice = function () {
|
||||
calls['Array#slice'] = true;
|
||||
};
|
||||
Function.prototype.apply = function () {
|
||||
calls['Function#apply'] = true;
|
||||
};
|
||||
Function.prototype.call = function () {
|
||||
calls['Function#call'] = true;
|
||||
};
|
||||
|
||||
// Now actually call and test the method twice
|
||||
binarySearch(a, 48);
|
||||
binarySearch(a, 13, function (a, b) {
|
||||
return a > b ? 1 : a < b ? -1 : 0;
|
||||
});
|
||||
|
||||
// Restore mocked up methods
|
||||
Array.prototype.slice = origArraySlice;
|
||||
Function.prototype.apply = origFunctionApply;
|
||||
Function.prototype.call = origFunctionCall;
|
||||
|
||||
// Expectations
|
||||
expect(calls['Array#slice']).to.be(false);
|
||||
expect(calls['Function#apply']).to.be(false);
|
||||
expect(calls['Function#call']).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when items are not found', function () {
|
||||
const arr = [1, 2, 2, 2, 3, 5, 9];
|
||||
|
||||
it('should return the index of where the item would go plus one, negated, if the item is not found', function () {
|
||||
expect(binarySearch(arr, 4)).to.equal(-6);
|
||||
});
|
||||
it('should work even on empty arrays', function () {
|
||||
expect(binarySearch([], 42)).to.equal(-1);
|
||||
});
|
||||
it('should work even on arrays of doubles', function () {
|
||||
expect(binarySearch([0.0, 0.1, 0.2, 0.3, 0.4], 0.25)).to.equal(-4);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('equals', function () {
|
||||
it('returns true for [] == []', function () {
|
||||
expect(equals([], [])).to.be(true);
|
||||
});
|
||||
it('returns true for [1] == [1]', function () {
|
||||
expect(equals([1], [1])).to.be(true);
|
||||
});
|
||||
it("returns true for ['1'] == ['1']", function () {
|
||||
expect(equals(['1'], ['1'])).to.be(true);
|
||||
});
|
||||
it("returns false for [1] == ['1']", function () {
|
||||
expect(equals([1], ['1'])).to.be(false);
|
||||
});
|
||||
it('returns true for [null] == [null]', function () {
|
||||
expect(equals([null], [null])).to.be(true);
|
||||
});
|
||||
it('returns false for [null] == [undefined]', function () {
|
||||
expect(equals([null], [undefined])).to.be(false);
|
||||
});
|
||||
it('returns true for [1, 2] == [1, 2]', function () {
|
||||
expect(equals([1, 2], [1, 2])).to.be(true);
|
||||
});
|
||||
it('returns false for [1, 2] == [2, 1]', function () {
|
||||
expect(equals([1, 2], [2, 1])).to.be(false);
|
||||
});
|
||||
it('returns false for [1, 2] == [1]', function () {
|
||||
expect(equals([1, 2], [1])).to.be(false);
|
||||
});
|
||||
it('returns false for [1] == [1, 2]', function () {
|
||||
expect(equals([1], [1, 2])).to.be(false);
|
||||
});
|
||||
it('returns false for [{}] == [{}]', function () {
|
||||
expect(equals([{}], [{}])).to.be(false);
|
||||
});
|
||||
});
|
||||
describe('extend', function () {
|
||||
it('extends an array in place with an array', function () {
|
||||
const a = [0, 1];
|
||||
extend(a, [2, 3]);
|
||||
expect(a).to.eql([0, 1, 2, 3]);
|
||||
});
|
||||
it('extends an array in place with a number', function () {
|
||||
const a = [0, 1];
|
||||
extend(a, 2);
|
||||
expect(a).to.eql([0, 1, 2]);
|
||||
});
|
||||
it('extends an array in place with a big array', function () {
|
||||
const a = [];
|
||||
let i = 250000; // original test has 1.000.000, but that was too slow
|
||||
const bigArray = Array(i);
|
||||
while (i--) {
|
||||
bigArray[i] = i;
|
||||
}
|
||||
extend(a, bigArray);
|
||||
expect(a).to.eql(bigArray);
|
||||
});
|
||||
});
|
||||
|
||||
describe('find', function () {
|
||||
it('finds numbers in an array', function () {
|
||||
const a = [0, 1, 2, 3];
|
||||
const b = find(a, function (val, index, a2) {
|
||||
expect(a).to.equal(a2);
|
||||
expect(typeof index).to.be('number');
|
||||
return val > 1;
|
||||
});
|
||||
expect(b).to.be(2);
|
||||
});
|
||||
|
||||
it('returns null when an item in an array is not found', function () {
|
||||
const a = [0, 1, 2, 3];
|
||||
const b = find(a, function (val, index, a2) {
|
||||
return val > 100;
|
||||
});
|
||||
expect(b).to.be(null);
|
||||
});
|
||||
|
||||
it('finds items in an array-like', function () {
|
||||
const a = 'abCD';
|
||||
const b = find(a, function (val, index, a2) {
|
||||
expect(a).to.equal(a2);
|
||||
expect(typeof index).to.be('number');
|
||||
return val >= 'A' && val <= 'Z';
|
||||
});
|
||||
expect(b).to.be('C');
|
||||
});
|
||||
|
||||
it('returns null when nothing in an array-like is found', function () {
|
||||
const a = 'abcd';
|
||||
const b = find(a, function (val, index, a2) {
|
||||
return val >= 'A' && val <= 'Z';
|
||||
});
|
||||
expect(b).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('findIndex', function () {
|
||||
it('finds index of numbers in an array', function () {
|
||||
const a = [0, 1, 2, 3];
|
||||
const b = findIndex(a, function (val, index, a2) {
|
||||
expect(a).to.equal(a2);
|
||||
expect(typeof index).to.be('number');
|
||||
return val > 1;
|
||||
});
|
||||
expect(b).to.be(2);
|
||||
});
|
||||
|
||||
it('returns -1 when an item in an array is not found', function () {
|
||||
const a = [0, 1, 2, 3];
|
||||
const b = findIndex(a, function (val, index, a2) {
|
||||
return val > 100;
|
||||
});
|
||||
expect(b).to.be(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSorted', function () {
|
||||
it('works with just an array as argument', function () {
|
||||
expect(isSorted([1, 2, 3])).to.be(true);
|
||||
expect(isSorted([1, 2, 2])).to.be(true);
|
||||
expect(isSorted([1, 2, 1])).to.be(false);
|
||||
});
|
||||
|
||||
it('works with strict comparison without compare function', function () {
|
||||
expect(isSorted([1, 2, 3], null, true)).to.be(true);
|
||||
expect(isSorted([1, 2, 2], null, true)).to.be(false);
|
||||
expect(isSorted([1, 2, 1], null, true)).to.be(false);
|
||||
});
|
||||
|
||||
it('works with a compare function', function () {
|
||||
function compare(a, b) {
|
||||
return b - a;
|
||||
}
|
||||
expect(isSorted([1, 2, 3], compare)).to.be(false);
|
||||
expect(isSorted([3, 2, 2], compare)).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('linearFindNearest', function () {
|
||||
it('returns expected value', function () {
|
||||
const arr = [1000, 500, 100];
|
||||
|
||||
expect(linearFindNearest(arr, 10000, 0)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 10000, 1)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 10000, -1)).to.eql(0);
|
||||
|
||||
expect(linearFindNearest(arr, 1000, 0)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 1000, 1)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 1000, -1)).to.eql(0);
|
||||
|
||||
expect(linearFindNearest(arr, 900, 0)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 900, 1)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 900, -1)).to.eql(1);
|
||||
|
||||
expect(linearFindNearest(arr, 750, 0)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 750, 1)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 750, -1)).to.eql(1);
|
||||
|
||||
expect(linearFindNearest(arr, 550, 0)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 550, 1)).to.eql(0);
|
||||
expect(linearFindNearest(arr, 550, -1)).to.eql(1);
|
||||
|
||||
expect(linearFindNearest(arr, 500, 0)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 500, 1)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 500, -1)).to.eql(1);
|
||||
|
||||
expect(linearFindNearest(arr, 450, 0)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 450, 1)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 450, -1)).to.eql(2);
|
||||
|
||||
expect(linearFindNearest(arr, 300, 0)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 300, 1)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 300, -1)).to.eql(2);
|
||||
|
||||
expect(linearFindNearest(arr, 200, 0)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 200, 1)).to.eql(1);
|
||||
expect(linearFindNearest(arr, 200, -1)).to.eql(2);
|
||||
|
||||
expect(linearFindNearest(arr, 100, 0)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 100, 1)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 100, -1)).to.eql(2);
|
||||
|
||||
expect(linearFindNearest(arr, 50, 0)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 50, 1)).to.eql(2);
|
||||
expect(linearFindNearest(arr, 50, -1)).to.eql(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('numberSafeCompareFunction', function () {
|
||||
it('sorts as expected', function () {
|
||||
const arr = [40, 200, 3000];
|
||||
// default sort would yield [200, 3000, 40]
|
||||
arr.sort(numberSafeCompareFunction);
|
||||
expect(arr).to.eql(arr);
|
||||
});
|
||||
});
|
||||
|
||||
describe('remove', function () {
|
||||
it('removes elements from an array', function () {
|
||||
const a = ['a', 'b', 'c', 'd'];
|
||||
remove(a, 'c');
|
||||
expect(a).to.eql(['a', 'b', 'd']);
|
||||
remove(a, 'x');
|
||||
expect(a).to.eql(['a', 'b', 'd']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reverseSubArray', function () {
|
||||
it('returns expected value', function () {
|
||||
let arr;
|
||||
const expected = [1, 2, 3, 4, 5, 6];
|
||||
|
||||
arr = [1, 5, 4, 3, 2, 6];
|
||||
reverseSubArray(arr, 1, 4);
|
||||
expect(arr).to.eql(expected);
|
||||
|
||||
arr = [3, 2, 1, 4, 5, 6];
|
||||
reverseSubArray(arr, 0, 2);
|
||||
expect(arr).to.eql(expected);
|
||||
|
||||
arr = [1, 2, 3, 6, 5, 4];
|
||||
reverseSubArray(arr, 3, 5);
|
||||
expect(arr).to.eql(expected);
|
||||
|
||||
arr = [6, 5, 4, 3, 2, 1];
|
||||
reverseSubArray(arr, 0, 5);
|
||||
expect(arr).to.eql(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stableSort', function () {
|
||||
let arr, wantedSortedValues;
|
||||
|
||||
beforeEach(function () {
|
||||
arr = [
|
||||
{key: 3, val: 'a'},
|
||||
{key: 2, val: 'b'},
|
||||
{key: 3, val: 'c'},
|
||||
{key: 4, val: 'd'},
|
||||
{key: 3, val: 'e'},
|
||||
];
|
||||
wantedSortedValues = ['b', 'a', 'c', 'e', 'd'];
|
||||
});
|
||||
|
||||
it('works on an array with custom comparison function', function () {
|
||||
function comparisonFn(obj1, obj2) {
|
||||
return obj1.key - obj2.key;
|
||||
}
|
||||
stableSort(arr, comparisonFn);
|
||||
const sortedValues = [];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
sortedValues.push(arr[i].val);
|
||||
}
|
||||
expect(wantedSortedValues).to.eql(sortedValues);
|
||||
});
|
||||
});
|
||||
});
|
||||
12
test/node/ol/asserts.test.js
Normal file
12
test/node/ol/asserts.test.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import expect from '../expect.js';
|
||||
import {assert} from '../../../src/ol/asserts.js';
|
||||
|
||||
describe('ol/asserts.js', function () {
|
||||
describe('assert', function () {
|
||||
it('throws an exception', function () {
|
||||
expect(function () {
|
||||
assert(false, 42);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import Circle from '../../../../src/ol/geom/Circle.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import Circle from '../../../src/ol/geom/Circle.js';
|
||||
import Projection from '../../../src/ol/proj/Projection.js';
|
||||
import expect from '../expect.js';
|
||||
import {
|
||||
add as addCoordinate,
|
||||
closestOnCircle,
|
||||
@@ -13,8 +14,8 @@ import {
|
||||
toStringHDMS,
|
||||
toStringXY,
|
||||
wrapX,
|
||||
} from '../../../../src/ol/coordinate.js';
|
||||
import {get} from '../../../../src/ol/proj.js';
|
||||
} from '../../../src/ol/coordinate.js';
|
||||
import {get} from '../../../src/ol/proj.js';
|
||||
|
||||
describe('ol.coordinate', function () {
|
||||
describe('#add', function () {
|
||||
@@ -1,4 +1,5 @@
|
||||
import {getFontParameters} from '../../../../src/ol/css.js';
|
||||
import expect from '../expect.js';
|
||||
import {getFontParameters} from '../../../src/ol/css.js';
|
||||
|
||||
describe('ol.css', function () {
|
||||
describe('getFontParameters()', function () {
|
||||
@@ -1,7 +1,9 @@
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import {listen, listenOnce, unlistenByKey} from '../../../../src/ol/events.js';
|
||||
import EventTarget from '../../../src/ol/events/Target.js';
|
||||
import expect from '../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {listen, listenOnce, unlistenByKey} from '../../../src/ol/events.js';
|
||||
|
||||
describe('ol.events', function () {
|
||||
describe('ol/events.js', function () {
|
||||
let add, target;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -1,9 +1,10 @@
|
||||
import Disposable from '../../../../../src/ol/Disposable.js';
|
||||
import Event from '../../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../../src/ol/events/Target.js';
|
||||
import {listen} from '../../../../../src/ol/events.js';
|
||||
import Disposable from '../../../../src/ol/Disposable.js';
|
||||
import Event from '../../../../src/ol/events/Event.js';
|
||||
import EventTarget from '../../../../src/ol/events/Target.js';
|
||||
import expect from '../../expect.js';
|
||||
import {listen} from '../../../../src/ol/events.js';
|
||||
|
||||
describe('ol.events.EventTarget', function () {
|
||||
describe('ol/events/Target.js', function () {
|
||||
let called, events, eventTarget, spy1, spy2, spy3;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -166,7 +167,7 @@ describe('ol.events.EventTarget', function () {
|
||||
|
||||
describe('#dispose()', function () {
|
||||
it('cleans up foreign references', function () {
|
||||
listen(eventTarget, 'foo', spy1, document);
|
||||
listen(eventTarget, 'foo', spy1);
|
||||
expect(eventTarget.hasListener('foo')).to.be(true);
|
||||
eventTarget.dispose();
|
||||
expect(eventTarget.hasListener('foo')).to.be(false);
|
||||
@@ -1,9 +1,11 @@
|
||||
import Event, {
|
||||
preventDefault,
|
||||
stopPropagation,
|
||||
} from '../../../../../src/ol/events/Event.js';
|
||||
} from '../../../../src/ol/events/Event.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('ol.events.Event', function () {
|
||||
describe('ol/events/Event.js', function () {
|
||||
describe('constructor', function () {
|
||||
it('takes a type as argument', function () {
|
||||
const event = new Event('foo');
|
||||
@@ -1,8 +1,11 @@
|
||||
import * as _ol_extent_ from '../../../../src/ol/extent.js';
|
||||
import {get, getTransform} from '../../../../src/ol/proj.js';
|
||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||
import * as _ol_extent_ from '../../../src/ol/extent.js';
|
||||
import expect from '../expect.js';
|
||||
import proj4 from 'proj4';
|
||||
import sinon from 'sinon';
|
||||
import {get, getTransform} from '../../../src/ol/proj.js';
|
||||
import {register} from '../../../src/ol/proj/proj4.js';
|
||||
|
||||
describe('ol.extent', function () {
|
||||
describe('ol/extent.js', function () {
|
||||
describe('buffer', function () {
|
||||
it('buffers an extent by some value', function () {
|
||||
const extent = [-10, -20, 10, 20];
|
||||
@@ -1,6 +1,7 @@
|
||||
import {memoizeOne} from '../../../../src/ol/functions.js';
|
||||
import expect from '../expect.js';
|
||||
import {memoizeOne} from '../../../src/ol/functions.js';
|
||||
|
||||
describe('ol/functions', function () {
|
||||
describe('ol/functions.js', function () {
|
||||
describe('memoizeOne()', function () {
|
||||
it('returns the result from the first call when called a second time with the same args', function () {
|
||||
const arg1 = {};
|
||||
@@ -1,6 +1,8 @@
|
||||
import Circle from '../../../../../src/ol/geom/Circle.js';
|
||||
import Circle from '../../../../src/ol/geom/Circle.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('ol.geom.Circle', function () {
|
||||
describe('ol/geom/Circle.js', function () {
|
||||
describe('with a unit circle', function () {
|
||||
let circle;
|
||||
beforeEach(function () {
|
||||
@@ -1,10 +1,12 @@
|
||||
import Geometry from '../../../../../src/ol/geom/Geometry.js';
|
||||
import GeometryCollection from '../../../../../src/ol/geom/GeometryCollection.js';
|
||||
import LineString from '../../../../../src/ol/geom/LineString.js';
|
||||
import Point from '../../../../../src/ol/geom/Point.js';
|
||||
import Polygon from '../../../../../src/ol/geom/Polygon.js';
|
||||
import Geometry from '../../../../src/ol/geom/Geometry.js';
|
||||
import GeometryCollection from '../../../../src/ol/geom/GeometryCollection.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('ol.geom.GeometryCollection', function () {
|
||||
describe('ol/geom/GeometryCollection.js', function () {
|
||||
const outer = [
|
||||
[0, 0],
|
||||
[0, 10],
|
||||
@@ -1,7 +1,9 @@
|
||||
import LineString from '../../../../../src/ol/geom/LineString.js';
|
||||
import {isEmpty} from '../../../../../src/ol/extent.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {isEmpty} from '../../../../src/ol/extent.js';
|
||||
|
||||
describe('ol.geom.LineString', function () {
|
||||
describe('ol/geom/LineString.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new LineString(null);
|
||||
@@ -1,8 +1,9 @@
|
||||
import LineString from '../../../../../src/ol/geom/LineString.js';
|
||||
import MultiLineString from '../../../../../src/ol/geom/MultiLineString.js';
|
||||
import {isEmpty} from '../../../../../src/ol/extent.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
|
||||
import expect from '../../expect.js';
|
||||
import {isEmpty} from '../../../../src/ol/extent.js';
|
||||
|
||||
describe('ol.geom.MultiLineString', function () {
|
||||
describe('ol/geom/MultiLineString.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new MultiLineString(null);
|
||||
@@ -1,8 +1,10 @@
|
||||
import MultiPoint from '../../../../../src/ol/geom/MultiPoint.js';
|
||||
import Point from '../../../../../src/ol/geom/Point.js';
|
||||
import {isEmpty} from '../../../../../src/ol/extent.js';
|
||||
import MultiPoint from '../../../../src/ol/geom/MultiPoint.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {isEmpty} from '../../../../src/ol/extent.js';
|
||||
|
||||
describe('ol.geom.MultiPoint', function () {
|
||||
describe('ol/geom/MultiPoint.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new MultiPoint(null);
|
||||
@@ -1,7 +1,8 @@
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import Polygon from '../../../../../src/ol/geom/Polygon.js';
|
||||
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
|
||||
import Polygon from '../../../../src/ol/geom/Polygon.js';
|
||||
import expect from '../../expect.js';
|
||||
|
||||
describe('ol.geom.MultiPolygon', function () {
|
||||
describe('ol/geom/MultiPolygon.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new MultiPolygon(null);
|
||||
@@ -1,10 +1,12 @@
|
||||
import Point from '../../../../../src/ol/geom/Point.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import expect from '../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {
|
||||
get as getProjection,
|
||||
getTransformFromProjections,
|
||||
} from '../../../../../src/ol/proj.js';
|
||||
} from '../../../../src/ol/proj.js';
|
||||
|
||||
describe('ol.geom.Point', function () {
|
||||
describe('ol/geom/Point.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new Point(null);
|
||||
@@ -1,12 +1,13 @@
|
||||
import Circle from '../../../../../src/ol/geom/Circle.js';
|
||||
import LinearRing from '../../../../../src/ol/geom/LinearRing.js';
|
||||
import Circle from '../../../../src/ol/geom/Circle.js';
|
||||
import LinearRing from '../../../../src/ol/geom/LinearRing.js';
|
||||
import Polygon, {
|
||||
fromCircle,
|
||||
fromExtent,
|
||||
} from '../../../../../src/ol/geom/Polygon.js';
|
||||
import {boundingExtent, isEmpty} from '../../../../../src/ol/extent.js';
|
||||
} from '../../../../src/ol/geom/Polygon.js';
|
||||
import expect from '../../expect.js';
|
||||
import {boundingExtent, isEmpty} from '../../../../src/ol/extent.js';
|
||||
|
||||
describe('ol/geom/Polygon', function () {
|
||||
describe('ol/geom/Polygon.js', function () {
|
||||
it('cannot be constructed with a null geometry', function () {
|
||||
expect(function () {
|
||||
return new Polygon(null);
|
||||
@@ -1,10 +1,8 @@
|
||||
import {
|
||||
linearRing,
|
||||
linearRings,
|
||||
} from '../../../../../../src/ol/geom/flat/area.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
|
||||
|
||||
describe('ol.geom.flat.area', function () {
|
||||
describe('ol.geom.flat.area.linearRing', function () {
|
||||
describe('ol/geom/flat/area.js', function () {
|
||||
describe('linearRing', function () {
|
||||
it('calculates the area of a triangle', function () {
|
||||
const area = linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
|
||||
expect(area).to.be(0.5);
|
||||
@@ -16,7 +14,7 @@ describe('ol.geom.flat.area', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.area.linearRings', function () {
|
||||
describe('linearRings', function () {
|
||||
it('calculates the area with holes', function () {
|
||||
const area = linearRings(
|
||||
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2],
|
||||
@@ -1,8 +1,9 @@
|
||||
import MultiPolygon from '../../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import {linearRingss as linearRingssCenter} from '../../../../../../src/ol/geom/flat/center.js';
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
|
||||
|
||||
describe('ol.geom.flat.center', function () {
|
||||
describe('ol.geom.flat.center.linearRingss', function () {
|
||||
describe('ol/geom/flat/center.js', function () {
|
||||
describe('linearRingss', function () {
|
||||
it('calculates the center of a square', function () {
|
||||
const squareMultiPoly = new MultiPolygon([
|
||||
[
|
||||
@@ -1,13 +1,14 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
assignClosestPoint,
|
||||
maxSquaredDelta,
|
||||
} from '../../../../../../src/ol/geom/flat/closest.js';
|
||||
} from '../../../../../src/ol/geom/flat/closest.js';
|
||||
|
||||
describe('ol.geom.flat.closest', function () {
|
||||
describe('ol/geom/flat/closest.js', function () {
|
||||
describe('with simple data', function () {
|
||||
const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
|
||||
|
||||
describe('ol.geom.flat.closest.maxSquaredDelta', function () {
|
||||
describe('maxSquaredDelta', function () {
|
||||
it('returns the expected value in simple cases', function () {
|
||||
expect(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
@@ -15,7 +16,7 @@ describe('ol.geom.flat.closest', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.closest.assignClosestPoint', function () {
|
||||
describe('assignClosestPoint', function () {
|
||||
it('returns the expected value', function () {
|
||||
const maxDelta = Math.sqrt(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
@@ -290,7 +291,7 @@ describe('ol.geom.flat.closest', function () {
|
||||
480.77,
|
||||
];
|
||||
|
||||
describe('ol.geom.closest.maxSquaredDelta', function () {
|
||||
describe('maxSquaredDelta', function () {
|
||||
it('returns the expected value', function () {
|
||||
expect(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
@@ -298,7 +299,7 @@ describe('ol.geom.flat.closest', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.closest.assignClosestPoint', function () {
|
||||
describe('assignClosestPoint', function () {
|
||||
it('returns the expected value', function () {
|
||||
const maxDelta = Math.sqrt(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
@@ -358,7 +359,7 @@ describe('ol.geom.flat.closest', function () {
|
||||
const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
|
||||
const stride = 4;
|
||||
|
||||
describe('ol.geom.flat.closest.assignClosestPoint', function () {
|
||||
describe('assignClosestPoint', function () {
|
||||
it('interpolates M coordinates', function () {
|
||||
const maxDelta = Math.sqrt(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, stride, 0)
|
||||
@@ -1,6 +1,7 @@
|
||||
import {linearRingContainsXY} from '../../../../../../src/ol/geom/flat/contains.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js';
|
||||
|
||||
describe('ol.geom.flat.contains', function () {
|
||||
describe('ol/geom/flat/contains.js', function () {
|
||||
describe('with simple data', function () {
|
||||
const flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1];
|
||||
const flatCoordinatesNonSimple = [
|
||||
@@ -26,7 +27,7 @@ describe('ol.geom.flat.contains', function () {
|
||||
4,
|
||||
];
|
||||
|
||||
describe('ol.geom.flat.contains.linearRingContainsXY', function () {
|
||||
describe('linearRingContainsXY', function () {
|
||||
it('returns true for point inside a simple polygon', function () {
|
||||
expect(
|
||||
linearRingContainsXY(
|
||||
@@ -1,10 +1,11 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
deflateCoordinates,
|
||||
deflateCoordinatesArray,
|
||||
} from '../../../../../../src/ol/geom/flat/deflate.js';
|
||||
} from '../../../../../src/ol/geom/flat/deflate.js';
|
||||
|
||||
describe('ol.geom.flat.deflate', function () {
|
||||
describe('ol.geom.flat.deflate.deflateCoordinates', function () {
|
||||
describe('ol/geom/flat/deflate.js', function () {
|
||||
describe('deflateCoordinates', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [];
|
||||
@@ -25,7 +26,7 @@ describe('ol.geom.flat.deflate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.deflate.deflateCoordinatesArray', function () {
|
||||
describe('deflateCoordinatesArray', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [];
|
||||
@@ -1,7 +1,8 @@
|
||||
import {flipXY} from '../../../../../../src/ol/geom/flat/flip.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
|
||||
|
||||
describe('ol.geom.flat.flip', function () {
|
||||
describe('ol.geom.flat.flip.flipXY', function () {
|
||||
describe('ol/geom/flat/flip.js', function () {
|
||||
describe('flipXY', function () {
|
||||
it('can flip XY coordinates', function () {
|
||||
const flatCoordinates = flipXY([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(flatCoordinates).to.eql([2, 1, 4, 3]);
|
||||
@@ -1,10 +1,11 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
inflateCoordinates,
|
||||
inflateCoordinatesArray,
|
||||
} from '../../../../../../src/ol/geom/flat/inflate.js';
|
||||
} from '../../../../../src/ol/geom/flat/inflate.js';
|
||||
|
||||
describe('ol.geom.flat.inflate', function () {
|
||||
describe('ol.geom.flat.inflate.inflateCoordinates', function () {
|
||||
describe('ol/geom/flat/inflate.js', function () {
|
||||
describe('inflateCoordinates', function () {
|
||||
it('inflates coordinates', function () {
|
||||
const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(coordinates).to.eql([
|
||||
@@ -14,7 +15,7 @@ describe('ol.geom.flat.inflate', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.inflate.inflateCoordinatesArray', function () {
|
||||
describe('inflateCoordinatesArray', function () {
|
||||
it('inflates arrays of coordinates', function () {
|
||||
const coordinatess = inflateCoordinatesArray(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8],
|
||||
@@ -1,7 +1,8 @@
|
||||
import {interpolatePoint} from '../../../../../../src/ol/geom/flat/interpolate.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js';
|
||||
|
||||
describe('ol.geom.flat.interpolate', function () {
|
||||
describe('ol.geom.flat.interpolate.interpolatePoint', function () {
|
||||
describe('ol/geom/flat/interpolate.js', function () {
|
||||
describe('interpolatePoint', function () {
|
||||
it('returns the expected value for single points', function () {
|
||||
const flatCoordinates = [0, 1];
|
||||
const point = interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
|
||||
@@ -1,11 +1,12 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
intersectsLineString,
|
||||
intersectsLinearRing,
|
||||
intersectsLinearRingArray,
|
||||
} from '../../../../../../src/ol/geom/flat/intersectsextent.js';
|
||||
} from '../../../../../src/ol/geom/flat/intersectsextent.js';
|
||||
|
||||
describe('ol.geom.flat.intersectsextent', function () {
|
||||
describe('ol.geom.flat.intersectsextent.intersectsLineString', function () {
|
||||
describe('ol/geom/flat/intersectsextent.js', function () {
|
||||
describe('intersectsLineString', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [0, 0, 1, 1, 2, 2];
|
||||
@@ -88,7 +89,7 @@ describe('ol.geom.flat.intersectsextent', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function () {
|
||||
describe('intersectsLinearRing', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0];
|
||||
@@ -138,7 +139,7 @@ describe('ol.geom.flat.intersectsextent', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function () {
|
||||
describe('intersectsLinearRingArray', function () {
|
||||
let flatCoordinates;
|
||||
let ends;
|
||||
beforeEach(function () {
|
||||
@@ -1,10 +1,11 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
lineStringLength,
|
||||
linearRingLength,
|
||||
} from '../../../../../../src/ol/geom/flat/length.js';
|
||||
} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
describe('ol.geom.flat.length', function () {
|
||||
describe('ol.geom.flat.length.lineStringLength', function () {
|
||||
describe('ol/geom/flat/length.js', function () {
|
||||
describe('lineStringLength', function () {
|
||||
describe('stride = 2', function () {
|
||||
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
|
||||
const stride = 2;
|
||||
@@ -64,7 +65,7 @@ describe('ol.geom.flat.length', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.length.linearRingLength', function () {
|
||||
describe('linearRingLength', function () {
|
||||
it('calculates the total length of a simple linearRing', function () {
|
||||
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
|
||||
const stride = 2;
|
||||
@@ -1,13 +1,14 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
linearRingIsClockwise,
|
||||
linearRingsAreOriented,
|
||||
linearRingssAreOriented,
|
||||
orientLinearRings,
|
||||
orientLinearRingsArray,
|
||||
} from '../../../../../../src/ol/geom/flat/orient.js';
|
||||
} from '../../../../../src/ol/geom/flat/orient.js';
|
||||
|
||||
describe('ol.geom.flat.orient', function () {
|
||||
describe('ol.geom.flat.orient.linearRingIsClockwise', function () {
|
||||
describe('ol/geom/flat/orient.js', function () {
|
||||
describe('linearRingIsClockwise', function () {
|
||||
it('identifies clockwise rings', function () {
|
||||
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
@@ -86,7 +87,7 @@ describe('ol.geom.flat.orient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.linearRingsAreOriented', function () {
|
||||
describe('linearRingsAreOriented', function () {
|
||||
const oriented = linearRingsAreOriented;
|
||||
|
||||
const rightCoords = [
|
||||
@@ -148,7 +149,7 @@ describe('ol.geom.flat.orient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.linearRingssAreOriented', function () {
|
||||
describe('linearRingssAreOriented', function () {
|
||||
const oriented = linearRingssAreOriented;
|
||||
|
||||
const rightCoords = [
|
||||
@@ -253,7 +254,7 @@ describe('ol.geom.flat.orient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.orientLinearRings', function () {
|
||||
describe('orientLinearRings', function () {
|
||||
const orient = orientLinearRings;
|
||||
|
||||
const rightCoords = [
|
||||
@@ -325,7 +326,7 @@ describe('ol.geom.flat.orient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.orient.orientLinearRingsArray', function () {
|
||||
describe('orientLinearRingsArray', function () {
|
||||
const orient = orientLinearRingsArray;
|
||||
|
||||
const rightCoords = [
|
||||
@@ -1,7 +1,8 @@
|
||||
import {coordinates as reverseCoordinates} from '../../../../../../src/ol/geom/flat/reverse.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js';
|
||||
|
||||
describe('ol.geom.flat.reverse', function () {
|
||||
describe('ol.geom.flat.reverse.coordinates', function () {
|
||||
describe('ol/geom/flat/reverse.js', function () {
|
||||
describe('coordinates', function () {
|
||||
describe('with a stride of 2', function () {
|
||||
it('can reverse empty flat coordinates', function () {
|
||||
const flatCoordinates = [];
|
||||
@@ -1,7 +1,9 @@
|
||||
import {forEach as forEachSegment} from '../../../../../../src/ol/geom/flat/segments.js';
|
||||
import expect from '../../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js';
|
||||
|
||||
describe('ol.geom.flat.segments', function () {
|
||||
describe('ol.geom.flat.segments.forEach', function () {
|
||||
describe('ol/geom/flat/segments.js', function () {
|
||||
describe('forEach', function () {
|
||||
let flatCoordinates, offset, end, stride;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [0, 0, 1, 1, 2, 2, 3, 3];
|
||||
@@ -1,11 +1,12 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
douglasPeucker,
|
||||
quantize,
|
||||
radialDistance,
|
||||
simplifyLineString,
|
||||
} from '../../../../../../src/ol/geom/flat/simplify.js';
|
||||
} from '../../../../../src/ol/geom/flat/simplify.js';
|
||||
|
||||
describe('ol.geom.flat.simplify', function () {
|
||||
describe('ol/geom/flat/simplify.js', function () {
|
||||
const flatCoordinates = [
|
||||
224.55,
|
||||
250.15,
|
||||
@@ -532,7 +533,7 @@ describe('ol.geom.flat.simplify', function () {
|
||||
480.77,
|
||||
];
|
||||
|
||||
describe('ol.geom.flat.simplify.simplifyLineString', function () {
|
||||
describe('simplifyLineString', function () {
|
||||
it('works with empty line strings', function () {
|
||||
expect(simplifyLineString([], 0, 0, 2, 1, true)).to.eql([]);
|
||||
expect(simplifyLineString([], 0, 0, 2, 1, false)).to.eql([]);
|
||||
@@ -570,7 +571,7 @@ describe('ol.geom.flat.simplify', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.simplify.radialDistance', function () {
|
||||
describe('radialDistance', function () {
|
||||
let dest;
|
||||
beforeEach(function () {
|
||||
dest = [];
|
||||
@@ -673,7 +674,7 @@ describe('ol.geom.flat.simplify', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.simplify.douglasPeucker', function () {
|
||||
describe('douglasPeucker', function () {
|
||||
let dest;
|
||||
beforeEach(function () {
|
||||
dest = [];
|
||||
@@ -809,7 +810,7 @@ describe('ol.geom.flat.simplify', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.simplify.quantize', function () {
|
||||
describe('quantize', function () {
|
||||
it('handles empty coordinates', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(quantize([], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
|
||||
@@ -1,7 +1,8 @@
|
||||
import {matchingChunk} from '../../../../../../src/ol/geom/flat/straightchunk.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js';
|
||||
|
||||
describe('ol.geom.flat.straightchunk', function () {
|
||||
describe('ol.geom.flat.straightchunk.matchingChunk', function () {
|
||||
describe('ol/geom/flat/straightchunk.js', function () {
|
||||
describe('matchingChunk', function () {
|
||||
describe('single segment with stride == 3', function () {
|
||||
const flatCoords = [0, 0, 42, 1, 1, 42];
|
||||
const stride = 3;
|
||||
@@ -1,7 +1,8 @@
|
||||
import {drawTextOnPath} from '../../../../../../src/ol/geom/flat/textpath.js';
|
||||
import {lineStringLength} from '../../../../../../src/ol/geom/flat/length.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js';
|
||||
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
describe('ol.geom.flat.drawTextOnPath', function () {
|
||||
describe('ol/geom/flat/drawTextOnPath.js', function () {
|
||||
const horizontal = [0, 0, 100, 0];
|
||||
const vertical = [0, 0, 0, 100];
|
||||
const diagonal = [0, 0, 100, 100];
|
||||
@@ -1,7 +1,8 @@
|
||||
import {lineStringIsClosed} from '../../../../../../src/ol/geom/flat/topology.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js';
|
||||
|
||||
describe('ol.geom.flat.topology', function () {
|
||||
describe('ol.geom.flat.topology.lineStringIsClosed', function () {
|
||||
describe('ol/geom/flat/topology.js', function () {
|
||||
describe('lineStringIsClosed', function () {
|
||||
it('identifies closed lines aka boundaries', function () {
|
||||
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
|
||||
const isClosed = lineStringIsClosed(
|
||||
@@ -1,12 +1,10 @@
|
||||
import MultiPolygon from '../../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import {
|
||||
rotate,
|
||||
translate,
|
||||
} from '../../../../../../src/ol/geom/flat/transform.js';
|
||||
import {transformGeom2D} from '../../../../../../src/ol/geom/SimpleGeometry.js';
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js';
|
||||
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
|
||||
|
||||
describe('ol.geom.flat.transform', function () {
|
||||
describe('ol.geom.flat.transform.transform2D', function () {
|
||||
describe('ol/geom/flat/transform.js', function () {
|
||||
describe('transform2D', function () {
|
||||
it('transforms a Simple Geometry to 2D', function () {
|
||||
const multiPolygonGeometry = new MultiPolygon([
|
||||
[
|
||||
@@ -79,7 +77,7 @@ describe('ol.geom.flat.transform', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.transform.translate', function () {
|
||||
describe('translate', function () {
|
||||
it('translates the coordinates array', function () {
|
||||
const multiPolygon = new MultiPolygon([
|
||||
[
|
||||
@@ -148,7 +146,7 @@ describe('ol.geom.flat.transform', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.geom.flat.transform.rotate', function () {
|
||||
describe('rotate', function () {
|
||||
it('rotates the coordinates array', function () {
|
||||
const multiPolygon = new MultiPolygon([
|
||||
[
|
||||
165
test/node/ol/math.test.js
Normal file
165
test/node/ol/math.test.js
Normal file
@@ -0,0 +1,165 @@
|
||||
import expect from '../expect.js';
|
||||
import {
|
||||
clamp,
|
||||
cosh,
|
||||
lerp,
|
||||
log2,
|
||||
modulo,
|
||||
solveLinearSystem,
|
||||
toDegrees,
|
||||
toRadians,
|
||||
} from '../../../src/ol/math.js';
|
||||
|
||||
describe('ol/math.js', () => {
|
||||
describe('clamp', function () {
|
||||
it('returns the correct value at -Infinity', function () {
|
||||
expect(clamp(-Infinity, 10, 20)).to.eql(10);
|
||||
});
|
||||
|
||||
it('returns the correct value at min', function () {
|
||||
expect(clamp(10, 10, 20)).to.eql(10);
|
||||
});
|
||||
|
||||
it('returns the correct value at mid point', function () {
|
||||
expect(clamp(15, 10, 20)).to.eql(15);
|
||||
});
|
||||
|
||||
it('returns the correct value at max', function () {
|
||||
expect(clamp(20, 10, 20)).to.eql(20);
|
||||
});
|
||||
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(clamp(Infinity, 10, 20)).to.eql(20);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cosh', function () {
|
||||
it('returns the correct value at -Infinity', function () {
|
||||
expect(cosh(-Infinity)).to.eql(Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at -1', function () {
|
||||
expect(cosh(-1)).to.roughlyEqual(1.5430806348152437, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(cosh(0)).to.eql(1);
|
||||
});
|
||||
|
||||
it('returns the correct value at 1', function () {
|
||||
expect(cosh(1)).to.roughlyEqual(1.5430806348152437, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(cosh(Infinity)).to.eql(Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
describe('log2', function () {
|
||||
it('returns the correct value at Infinity', function () {
|
||||
expect(log2(Infinity)).to.eql(Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at 3', function () {
|
||||
expect(log2(3)).to.roughlyEqual(1.584962500721156, 1e-9);
|
||||
});
|
||||
|
||||
it('returns the correct value at 2', function () {
|
||||
expect(log2(2)).to.eql(1);
|
||||
});
|
||||
|
||||
it('returns the correct value at 1', function () {
|
||||
expect(log2(1)).to.eql(0);
|
||||
});
|
||||
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(log2(0)).to.eql(-Infinity);
|
||||
});
|
||||
|
||||
it('returns the correct value at -1', function () {
|
||||
expect(log2(-1).toString()).to.eql('NaN');
|
||||
});
|
||||
});
|
||||
|
||||
describe('solveLinearSystem', function () {
|
||||
it('calculates correctly', function () {
|
||||
const result = solveLinearSystem([
|
||||
[2, 1, 3, 1],
|
||||
[2, 6, 8, 3],
|
||||
[6, 8, 18, 5],
|
||||
]);
|
||||
expect(result[0]).to.roughlyEqual(0.3, 1e-9);
|
||||
expect(result[1]).to.roughlyEqual(0.4, 1e-9);
|
||||
expect(result[2]).to.roughlyEqual(0, 1e-9);
|
||||
});
|
||||
|
||||
it('can handle singular matrix', function () {
|
||||
const result = solveLinearSystem([
|
||||
[2, 1, 3, 1],
|
||||
[2, 6, 8, 3],
|
||||
[2, 1, 3, 1],
|
||||
]);
|
||||
expect(result).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toDegrees', function () {
|
||||
it('returns the correct value at -π', function () {
|
||||
expect(toDegrees(-Math.PI)).to.be(-180);
|
||||
});
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(toDegrees(0)).to.be(0);
|
||||
});
|
||||
it('returns the correct value at π', function () {
|
||||
expect(toDegrees(Math.PI)).to.be(180);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toRadians', function () {
|
||||
it('returns the correct value at -180', function () {
|
||||
expect(toRadians(-180)).to.be(-Math.PI);
|
||||
});
|
||||
it('returns the correct value at 0', function () {
|
||||
expect(toRadians(0)).to.be(0);
|
||||
});
|
||||
it('returns the correct value at 180', function () {
|
||||
expect(toRadians(180)).to.be(Math.PI);
|
||||
});
|
||||
});
|
||||
|
||||
describe('modulo', function () {
|
||||
it('256 / 8 returns 0', function () {
|
||||
expect(modulo(256, 8)).to.be(0);
|
||||
});
|
||||
it('positive and positive returns a positive ', function () {
|
||||
expect(modulo(7, 8)).to.be(7);
|
||||
});
|
||||
it('same Dividend and Divisor returns 0', function () {
|
||||
expect(modulo(4, 4)).to.be(0);
|
||||
});
|
||||
it('negative and positive returns positive', function () {
|
||||
expect(modulo(-3, 4)).to.be(1);
|
||||
});
|
||||
it('negative and negative returns negative', function () {
|
||||
expect(modulo(-4, -5)).to.be(-4);
|
||||
expect(modulo(-3, -4)).to.be(-3);
|
||||
});
|
||||
it('positive and negative returns negative', function () {
|
||||
expect(modulo(3, -4)).to.be(-1);
|
||||
expect(modulo(1, -5)).to.be(-4);
|
||||
expect(modulo(6, -5)).to.be(-4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lerp', function () {
|
||||
it('correctly interpolated numbers', function () {
|
||||
expect(lerp(0, 0, 0)).to.be(0);
|
||||
expect(lerp(0, 1, 0)).to.be(0);
|
||||
expect(lerp(1, 11, 5)).to.be(51);
|
||||
});
|
||||
it('correctly interpolates floats', function () {
|
||||
expect(lerp(0, 1, 0.5)).to.be(0.5);
|
||||
expect(lerp(0.25, 0.75, 0.5)).to.be(0.5);
|
||||
});
|
||||
});
|
||||
});
|
||||
67
test/node/ol/obj.test.js
Normal file
67
test/node/ol/obj.test.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import expect from '../expect.js';
|
||||
import {assign, clear, getValues, isEmpty} from '../../../src/ol/obj.js';
|
||||
|
||||
describe('ol/obj.js', () => {
|
||||
describe('assign()', function () {
|
||||
it('is an alias for Object.assign() where available', function () {
|
||||
if (typeof Object.assign === 'function') {
|
||||
expect(assign).to.be(Object.assign);
|
||||
}
|
||||
});
|
||||
|
||||
it('assigns properties from a source object to a target object', function () {
|
||||
const source = {
|
||||
sourceProp1: 'sourceValue1',
|
||||
sourceProp2: 'sourceValue2',
|
||||
};
|
||||
|
||||
const target = {
|
||||
sourceProp1: 'overridden',
|
||||
targetProp1: 'targetValue1',
|
||||
};
|
||||
|
||||
const assigned = assign(target, source);
|
||||
expect(assigned).to.be(target);
|
||||
expect(assigned.sourceProp1).to.be('sourceValue1');
|
||||
expect(assigned.sourceProp2).to.be('sourceValue2');
|
||||
expect(assigned.targetProp1).to.be('targetValue1');
|
||||
});
|
||||
|
||||
it('throws a TypeError with `undefined` as target', function () {
|
||||
expect(() => assign()).to.throwException(
|
||||
/Cannot convert undefined or null to object/
|
||||
);
|
||||
});
|
||||
|
||||
it('throws a TypeError with `null` as target', function () {
|
||||
expect(() => assign(null)).to.throwException(
|
||||
/Cannot convert undefined or null to object/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('clear()', function () {
|
||||
it('removes all properties from an object', function () {
|
||||
expect(isEmpty(clear({foo: 'bar'}))).to.be(true);
|
||||
expect(isEmpty(clear({foo: 'bar', num: 42}))).to.be(true);
|
||||
expect(isEmpty(clear({}))).to.be(true);
|
||||
expect(isEmpty(clear(null))).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getValues()', function () {
|
||||
it('gets a list of property values from an object', function () {
|
||||
expect(getValues({foo: 'bar', num: 42}).sort()).to.eql([42, 'bar']);
|
||||
expect(getValues([])).to.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isEmpty()', function () {
|
||||
it('checks if an object has any properties', function () {
|
||||
expect(isEmpty({})).to.be(true);
|
||||
expect(isEmpty(null)).to.be(true);
|
||||
expect(isEmpty({foo: 'bar'})).to.be(false);
|
||||
expect(isEmpty({foo: false})).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,8 @@
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import Units from '../../../../src/ol/proj/Units.js';
|
||||
import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js';
|
||||
import Projection from '../../../src/ol/proj/Projection.js';
|
||||
import Units from '../../../src/ol/proj/Units.js';
|
||||
import expect from '../expect.js';
|
||||
import proj4 from 'proj4';
|
||||
import {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js';
|
||||
import {
|
||||
METERS_PER_UNIT,
|
||||
addCommon,
|
||||
@@ -22,11 +24,11 @@ import {
|
||||
transform,
|
||||
transformExtent,
|
||||
useGeographic,
|
||||
} from '../../../../src/ol/proj.js';
|
||||
import {METERS_PER_UNIT as metersPerDegree} from '../../../../src/ol/proj/epsg4326.js';
|
||||
import {register} from '../../../../src/ol/proj/proj4.js';
|
||||
} from '../../../src/ol/proj.js';
|
||||
import {METERS_PER_UNIT as metersPerDegree} from '../../../src/ol/proj/epsg4326.js';
|
||||
import {register} from '../../../src/ol/proj/proj4.js';
|
||||
|
||||
describe('ol.proj', function () {
|
||||
describe('ol/proj.js', function () {
|
||||
afterEach(function () {
|
||||
clearAllProjections();
|
||||
clearUserProjection();
|
||||
@@ -1,6 +1,7 @@
|
||||
import LinkedList from '../../../../../src/ol/structs/LinkedList.js';
|
||||
import LinkedList from '../../../../src/ol/structs/LinkedList.js';
|
||||
import expect from '../../expect.js';
|
||||
|
||||
describe('ol.structs.LinkedList', function () {
|
||||
describe('ol/structs/LinkedList.js', function () {
|
||||
let ll;
|
||||
const item = {};
|
||||
const item2 = {};
|
||||
@@ -1,6 +1,7 @@
|
||||
import LRUCache from '../../../../../src/ol/structs/LRUCache.js';
|
||||
import LRUCache from '../../../../src/ol/structs/LRUCache.js';
|
||||
import expect from '../../expect.js';
|
||||
|
||||
describe('ol.structs.LRUCache', function () {
|
||||
describe('ol/structs/LRUCache.js', function () {
|
||||
let lruCache;
|
||||
|
||||
function fillLRUCache(lruCache) {
|
||||
@@ -1,8 +1,7 @@
|
||||
import PriorityQueue, {
|
||||
DROP,
|
||||
} from '../../../../../src/ol/structs/PriorityQueue.js';
|
||||
import PriorityQueue, {DROP} from '../../../../src/ol/structs/PriorityQueue.js';
|
||||
import expect from '../../expect.js';
|
||||
|
||||
describe('ol.structs.PriorityQueue', function () {
|
||||
describe('ol/structs/PriorityQueue.js', function () {
|
||||
const identity = function (a) {
|
||||
return a;
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import RBush from '../../../../../src/ol/structs/RBush.js';
|
||||
import RBush from '../../../../src/ol/structs/RBush.js';
|
||||
import expect from '../../expect.js';
|
||||
|
||||
describe('ol.structs.RBush', function () {
|
||||
describe('ol/structs/RBush.js', function () {
|
||||
let rBush;
|
||||
beforeEach(function () {
|
||||
rBush = new RBush();
|
||||
@@ -1,24 +1,25 @@
|
||||
import Projection from '../../../../../src/ol/proj/Projection.js';
|
||||
import TileGrid from '../../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import TileRange from '../../../../../src/ol/TileRange.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
import TileGrid from '../../../../src/ol/tilegrid/TileGrid.js';
|
||||
import TileRange from '../../../../src/ol/TileRange.js';
|
||||
import expect from '../../expect.js';
|
||||
import {
|
||||
DEFAULT_MAX_ZOOM,
|
||||
DEFAULT_TILE_SIZE,
|
||||
} from '../../../../../src/ol/tilegrid/common.js';
|
||||
import {HALF_SIZE} from '../../../../../src/ol/proj/epsg3857.js';
|
||||
} from '../../../../src/ol/tilegrid/common.js';
|
||||
import {HALF_SIZE} from '../../../../src/ol/proj/epsg3857.js';
|
||||
import {
|
||||
METERS_PER_UNIT,
|
||||
get as getProjection,
|
||||
} from '../../../../../src/ol/proj.js';
|
||||
} from '../../../../src/ol/proj.js';
|
||||
import {
|
||||
createForExtent,
|
||||
createForProjection,
|
||||
createXYZ,
|
||||
getForProjection as getTileGridForProjection,
|
||||
} from '../../../../../src/ol/tilegrid.js';
|
||||
import {createOrUpdate} from '../../../../../src/ol/extent.js';
|
||||
} from '../../../../src/ol/tilegrid.js';
|
||||
import {createOrUpdate} from '../../../../src/ol/extent.js';
|
||||
|
||||
describe('ol.tilegrid.TileGrid', function () {
|
||||
describe('ol/tilegrid/TileGrid.js', function () {
|
||||
let resolutions;
|
||||
let origin;
|
||||
let tileSize;
|
||||
25
test/node/ol/util.test.js
Normal file
25
test/node/ol/util.test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import expect from '../expect.js';
|
||||
import {getUid} from '../../../src/ol/util.js';
|
||||
|
||||
describe('ol/util.js', () => {
|
||||
describe('getUid()', function () {
|
||||
it('is constant once generated', function () {
|
||||
const a = {};
|
||||
expect(getUid(a)).to.be(getUid(a));
|
||||
});
|
||||
|
||||
it('generates a strictly increasing sequence', function () {
|
||||
const a = {};
|
||||
const b = {};
|
||||
const c = {};
|
||||
getUid(a);
|
||||
getUid(c);
|
||||
getUid(b);
|
||||
|
||||
// uid order should be a < c < b
|
||||
expect(getUid(a)).to.be.lessThan(getUid(c));
|
||||
expect(getUid(c)).to.be.lessThan(getUid(b));
|
||||
expect(getUid(a)).to.be.lessThan(getUid(b));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,14 @@
|
||||
import {create, fromTransform} from '../../../../../src/ol/vec/mat4.js';
|
||||
import expect from '../../expect.js';
|
||||
import {create, fromTransform} from '../../../../src/ol/vec/mat4.js';
|
||||
|
||||
describe('mat4', function () {
|
||||
describe('mat4.create()', function () {
|
||||
describe('ol/vec/mat4.js', function () {
|
||||
describe('create()', function () {
|
||||
it('returns the expected matrix', function () {
|
||||
expect(create()).to.eql([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mat4.fromTransform()', function () {
|
||||
describe('fromTransform()', function () {
|
||||
it('sets the expected transform on the matrix', function () {
|
||||
const transform = [1, 2, 3, 4, 5, 6];
|
||||
const result = create();
|
||||
11
test/node/readme.md
Normal file
11
test/node/readme.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Node.js Based Tests
|
||||
|
||||
The tests in this directory are run in Node.js. To run the tests:
|
||||
|
||||
npm run test-node
|
||||
|
||||
To attach a debugger to the tests, add a `debugger` statement in the module that you want to debug and run the tests with the `--inspect-brk` flag:
|
||||
|
||||
npm run test-node -- --inspect-brk
|
||||
|
||||
Then open chrome://inspect/ and attach to the remote target (or see https://nodejs.org/en/docs/guides/debugging-getting-started/ for other options).
|
||||
Reference in New Issue
Block a user