Add ol.structs.IntegerSet.toString

This commit is contained in:
Tom Payne
2013-03-19 07:30:51 +01:00
parent 9047e98889
commit 6ab5cfae8c
2 changed files with 43 additions and 0 deletions

View File

@@ -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(', ');
};
}

View File

@@ -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() {