Named exports from ol/array module

This commit is contained in:
Marc Jansen
2017-12-19 12:22:46 +01:00
committed by Frederic Junod
parent 767f61ba78
commit 02002082bf
47 changed files with 296 additions and 298 deletions

View File

@@ -1,4 +1,16 @@
import _ol_array_ from '../../../src/ol/array.js';
import {
binarySearch,
equals,
extend,
find,
findIndex,
isSorted,
linearFindNearest,
numberSafeCompareFunction,
remove,
reverseSubArray,
stableSort
} from '../../../src/ol/array.js';
describe('ol.array', function() {
@@ -20,43 +32,43 @@ describe('ol.array', function() {
];
it('should find \'1000\' at index 0', function() {
expect(_ol_array_.binarySearch(a, '1000')).to.be(0);
expect(binarySearch(a, '1000')).to.be(0);
});
it('should find \'zzz\' at index ' + (a.length - 1), function() {
expect(_ol_array_.binarySearch(a, 'zzz')).to.be(a.length - 1);
expect(binarySearch(a, 'zzz')).to.be(a.length - 1);
});
it('should find \'C\' at index 10', function() {
expect(_ol_array_.binarySearch(a, 'C')).to.be(10);
expect(binarySearch(a, 'C')).to.be(10);
});
it('should find \'B\' at index 7 || 8 || 9', function() {
var pos = _ol_array_.binarySearch(a, 'B');
var pos = binarySearch(a, 'B');
expect(pos == 7 || pos == 8 || pos == 9).to.be.ok();
});
it('should not find \'100\'', function() {
var pos = _ol_array_.binarySearch(a, '100');
var pos = binarySearch(a, '100');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'100\'', function() {
var pos = _ol_array_.binarySearch(a, '100');
var pos = binarySearch(a, '100');
expect(insertionPoint(pos)).to.be(0);
});
it('should not find \'zzz0\'', function() {
var pos = _ol_array_.binarySearch(a, 'zzz0');
var pos = binarySearch(a, 'zzz0');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of ' + (a.length) + ' for \'zzz0\'',
function() {
var pos = _ol_array_.binarySearch(a, 'zzz0');
var pos = binarySearch(a, 'zzz0');
expect(insertionPoint(pos)).to.be(a.length);
}
);
it('should not find \'BA\'', function() {
var pos = _ol_array_.binarySearch(a, 'zzz0');
var pos = binarySearch(a, 'zzz0');
expect(pos < 0).to.be.ok();
});
it('should have an insertion point of 10 for \'BA\'',
function() {
var pos = _ol_array_.binarySearch(a, 'BA');
var pos = binarySearch(a, 'BA');
expect(insertionPoint(pos)).to.be(10);
}
);
@@ -65,11 +77,11 @@ describe('ol.array', function() {
describe('0 length array with default comparison', function() {
var b = [];
it('should not find \'a\'', function() {
expect(_ol_array_.binarySearch(b, 'a') < 0).to.be.ok();
expect(binarySearch(b, 'a') < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'a\'',
function() {
var pos = _ol_array_.binarySearch(b, 'a');
var pos = binarySearch(b, 'a');
expect(insertionPoint(pos)).to.be(0);
}
);
@@ -79,23 +91,23 @@ describe('ol.array', function() {
function() {
var c = ['only item'];
it('should find \'only item\' at index 0', function() {
expect(_ol_array_.binarySearch(c, 'only item')).to.be(0);
expect(binarySearch(c, 'only item')).to.be(0);
});
it('should not find \'a\'', function() {
expect(_ol_array_.binarySearch(c, 'a') < 0).to.be.ok();
expect(binarySearch(c, 'a') < 0).to.be.ok();
});
it('should have an insertion point of 0 for \'a\'',
function() {
var pos = _ol_array_.binarySearch(c, 'a');
var pos = binarySearch(c, 'a');
expect(insertionPoint(pos)).to.be(0);
}
);
it('should not find \'z\'', function() {
expect(_ol_array_.binarySearch(c, 'z') < 0).to.be.ok();
expect(binarySearch(c, 'z') < 0).to.be.ok();
});
it('should have an insertion point of 1 for \'z\'',
function() {
var pos = _ol_array_.binarySearch(c, 'z');
var pos = binarySearch(c, 'z');
expect(insertionPoint(pos)).to.be(1);
}
);
@@ -108,42 +120,42 @@ describe('ol.array', function() {
0.31255, 5, 142.88888708, 334, 342, 453, 54254
];
it('should find -897123.9 at index 0', function() {
expect(_ol_array_.binarySearch(d, -897123.9)).to.be(0);
expect(binarySearch(d, -897123.9)).to.be(0);
});
it('should find 54254 at index ' + (d.length - 1), function() {
expect(_ol_array_.binarySearch(d, 54254)).to.be(d.length - 1);
expect(binarySearch(d, 54254)).to.be(d.length - 1);
});
it('should find -3 at index 5', function() {
expect(_ol_array_.binarySearch(d, -3)).to.be(5);
expect(binarySearch(d, -3)).to.be(5);
});
it('should find 0 at index 6 || 7 || 8', function() {
var pos = _ol_array_.binarySearch(d, 0);
var pos = binarySearch(d, 0);
expect(pos == 6 || pos == 7 || pos == 8).to.be(true);
});
it('should not find -900000', function() {
var pos = _ol_array_.binarySearch(d, -900000);
var pos = binarySearch(d, -900000);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for -900000', function() {
var pos = _ol_array_.binarySearch(d, -900000);
var pos = binarySearch(d, -900000);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find 54255', function() {
var pos = _ol_array_.binarySearch(d, 54255);
var pos = binarySearch(d, 54255);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of ' + (d.length) + ' for 54255',
function() {
var pos = _ol_array_.binarySearch(d, 54255);
var pos = binarySearch(d, 54255);
expect(insertionPoint(pos)).to.be(d.length);
}
);
it('should not find 1.1', function() {
var pos = _ol_array_.binarySearch(d, 1.1);
var pos = binarySearch(d, 1.1);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 10 for 1.1', function() {
var pos = _ol_array_.binarySearch(d, 1.1);
var pos = binarySearch(d, 1.1);
expect(insertionPoint(pos)).to.be(10);
});
});
@@ -155,45 +167,45 @@ describe('ol.array', function() {
-9, -324, -1321.3124, -321434.58758, -897123.9
];
it('should find 54254 at index 0', function() {
var pos = _ol_array_.binarySearch(e, 54254, revNumCompare);
var pos = binarySearch(e, 54254, revNumCompare);
expect(pos).to.be(0);
});
it('should find -897123.9 at index ' + (e.length - 1), function() {
var pos = _ol_array_.binarySearch(e, -897123.9, revNumCompare);
var pos = binarySearch(e, -897123.9, revNumCompare);
expect(pos).to.be(e.length - 1);
});
it('should find -3 at index 10', function() {
var pos = _ol_array_.binarySearch(e, -3, revNumCompare);
var pos = binarySearch(e, -3, revNumCompare);
expect(pos).to.be(10);
});
it('should find 0 at index 7 || 8 || 9', function() {
var pos = _ol_array_.binarySearch(e, 0, revNumCompare);
var pos = binarySearch(e, 0, revNumCompare);
expect(pos == 7 || pos == 8 || pos == 9).to.be(true);
});
it('should not find 54254.1', function() {
var pos = _ol_array_.binarySearch(e, 54254.1, revNumCompare);
var pos = binarySearch(e, 54254.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 54254.1', function() {
var pos = _ol_array_.binarySearch(e, 54254.1, revNumCompare);
var pos = binarySearch(e, 54254.1, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find -897124', function() {
var pos = _ol_array_.binarySearch(e, -897124, revNumCompare);
var pos = binarySearch(e, -897124, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of ' + e.length + ' for -897124',
function() {
var pos = _ol_array_.binarySearch(e, -897124, revNumCompare);
var pos = binarySearch(e, -897124, revNumCompare);
expect(insertionPoint(pos)).to.be(e.length);
}
);
it('should not find 1.1', function() {
var pos = _ol_array_.binarySearch(e, 1.1, revNumCompare);
var pos = binarySearch(e, 1.1, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 1.1', function() {
var pos = _ol_array_.binarySearch(e, 1.1, revNumCompare);
var pos = binarySearch(e, 1.1, revNumCompare);
expect(insertionPoint(pos)).to.be(6);
});
}
@@ -202,11 +214,11 @@ describe('ol.array', function() {
describe('0 length array with custom comparison function', function() {
var f = [];
it('should not find 0', function() {
var pos = _ol_array_.binarySearch(f, 0, revNumCompare);
var pos = binarySearch(f, 0, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 0', function() {
var pos = _ol_array_.binarySearch(f, 0, revNumCompare);
var pos = binarySearch(f, 0, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
});
@@ -215,23 +227,23 @@ describe('ol.array', function() {
function() {
var g = [1];
it('should find 1 at index 0', function() {
var pos = _ol_array_.binarySearch(g, 1, revNumCompare);
var pos = binarySearch(g, 1, revNumCompare);
expect(pos).to.be(0);
});
it('should not find 2', function() {
var pos = _ol_array_.binarySearch(g, 2, revNumCompare);
var pos = binarySearch(g, 2, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 0 for 2', function() {
var pos = _ol_array_.binarySearch(g, 2, revNumCompare);
var pos = binarySearch(g, 2, revNumCompare);
expect(insertionPoint(pos)).to.be(0);
});
it('should not find 0', function() {
var pos = _ol_array_.binarySearch(g, 0, revNumCompare);
var pos = binarySearch(g, 0, revNumCompare);
expect(pos < 0).to.be(true);
});
it('should have an insertion point of 1 for 0', function() {
var pos = _ol_array_.binarySearch(g, 0, revNumCompare);
var pos = binarySearch(g, 0, revNumCompare);
expect(insertionPoint(pos)).to.be(1);
});
}
@@ -239,10 +251,10 @@ describe('ol.array', function() {
describe('finding first index when multiple candidates', function() {
it('should find the index of the first 0', function() {
expect(_ol_array_.binarySearch([0, 0, 1], 0)).to.be(0);
expect(binarySearch([0, 0, 1], 0)).to.be(0);
});
it('should find the index of the first 1', function() {
expect(_ol_array_.binarySearch([0, 1, 1], 1)).to.be(1);
expect(binarySearch([0, 1, 1], 1)).to.be(1);
});
});
@@ -275,8 +287,8 @@ describe('ol.array', function() {
};
// Now actually call and test the method twice
_ol_array_.binarySearch(a, 48);
_ol_array_.binarySearch(a, 13, function(a, b) {
binarySearch(a, 48);
binarySearch(a, 13, function(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
});
@@ -298,61 +310,61 @@ describe('ol.array', function() {
var 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(_ol_array_.binarySearch(arr, 4)).to.equal(-6);
expect(binarySearch(arr, 4)).to.equal(-6);
});
it('should work even on empty arrays', function() {
expect(_ol_array_.binarySearch([], 42)).to.equal(-1);
expect(binarySearch([], 42)).to.equal(-1);
});
it('should work even on arrays of doubles', function() {
expect(_ol_array_.binarySearch([0.0, 0.1, 0.2, 0.3, 0.4], 0.25)).to.equal(-4);
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(_ol_array_.equals([], [])).to.be(true);
expect(equals([], [])).to.be(true);
});
it('returns true for [1] == [1]', function() {
expect(_ol_array_.equals([1], [1])).to.be(true);
expect(equals([1], [1])).to.be(true);
});
it('returns true for [\'1\'] == [\'1\']', function() {
expect(_ol_array_.equals(['1'], ['1'])).to.be(true);
expect(equals(['1'], ['1'])).to.be(true);
});
it('returns false for [1] == [\'1\']', function() {
expect(_ol_array_.equals([1], ['1'])).to.be(false);
expect(equals([1], ['1'])).to.be(false);
});
it('returns true for [null] == [null]', function() {
expect(_ol_array_.equals([null], [null])).to.be(true);
expect(equals([null], [null])).to.be(true);
});
it('returns false for [null] == [undefined]', function() {
expect(_ol_array_.equals([null], [undefined])).to.be(false);
expect(equals([null], [undefined])).to.be(false);
});
it('returns true for [1, 2] == [1, 2]', function() {
expect(_ol_array_.equals([1, 2], [1, 2])).to.be(true);
expect(equals([1, 2], [1, 2])).to.be(true);
});
it('returns false for [1, 2] == [2, 1]', function() {
expect(_ol_array_.equals([1, 2], [2, 1])).to.be(false);
expect(equals([1, 2], [2, 1])).to.be(false);
});
it('returns false for [1, 2] == [1]', function() {
expect(_ol_array_.equals([1, 2], [1])).to.be(false);
expect(equals([1, 2], [1])).to.be(false);
});
it('returns false for [1] == [1, 2]', function() {
expect(_ol_array_.equals([1], [1, 2])).to.be(false);
expect(equals([1], [1, 2])).to.be(false);
});
it('returns false for [{}] == [{}]', function() {
expect(_ol_array_.equals([{}], [{}])).to.be(false);
expect(equals([{}], [{}])).to.be(false);
});
});
describe('extend', function() {
it('extends an array in place with an array', function() {
var a = [0, 1];
_ol_array_.extend(a, [2, 3]);
extend(a, [2, 3]);
expect(a).to.eql([0, 1, 2, 3]);
});
it('extends an array in place with a number', function() {
var a = [0, 1];
_ol_array_.extend(a, 2);
extend(a, 2);
expect(a).to.eql([0, 1, 2]);
});
it('extends an array in place with a big array', function() {
@@ -362,7 +374,7 @@ describe('ol.array', function() {
while (i--) {
bigArray[i] = i;
}
_ol_array_.extend(a, bigArray);
extend(a, bigArray);
expect(a).to.eql(bigArray);
});
});
@@ -370,7 +382,7 @@ describe('ol.array', function() {
describe('find', function() {
it('finds numbers in an array', function() {
var a = [0, 1, 2, 3];
var b = _ol_array_.find(a, function(val, index, a2) {
var b = find(a, function(val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
@@ -380,7 +392,7 @@ describe('ol.array', function() {
it('returns null when an item in an array is not found', function() {
var a = [0, 1, 2, 3];
var b = _ol_array_.find(a, function(val, index, a2) {
var b = find(a, function(val, index, a2) {
return val > 100;
});
expect(b).to.be(null);
@@ -388,7 +400,7 @@ describe('ol.array', function() {
it('finds items in an array-like', function() {
var a = 'abCD';
var b = _ol_array_.find(a, function(val, index, a2) {
var b = find(a, function(val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val >= 'A' && val <= 'Z';
@@ -398,7 +410,7 @@ describe('ol.array', function() {
it('returns null when nothing in an array-like is found', function() {
var a = 'abcd';
var b = _ol_array_.find(a, function(val, index, a2) {
var b = find(a, function(val, index, a2) {
return val >= 'A' && val <= 'Z';
});
expect(b).to.be(null);
@@ -408,7 +420,7 @@ describe('ol.array', function() {
describe('findIndex', function() {
it('finds index of numbers in an array', function() {
var a = [0, 1, 2, 3];
var b = _ol_array_.findIndex(a, function(val, index, a2) {
var b = findIndex(a, function(val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
@@ -418,7 +430,7 @@ describe('ol.array', function() {
it('returns -1 when an item in an array is not found', function() {
var a = [0, 1, 2, 3];
var b = _ol_array_.findIndex(a, function(val, index, a2) {
var b = findIndex(a, function(val, index, a2) {
return val > 100;
});
expect(b).to.be(-1);
@@ -427,23 +439,23 @@ describe('ol.array', function() {
describe('isSorted', function() {
it('works with just an array as argument', function() {
expect(_ol_array_.isSorted([1, 2, 3])).to.be(true);
expect(_ol_array_.isSorted([1, 2, 2])).to.be(true);
expect(_ol_array_.isSorted([1, 2, 1])).to.be(false);
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(_ol_array_.isSorted([1, 2, 3], null, true)).to.be(true);
expect(_ol_array_.isSorted([1, 2, 2], null, true)).to.be(false);
expect(_ol_array_.isSorted([1, 2, 1], null, true)).to.be(false);
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(_ol_array_.isSorted([1, 2, 3], compare)).to.be(false);
expect(_ol_array_.isSorted([3, 2, 2], compare)).to.be(true);
expect(isSorted([1, 2, 3], compare)).to.be(false);
expect(isSorted([3, 2, 2], compare)).to.be(true);
});
});
@@ -451,49 +463,49 @@ describe('ol.array', function() {
it('returns expected value', function() {
var arr = [1000, 500, 100];
expect(_ol_array_.linearFindNearest(arr, 10000, 0)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 10000, 1)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 10000, -1)).to.eql(0);
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(_ol_array_.linearFindNearest(arr, 1000, 0)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 1000, 1)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 1000, -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(_ol_array_.linearFindNearest(arr, 900, 0)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 900, 1)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 900, -1)).to.eql(1);
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(_ol_array_.linearFindNearest(arr, 750, 0)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 750, 1)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 750, -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(_ol_array_.linearFindNearest(arr, 550, 0)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 550, 1)).to.eql(0);
expect(_ol_array_.linearFindNearest(arr, 550, -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(_ol_array_.linearFindNearest(arr, 500, 0)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 500, 1)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 500, -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(_ol_array_.linearFindNearest(arr, 450, 0)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 450, 1)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 450, -1)).to.eql(2);
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(_ol_array_.linearFindNearest(arr, 300, 0)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 300, 1)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 300, -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(_ol_array_.linearFindNearest(arr, 200, 0)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 200, 1)).to.eql(1);
expect(_ol_array_.linearFindNearest(arr, 200, -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(_ol_array_.linearFindNearest(arr, 100, 0)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 100, 1)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 100, -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(_ol_array_.linearFindNearest(arr, 50, 0)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 50, 1)).to.eql(2);
expect(_ol_array_.linearFindNearest(arr, 50, -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);
});
});
@@ -501,7 +513,7 @@ describe('ol.array', function() {
it('sorts as expected', function() {
var arr = [40, 200, 3000];
// default sort would yield [200, 3000, 40]
arr.sort(_ol_array_.numberSafeCompareFunction);
arr.sort(numberSafeCompareFunction);
expect(arr).to.eql(arr);
});
});
@@ -509,9 +521,9 @@ describe('ol.array', function() {
describe('remove', function() {
it('removes elements from an array', function() {
var a = ['a', 'b', 'c', 'd'];
_ol_array_.remove(a, 'c');
remove(a, 'c');
expect(a).to.eql(['a', 'b', 'd']);
_ol_array_.remove(a, 'x');
remove(a, 'x');
expect(a).to.eql(['a', 'b', 'd']);
});
});
@@ -522,19 +534,19 @@ describe('ol.array', function() {
var expected = [1, 2, 3, 4, 5, 6];
arr = [1, 5, 4, 3, 2, 6];
_ol_array_.reverseSubArray(arr, 1, 4);
reverseSubArray(arr, 1, 4);
expect(arr).to.eql(expected);
arr = [3, 2, 1, 4, 5, 6];
_ol_array_.reverseSubArray(arr, 0, 2);
reverseSubArray(arr, 0, 2);
expect(arr).to.eql(expected);
arr = [1, 2, 3, 6, 5, 4];
_ol_array_.reverseSubArray(arr, 3, 5);
reverseSubArray(arr, 3, 5);
expect(arr).to.eql(expected);
arr = [6, 5, 4, 3, 2, 1];
_ol_array_.reverseSubArray(arr, 0, 5);
reverseSubArray(arr, 0, 5);
expect(arr).to.eql(expected);
});
});
@@ -552,7 +564,7 @@ describe('ol.array', function() {
function comparisonFn(obj1, obj2) {
return obj1.key - obj2.key;
}
_ol_array_.stableSort(arr, comparisonFn);
stableSort(arr, comparisonFn);
var sortedValues = [];
for (var i = 0; i < arr.length; i++) {
sortedValues.push(arr[i].val);