Skip to content

Commit 7466cea

Browse files
committed
Add more boundless/unknown interval tests for Long intervals
1 parent a97cdac commit 7466cea

1 file changed

Lines changed: 216 additions & 0 deletions

File tree

test/datatypes/interval-test.ts

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3968,6 +3968,8 @@ describe('LongInterval', () => {
39683968
new Interval(0n, null, true, false).contains(0n).should.be.true();
39693969
should(new Interval(0n, null, true, false).contains(123456789n)).be.null();
39703970
new Interval(0n, null, true, false).contains(-1n).should.be.false();
3971+
new Interval(null, null).contains(5n).should.be.true();
3972+
should(new Interval(null, null, false, false).contains(5n)).be.null();
39713973
});
39723974

39733975
it('should properly handle imprecision', () => {
@@ -4119,6 +4121,15 @@ describe('LongInterval', () => {
41194121
it('should include a point Long', () => {
41204122
d.zeroToHundredLong.closed.includes(50n).should.be.true();
41214123
});
4124+
4125+
it('should properly handle boundless and unknown intervals', () => {
4126+
boundlessInterval().includes(50n).should.be.true();
4127+
boundlessInterval().includes(d.zeroToHundredLong.closed).should.be.true();
4128+
boundlessInterval().includes(unknownInterval()).should.be.true();
4129+
d.zeroToHundredLong.closed.includes(boundlessInterval()).should.be.false();
4130+
should(unknownInterval().includes(d.zeroToHundredLong.closed)).be.null();
4131+
should(unknownInterval().includes(boundlessInterval())).be.null();
4132+
});
41224133
});
41234134

41244135
describe('includedIn', () => {
@@ -4238,6 +4249,57 @@ describe('LongInterval', () => {
42384249
d.zeroToHundredLong.closed.includedIn(50n).should.be.true();
42394250
d.zeroToHundredLong.closed.includedIn(500n).should.be.false();
42404251
});
4252+
4253+
it('should properly handle boundless and unknown intervals', () => {
4254+
d.zeroToHundredLong.closed.includedIn(boundlessInterval()).should.be.true();
4255+
boundlessInterval().includedIn(d.zeroToHundredLong.closed).should.be.false();
4256+
boundlessInterval().includedIn(boundlessInterval()).should.be.true();
4257+
unknownInterval().includedIn(boundlessInterval()).should.be.true();
4258+
});
4259+
});
4260+
4261+
describe('properlyIncludes', () => {
4262+
let d: any;
4263+
beforeEach(() => {
4264+
d = data();
4265+
});
4266+
4267+
it('should properly handle boundless and unknown intervals', () => {
4268+
boundlessInterval().properlyIncludes(d.zeroToHundredLong.closed).should.be.true();
4269+
boundlessInterval().properlyIncludes(boundlessInterval()).should.be.false();
4270+
should(boundlessInterval().properlyIncludes(unknownInterval())).be.null();
4271+
should(unknownInterval().properlyIncludes(d.zeroToHundredLong.closed)).be.null();
4272+
});
4273+
});
4274+
4275+
describe('starts', () => {
4276+
let d: any;
4277+
beforeEach(() => {
4278+
d = data();
4279+
});
4280+
4281+
it('should properly handle boundless and unknown intervals', () => {
4282+
boundlessInterval().starts(boundlessInterval()).should.be.true();
4283+
boundlessInterval().starts(d.zeroToHundredLong.closed).should.be.false();
4284+
d.zeroToHundredLong.closed.starts(boundlessInterval()).should.be.false();
4285+
should(boundlessInterval().starts(unknownInterval())).be.null();
4286+
should(unknownInterval().starts(boundlessInterval())).be.null();
4287+
});
4288+
});
4289+
4290+
describe('ends', () => {
4291+
let d: any;
4292+
beforeEach(() => {
4293+
d = data();
4294+
});
4295+
4296+
it('should properly handle boundless and unknown intervals', () => {
4297+
boundlessInterval().ends(boundlessInterval()).should.be.true();
4298+
boundlessInterval().ends(d.zeroToHundredLong.closed).should.be.false();
4299+
d.zeroToHundredLong.closed.ends(boundlessInterval()).should.be.false();
4300+
should(boundlessInterval().ends(unknownInterval())).be.null();
4301+
should(unknownInterval().ends(boundlessInterval())).be.null();
4302+
});
42414303
});
42424304

42434305
describe('overlaps(LongInterval)', () => {
@@ -4330,6 +4392,30 @@ describe('LongInterval', () => {
43304392
y.open.overlaps(x.open).should.be.true();
43314393
});
43324394

4395+
it('should properly handle null endpoints', () => {
4396+
const negativeInterval = new Interval(-123456789n, -1n);
4397+
const positiveInterval = new Interval(1n, 123456789n);
4398+
const startsAtZero = new Interval(0n, 123456789n);
4399+
const endsAtZero = new Interval(-123456789n, 0n);
4400+
4401+
should(new Interval(null, 0n).overlaps(negativeInterval)).be.true();
4402+
should(new Interval(null, 0n).overlaps(positiveInterval)).be.false();
4403+
should(new Interval(null, 0n, false, true).overlaps(startsAtZero)).be.true();
4404+
should(new Interval(null, 0n, false, true).overlaps(negativeInterval)).be.null();
4405+
should(new Interval(null, 0n, false, true).overlaps(positiveInterval)).be.false();
4406+
4407+
should(new Interval(0n, null).overlaps(positiveInterval)).be.true();
4408+
should(new Interval(0n, null).overlaps(negativeInterval)).be.false();
4409+
should(new Interval(0n, null, true, false).overlaps(endsAtZero)).be.true();
4410+
should(new Interval(0n, null, true, false).overlaps(positiveInterval)).be.null();
4411+
should(new Interval(0n, null, true, false).overlaps(negativeInterval)).be.false();
4412+
4413+
should(new Interval(null, null).overlaps(d.zeroToHundredLong.closed)).be.true();
4414+
should(new Interval(null, null, false, false).overlaps(d.zeroToHundredLong.closed)).be.null();
4415+
should(d.zeroToHundredLong.closed.overlaps(new Interval(null, null))).be.true();
4416+
should(d.zeroToHundredLong.closed.overlaps(new Interval(null, null, false, false))).be.null();
4417+
});
4418+
43334419
it('should properly handle boundless and unknown intervals', () => {
43344420
boundlessInterval().overlaps(boundlessInterval()).should.be.true();
43354421
boundlessInterval().overlaps(d.zeroToHundredLong.closed).should.be.true();
@@ -4390,6 +4476,21 @@ describe('LongInterval', () => {
43904476
d.zeroToHundredLong.closed.overlaps(105n).should.be.false();
43914477
});
43924478

4479+
it('should properly handle null endpoints', () => {
4480+
should(new Interval(null, 0n).overlaps(-123456789n)).be.true();
4481+
should(new Interval(null, 0n).overlaps(1n)).be.false();
4482+
should(new Interval(null, 0n, false, true).overlaps(0n)).be.true();
4483+
should(new Interval(null, 0n, false, true).overlaps(-123456789n)).be.null();
4484+
should(new Interval(null, 0n, false, true).overlaps(1n)).be.false();
4485+
should(new Interval(0n, null).overlaps(123456789n)).be.true();
4486+
should(new Interval(0n, null).overlaps(-1n)).be.false();
4487+
should(new Interval(0n, null, true, false).overlaps(0n)).be.true();
4488+
should(new Interval(0n, null, true, false).overlaps(123456789n)).be.null();
4489+
should(new Interval(0n, null, true, false).overlaps(-1n)).be.false();
4490+
should(new Interval(null, null).overlaps(5n)).be.true();
4491+
should(new Interval(null, null, false, false).overlaps(5n)).be.null();
4492+
});
4493+
43934494
it('should properly handle boundless and unknown intervals', () => {
43944495
boundlessInterval().overlaps(5n).should.be.true();
43954496
should(boundlessInterval().overlaps(null)).be.null();
@@ -4596,6 +4697,31 @@ describe('LongInterval', () => {
45964697

45974698
ivl.equals(point).should.be.false();
45984699
});
4700+
4701+
it('should properly handle boundless and unknown intervals', () => {
4702+
boundlessInterval().equals(boundlessInterval()).should.be.true();
4703+
boundlessInterval().equals(d.zeroToHundredLong.closed).should.be.false();
4704+
d.zeroToHundredLong.closed.equals(boundlessInterval()).should.be.false();
4705+
should(boundlessInterval().equals(unknownInterval())).be.null();
4706+
should(unknownInterval().equals(boundlessInterval())).be.null();
4707+
should(unknownInterval().equals(unknownInterval())).be.null();
4708+
});
4709+
});
4710+
4711+
describe('sameAs', () => {
4712+
let d: any;
4713+
beforeEach(() => {
4714+
d = data();
4715+
});
4716+
4717+
it('should properly handle boundless and unknown intervals', () => {
4718+
boundlessInterval().sameAs(boundlessInterval()).should.be.true();
4719+
boundlessInterval().sameAs(d.zeroToHundredLong.closed).should.be.false();
4720+
d.zeroToHundredLong.closed.sameAs(boundlessInterval()).should.be.false();
4721+
should(boundlessInterval().sameAs(unknownInterval())).be.null();
4722+
should(unknownInterval().sameAs(boundlessInterval())).be.null();
4723+
should(unknownInterval().sameAs(unknownInterval())).be.null();
4724+
});
45994725
});
46004726

46014727
describe('union', () => {
@@ -4740,6 +4866,14 @@ describe('LongInterval', () => {
47404866
it('should throw when the argument is a point', () => {
47414867
should(() => d.zeroToHundredLong.union(300n)).throw(Error);
47424868
});
4869+
4870+
it('should properly handle boundless and unknown intervals', () => {
4871+
boundlessInterval().union(d.zeroToHundredLong.closed).should.eql(boundlessInterval());
4872+
d.zeroToHundredLong.closed.union(boundlessInterval()).should.eql(boundlessInterval());
4873+
boundlessInterval().union(unknownInterval()).should.eql(boundlessInterval());
4874+
unknownInterval().union(boundlessInterval()).should.eql(boundlessInterval());
4875+
should(unknownInterval().union(unknownInterval())).be.null();
4876+
});
47434877
});
47444878

47454879
describe('intersect', () => {
@@ -4876,6 +5010,18 @@ describe('LongInterval', () => {
48765010
it('should throw when the argument is a point', () => {
48775011
should(() => d.zeroToHundredLong.intersect(50n)).throw(Error);
48785012
});
5013+
5014+
it('should properly handle boundless and unknown intervals', () => {
5015+
boundlessInterval()
5016+
.intersect(d.zeroToHundredLong.closed)
5017+
.should.eql(d.zeroToHundredLong.closed);
5018+
d.zeroToHundredLong.closed
5019+
.intersect(boundlessInterval())
5020+
.should.eql(d.zeroToHundredLong.closed);
5021+
boundlessInterval().intersect(unknownInterval()).should.eql(unknownInterval());
5022+
unknownInterval().intersect(boundlessInterval()).should.eql(unknownInterval());
5023+
should(unknownInterval().intersect(unknownInterval())).be.null();
5024+
});
48795025
});
48805026

48815027
describe('except', () => {
@@ -5131,6 +5277,29 @@ describe('LongInterval', () => {
51315277

51325278
uIvl.after(uIvl).should.be.false();
51335279
});
5280+
5281+
it('should properly handle boundless intervals', () => {
5282+
boundlessInterval().after(boundlessInterval()).should.be.false();
5283+
boundlessInterval().after(d.zeroToHundredLong.closed).should.be.false();
5284+
d.zeroToHundredLong.closed.after(boundlessInterval()).should.be.false();
5285+
unknownInterval().after(boundlessInterval()).should.be.false();
5286+
should(unknownInterval().after(unknownInterval())).be.null();
5287+
});
5288+
});
5289+
5290+
describe('sameOrAfter', () => {
5291+
let d: any;
5292+
beforeEach(() => {
5293+
d = data();
5294+
});
5295+
5296+
it('should properly handle boundless and unknown intervals', () => {
5297+
boundlessInterval().sameOrAfter(boundlessInterval()).should.be.true();
5298+
boundlessInterval().sameOrAfter(d.zeroToHundredLong.closed).should.be.false();
5299+
d.zeroToHundredLong.closed.sameOrAfter(boundlessInterval()).should.be.false();
5300+
should(unknownInterval().sameOrAfter(boundlessInterval())).be.null();
5301+
should(unknownInterval().sameOrAfter(unknownInterval())).be.null();
5302+
});
51345303
});
51355304

51365305
describe('before', () => {
@@ -5252,6 +5421,29 @@ describe('LongInterval', () => {
52525421

52535422
uIvl.before(uIvl).should.be.false();
52545423
});
5424+
5425+
it('should properly handle boundless intervals', () => {
5426+
boundlessInterval().before(boundlessInterval()).should.be.false();
5427+
boundlessInterval().before(d.zeroToHundredLong.closed).should.be.false();
5428+
d.zeroToHundredLong.closed.before(boundlessInterval()).should.be.false();
5429+
unknownInterval().before(boundlessInterval()).should.be.false();
5430+
should(unknownInterval().before(unknownInterval())).be.null();
5431+
});
5432+
});
5433+
5434+
describe('sameOrBefore', () => {
5435+
let d: any;
5436+
beforeEach(() => {
5437+
d = data();
5438+
});
5439+
5440+
it('should properly handle boundless and unknown intervals', () => {
5441+
boundlessInterval().sameOrBefore(boundlessInterval()).should.be.true();
5442+
boundlessInterval().sameOrBefore(d.zeroToHundredLong.closed).should.be.false();
5443+
d.zeroToHundredLong.closed.sameOrBefore(boundlessInterval()).should.be.false();
5444+
should(unknownInterval().sameOrBefore(boundlessInterval())).be.null();
5445+
should(unknownInterval().sameOrBefore(unknownInterval())).be.null();
5446+
});
52555447
});
52565448

52575449
describe('meets', () => {
@@ -5373,6 +5565,14 @@ describe('LongInterval', () => {
53735565

53745566
uIvl.meets(uIvl).should.be.false();
53755567
});
5568+
5569+
it('should properly handle boundless intervals', () => {
5570+
boundlessInterval().meets(boundlessInterval()).should.be.false();
5571+
boundlessInterval().meets(d.zeroToHundredLong.closed).should.be.false();
5572+
d.zeroToHundredLong.closed.meets(boundlessInterval()).should.be.false();
5573+
unknownInterval().meets(boundlessInterval()).should.be.false();
5574+
should(unknownInterval().meets(unknownInterval())).be.null();
5575+
});
53765576
});
53775577

53785578
describe('meetsAfter', () => {
@@ -5494,6 +5694,14 @@ describe('LongInterval', () => {
54945694

54955695
uIvl.meetsAfter(uIvl).should.be.false();
54965696
});
5697+
5698+
it('should properly handle boundless intervals', () => {
5699+
boundlessInterval().meetsAfter(boundlessInterval()).should.be.false();
5700+
boundlessInterval().meetsAfter(d.zeroToHundredLong.closed).should.be.false();
5701+
d.zeroToHundredLong.closed.meetsAfter(boundlessInterval()).should.be.false();
5702+
unknownInterval().meetsAfter(boundlessInterval()).should.be.false();
5703+
should(unknownInterval().meetsAfter(unknownInterval())).be.null();
5704+
});
54975705
});
54985706

54995707
describe('meetsBefore', () => {
@@ -5615,6 +5823,14 @@ describe('LongInterval', () => {
56155823

56165824
uIvl.meetsBefore(uIvl).should.be.false();
56175825
});
5826+
5827+
it('should properly handle boundless intervals', () => {
5828+
boundlessInterval().meetsBefore(boundlessInterval()).should.be.false();
5829+
boundlessInterval().meetsBefore(d.zeroToHundredLong.closed).should.be.false();
5830+
d.zeroToHundredLong.closed.meetsBefore(boundlessInterval()).should.be.false();
5831+
unknownInterval().meetsBefore(boundlessInterval()).should.be.false();
5832+
should(unknownInterval().meetsBefore(unknownInterval())).be.null();
5833+
});
56185834
});
56195835
});
56205836

0 commit comments

Comments
 (0)