Add ol.structs.IntegerSet.toString
This commit is contained in:
@@ -293,3 +293,23 @@ ol.structs.IntegerSet.prototype.removeRange =
|
||||
}
|
||||
this.compactRanges_();
|
||||
};
|
||||
|
||||
|
||||
if (goog.DEBUG) {
|
||||
|
||||
/**
|
||||
* @return {string} String.
|
||||
*/
|
||||
ol.structs.IntegerSet.prototype.toString = function() {
|
||||
var arr = this.arr_;
|
||||
var n = arr.length;
|
||||
var result = new Array(n / 2);
|
||||
var resultIndex = 0;
|
||||
var i;
|
||||
for (i = 0; i < n; i += 2) {
|
||||
result[resultIndex++] = arr[i] + '-' + arr[i + 1];
|
||||
}
|
||||
return result.join(', ');
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +116,14 @@ describe('ol.structs.IntegerSet', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns an empty string', function() {
|
||||
expect(is.toString()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a populated instance', function() {
|
||||
@@ -342,6 +350,13 @@ describe('ol.structs.IntegerSet', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.toString()).to.be('4-6, 8-10, 12-14');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with fragmentation', function() {
|
||||
@@ -427,6 +442,14 @@ describe('ol.structs.IntegerSet', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('toString', function() {
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(is.toString()).to.be('0-1, 2-4, 5-8, 9-12, 13-15, 16-17');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('compared to a slow reference implementation', function() {
|
||||
|
||||
Reference in New Issue
Block a user