Merge pull request #2186 from fredj/rbush-tests
Add more tests for ol.structs.RBush#forEach
This commit is contained in:
@@ -395,6 +395,8 @@ ol.structs.RBush.prototype.condense_ = function(path) {
|
|||||||
/**
|
/**
|
||||||
* Calls a callback function with each node in the tree. Inside the callback,
|
* Calls a callback function with each node in the tree. Inside the callback,
|
||||||
* no tree modifications (insert, update, remove) can be made.
|
* no tree modifications (insert, update, remove) can be made.
|
||||||
|
* If the callback returns a truthy value, this value is returned without
|
||||||
|
* checking the rest of the tree.
|
||||||
* @param {function(this: S, T): *} callback Callback.
|
* @param {function(this: S, T): *} callback Callback.
|
||||||
* @param {S=} opt_this The object to use as `this` in `callback`.
|
* @param {S=} opt_this The object to use as `this` in `callback`.
|
||||||
* @return {*} Callback return value.
|
* @return {*} Callback return value.
|
||||||
|
|||||||
@@ -64,6 +64,27 @@ describe('ol.structs.RBush', function() {
|
|||||||
rBush.insert([-3, -3, -2, -2], objs[10]);
|
rBush.insert([-3, -3, -2, -2], objs[10]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#forEach', function() {
|
||||||
|
|
||||||
|
it('called for all the objects', function() {
|
||||||
|
var i = 0;
|
||||||
|
rBush.forEach(function() {
|
||||||
|
++i;
|
||||||
|
});
|
||||||
|
expect(i).to.be(objs.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stops when the function returns true', function() {
|
||||||
|
var i = 0;
|
||||||
|
var result = rBush.forEach(function() {
|
||||||
|
return ++i >= 4;
|
||||||
|
});
|
||||||
|
expect(i).to.be(4);
|
||||||
|
expect(result).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getInExtent', function() {
|
describe('#getInExtent', function() {
|
||||||
|
|
||||||
it('returns the expected objects', function() {
|
it('returns the expected objects', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user