Comparing version 1.0.3 to 1.1.0
@@ -158,3 +158,5 @@ /*! | ||
Insection.prototype.getEntries = function () { | ||
var interval = Insection.interval.apply(null, arguments); | ||
var interval = arguments.length === 0 ? | ||
{ intersect: function () { return true; } } : | ||
Insection.interval.apply(null, arguments); | ||
@@ -161,0 +163,0 @@ var root = this.data.root; |
@@ -137,3 +137,5 @@ var InvalidIntervalError = require('./InvalidIntervalError'); | ||
Insection.prototype.getEntries = function () { | ||
var interval = Insection.interval.apply(null, arguments); | ||
var interval = arguments.length === 0 ? | ||
{ intersect: function () { return true; } } : | ||
Insection.interval.apply(null, arguments); | ||
@@ -140,0 +142,0 @@ var root = this.data.root; |
{ | ||
"name": "insection", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A data structure for storing number intervals", | ||
@@ -35,4 +35,4 @@ "main": "lib/insection.js", | ||
"mocha": "2.0.1", | ||
"unexpected": "5.0.0-beta24" | ||
"unexpected": "5.1.4" | ||
} | ||
} |
@@ -142,2 +142,3 @@ # Insection | ||
```js | ||
insection.get() => insection.get('(', min, max, ')'); | ||
insection.get(p) => insection.get('[', p, p, ']'); | ||
@@ -166,2 +167,3 @@ insection.get(start, end) => insection.get('[', start, end, ']'); | ||
expect(insection.get(2).sort(), 'to equal', ['foo', 'baz', 'qux']); | ||
expect(insection.get().sort(), 'to equal', ['foo', 'bar', 'baz', 'qux']); | ||
``` | ||
@@ -176,2 +178,3 @@ | ||
```js | ||
insection.getIntervals() => insection.getIntervals('(', min, max, ')'); | ||
insection.getIntervals(p) => insection.getIntervals('[', p, p, ']'); | ||
@@ -200,3 +203,3 @@ insection.getIntervals(start, end) => insection.getIntervals('[', start, end, ']'); | ||
insection.add('[', 2, Infinity, ')', 'qux'); | ||
expect(insection.getIntervals(1, 5).map(String).sort(), 'to equal', ['[0;4]', '(2;6]']); | ||
expect(insection.getIntervals(1, 5).map(String).sort(), 'to equal', ['(2;6]', '[0;4]']); | ||
expect(insection.getIntervals(0, 2).map(String).sort(), 'to equal', ['[0;4]']); | ||
@@ -209,2 +212,8 @@ expect(insection.getIntervals('(', -Infinity, 2, ')').map(String).sort(), 'to equal', ['[0;4]']); | ||
]); | ||
expect(insection.getIntervals().map(String).sort(), 'to equal', [ | ||
'(2;6]', | ||
'[0;4]', | ||
'[2;Infinity)', | ||
'[2;Infinity)' | ||
]); | ||
``` | ||
@@ -218,2 +227,3 @@ ### getEntries | ||
```js | ||
insection.getEntries() => insection.getEntries('(', min, max, ')'); | ||
insection.getEntries(p) => insection.getEntries('[', p, p, ']'); | ||
@@ -242,3 +252,6 @@ insection.getEntries(start, end) => insection.getEntries('[', start, end, ']'); | ||
return entry.interval + ' => ' + entry.value; | ||
}).sort(), 'to equal', ['[0;4] => foo', '(2;6] => bar']); | ||
}).sort(), 'to equal', ['(2;6] => bar', '[0;4] => foo']); | ||
expect(insection.getIntervals().map(function (entry) { | ||
return entry.interval + ' => ' + entry.value; | ||
}).sort(), 'to equal', ['(2;6] => bar', '[0;4] => foo']); | ||
``` | ||
@@ -245,0 +258,0 @@ |
@@ -260,2 +260,6 @@ var Insection = require('../lib/Insection.js'); | ||
it("get() returns all values in the data structure", function () { | ||
expect(insection.get(), 'to equal', insection.get(Insection.interval('(', -Infinity, Infinity, ')'))); | ||
}); | ||
it("get(3) is an alias for get(Insection.interval('[',3,3,']'))", function () { | ||
@@ -319,3 +323,7 @@ expect(insection.get(3), 'to equal', insection.get(Insection.interval('[', 3, 3, ']'))); | ||
it("getInterval(3) is an alias for getIntervals(Insection.interval('[',3,3,']'))", function () { | ||
it("getIntervals() returns all values in the data structure", function () { | ||
expect(insection.getIntervals(), 'to equal', insection.getIntervals(Insection.interval('(', -Infinity, Infinity, ')'))); | ||
}); | ||
it("getIntervals(3) is an alias for getIntervals(Insection.interval('[',3,3,']'))", function () { | ||
expect(insection.getIntervals(3), 'to equal', insection.getIntervals(Insection.interval('[', 3, 3, ']'))); | ||
@@ -376,2 +384,6 @@ }); | ||
it("getEntries() returns all values in the data structure", function () { | ||
expect(insection.getEntries(), 'to equal', insection.getEntries(Insection.interval('(', -Infinity, Infinity, ')'))); | ||
}); | ||
it("getEntries(3) is an alias for getEntries(Insection.interval('[',3,3,']'))", function () { | ||
@@ -378,0 +390,0 @@ expect(insection.getEntries(3), 'to equal', insection.getEntries(Insection.interval('[', 3, 3, ']'))); |
@@ -10,4 +10,46 @@ var Insection = require('../lib/Insection.js'); | ||
}, | ||
inspect: function (insection, depth, output) { | ||
return output.text('Insection'); | ||
inspect: function (insection, depth, output, inspect) { | ||
var entries = insection.getEntries(); | ||
var large = entries.length > 4; | ||
output.text('insection('); | ||
if (large) { | ||
output.nl(); | ||
output.indentLines(); | ||
} else { | ||
output.sp(); | ||
} | ||
entries.sort(function (x, y) { | ||
var xInterval = x.interval; | ||
var yInterval = y.interval; | ||
if (xInterval.start < yInterval.start) { return -1; } | ||
if (xInterval.start > yInterval.start) { return 1; } | ||
if (xInterval.end < yInterval.end) { return -1; } | ||
if (xInterval.end > yInterval.end) { return 1; } | ||
if (!xInterval.isStartOpen() && yInterval.isStartOpen()) { return -1; } | ||
if (xInterval.isStartOpen() && !yInterval.isStartOpen()) { return 1; } | ||
if (!xInterval.isEndOpen() && yInterval.isEndOpen()) { return -1; } | ||
if (xInterval.isEndOpen() && !yInterval.isEndOpen()) { return 1; } | ||
return 0; | ||
}).forEach(function (entry, index) { | ||
if (index > 0) { | ||
output.text(', '); | ||
if (large) { | ||
output.nl(); | ||
} else { | ||
output.sp(); | ||
} | ||
} | ||
output.i().append(inspect(entry.interval)) | ||
.text(' => ') | ||
.append(inspect(entry.value)); | ||
}); | ||
if (large) { | ||
output.nl(); | ||
output.outdentLines(); | ||
} else { | ||
output.sp(); | ||
} | ||
output.text(')'); | ||
} | ||
@@ -25,5 +67,5 @@ }) | ||
output.text(interval.startString || '[') | ||
.text(interval.start) | ||
.number(interval.start) | ||
.text(';') | ||
.text(interval.end) | ||
.number(interval.end) | ||
.text(interval.endString || ']'); | ||
@@ -30,0 +72,0 @@ return output; |
90056
1757
380