Skip to content

Commit 06d7db6

Browse files
committed
Add more boundless/unknown interval tests for Long intervals
1 parent 433fc4d commit 06d7db6

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
@@ -4167,6 +4167,8 @@ describe('LongInterval', () => {
41674167
new Interval(0n, null, true, false).contains(0n).should.be.true();
41684168
should(new Interval(0n, null, true, false).contains(123456789n)).be.null();
41694169
new Interval(0n, null, true, false).contains(-1n).should.be.false();
4170+
new Interval(null, null).contains(5n).should.be.true();
4171+
should(new Interval(null, null, false, false).contains(5n)).be.null();
41704172
});
41714173

41724174
it('should properly handle imprecision', () => {
@@ -4408,6 +4410,15 @@ describe('LongInterval', () => {
44084410
it('should include a point Long', () => {
44094411
d.zeroToHundredLong.closed.includes(50n).should.be.true();
44104412
});
4413+
4414+
it('should properly handle boundless and unknown intervals', () => {
4415+
boundlessInterval().includes(50n).should.be.true();
4416+
boundlessInterval().includes(d.zeroToHundredLong.closed).should.be.true();
4417+
boundlessInterval().includes(unknownInterval()).should.be.true();
4418+
d.zeroToHundredLong.closed.includes(boundlessInterval()).should.be.false();
4419+
should(unknownInterval().includes(d.zeroToHundredLong.closed)).be.null();
4420+
should(unknownInterval().includes(boundlessInterval())).be.null();
4421+
});
44114422
});
44124423

44134424
describe('includedIn', () => {
@@ -4527,6 +4538,57 @@ describe('LongInterval', () => {
45274538
d.zeroToHundredLong.closed.includedIn(50n).should.be.true();
45284539
d.zeroToHundredLong.closed.includedIn(500n).should.be.false();
45294540
});
4541+
4542+
it('should properly handle boundless and unknown intervals', () => {
4543+
d.zeroToHundredLong.closed.includedIn(boundlessInterval()).should.be.true();
4544+
boundlessInterval().includedIn(d.zeroToHundredLong.closed).should.be.false();
4545+
boundlessInterval().includedIn(boundlessInterval()).should.be.true();
4546+
unknownInterval().includedIn(boundlessInterval()).should.be.true();
4547+
});
4548+
});
4549+
4550+
describe('properlyIncludes', () => {
4551+
let d: any;
4552+
beforeEach(() => {
4553+
d = data();
4554+
});
4555+
4556+
it('should properly handle boundless and unknown intervals', () => {
4557+
boundlessInterval().properlyIncludes(d.zeroToHundredLong.closed).should.be.true();
4558+
boundlessInterval().properlyIncludes(boundlessInterval()).should.be.false();
4559+
should(boundlessInterval().properlyIncludes(unknownInterval())).be.null();
4560+
should(unknownInterval().properlyIncludes(d.zeroToHundredLong.closed)).be.null();
4561+
});
4562+
});
4563+
4564+
describe('starts', () => {
4565+
let d: any;
4566+
beforeEach(() => {
4567+
d = data();
4568+
});
4569+
4570+
it('should properly handle boundless and unknown intervals', () => {
4571+
boundlessInterval().starts(boundlessInterval()).should.be.true();
4572+
boundlessInterval().starts(d.zeroToHundredLong.closed).should.be.false();
4573+
d.zeroToHundredLong.closed.starts(boundlessInterval()).should.be.false();
4574+
should(boundlessInterval().starts(unknownInterval())).be.null();
4575+
should(unknownInterval().starts(boundlessInterval())).be.null();
4576+
});
4577+
});
4578+
4579+
describe('ends', () => {
4580+
let d: any;
4581+
beforeEach(() => {
4582+
d = data();
4583+
});
4584+
4585+
it('should properly handle boundless and unknown intervals', () => {
4586+
boundlessInterval().ends(boundlessInterval()).should.be.true();
4587+
boundlessInterval().ends(d.zeroToHundredLong.closed).should.be.false();
4588+
d.zeroToHundredLong.closed.ends(boundlessInterval()).should.be.false();
4589+
should(boundlessInterval().ends(unknownInterval())).be.null();
4590+
should(unknownInterval().ends(boundlessInterval())).be.null();
4591+
});
45304592
});
45314593

45324594
describe('overlaps(LongInterval)', () => {
@@ -4619,6 +4681,30 @@ describe('LongInterval', () => {
46194681
y.open.overlaps(x.open).should.be.true();
46204682
});
46214683

4684+
it('should properly handle null endpoints', () => {
4685+
const negativeInterval = new Interval(-123456789n, -1n);
4686+
const positiveInterval = new Interval(1n, 123456789n);
4687+
const startsAtZero = new Interval(0n, 123456789n);
4688+
const endsAtZero = new Interval(-123456789n, 0n);
4689+
4690+
should(new Interval(null, 0n).overlaps(negativeInterval)).be.true();
4691+
should(new Interval(null, 0n).overlaps(positiveInterval)).be.false();
4692+
should(new Interval(null, 0n, false, true).overlaps(startsAtZero)).be.true();
4693+
should(new Interval(null, 0n, false, true).overlaps(negativeInterval)).be.null();
4694+
should(new Interval(null, 0n, false, true).overlaps(positiveInterval)).be.false();
4695+
4696+
should(new Interval(0n, null).overlaps(positiveInterval)).be.true();
4697+
should(new Interval(0n, null).overlaps(negativeInterval)).be.false();
4698+
should(new Interval(0n, null, true, false).overlaps(endsAtZero)).be.true();
4699+
should(new Interval(0n, null, true, false).overlaps(positiveInterval)).be.null();
4700+
should(new Interval(0n, null, true, false).overlaps(negativeInterval)).be.false();
4701+
4702+
should(new Interval(null, null).overlaps(d.zeroToHundredLong.closed)).be.true();
4703+
should(new Interval(null, null, false, false).overlaps(d.zeroToHundredLong.closed)).be.null();
4704+
should(d.zeroToHundredLong.closed.overlaps(new Interval(null, null))).be.true();
4705+
should(d.zeroToHundredLong.closed.overlaps(new Interval(null, null, false, false))).be.null();
4706+
});
4707+
46224708
it('should properly handle boundless and unknown intervals', () => {
46234709
boundlessInterval().overlaps(boundlessInterval()).should.be.true();
46244710
boundlessInterval().overlaps(d.zeroToHundredLong.closed).should.be.true();
@@ -4679,6 +4765,21 @@ describe('LongInterval', () => {
46794765
d.zeroToHundredLong.closed.overlaps(105n).should.be.false();
46804766
});
46814767

4768+
it('should properly handle null endpoints', () => {
4769+
should(new Interval(null, 0n).overlaps(-123456789n)).be.true();
4770+
should(new Interval(null, 0n).overlaps(1n)).be.false();
4771+
should(new Interval(null, 0n, false, true).overlaps(0n)).be.true();
4772+
should(new Interval(null, 0n, false, true).overlaps(-123456789n)).be.null();
4773+
should(new Interval(null, 0n, false, true).overlaps(1n)).be.false();
4774+
should(new Interval(0n, null).overlaps(123456789n)).be.true();
4775+
should(new Interval(0n, null).overlaps(-1n)).be.false();
4776+
should(new Interval(0n, null, true, false).overlaps(0n)).be.true();
4777+
should(new Interval(0n, null, true, false).overlaps(123456789n)).be.null();
4778+
should(new Interval(0n, null, true, false).overlaps(-1n)).be.false();
4779+
should(new Interval(null, null).overlaps(5n)).be.true();
4780+
should(new Interval(null, null, false, false).overlaps(5n)).be.null();
4781+
});
4782+
46824783
it('should properly handle boundless and unknown intervals', () => {
46834784
boundlessInterval().overlaps(5n).should.be.true();
46844785
should(boundlessInterval().overlaps(null)).be.null();
@@ -4885,6 +4986,31 @@ describe('LongInterval', () => {
48854986

48864987
ivl.equals(point).should.be.false();
48874988
});
4989+
4990+
it('should properly handle boundless and unknown intervals', () => {
4991+
boundlessInterval().equals(boundlessInterval()).should.be.true();
4992+
boundlessInterval().equals(d.zeroToHundredLong.closed).should.be.false();
4993+
d.zeroToHundredLong.closed.equals(boundlessInterval()).should.be.false();
4994+
should(boundlessInterval().equals(unknownInterval())).be.null();
4995+
should(unknownInterval().equals(boundlessInterval())).be.null();
4996+
should(unknownInterval().equals(unknownInterval())).be.null();
4997+
});
4998+
});
4999+
5000+
describe('sameAs', () => {
5001+
let d: any;
5002+
beforeEach(() => {
5003+
d = data();
5004+
});
5005+
5006+
it('should properly handle boundless and unknown intervals', () => {
5007+
boundlessInterval().sameAs(boundlessInterval()).should.be.true();
5008+
boundlessInterval().sameAs(d.zeroToHundredLong.closed).should.be.false();
5009+
d.zeroToHundredLong.closed.sameAs(boundlessInterval()).should.be.false();
5010+
should(boundlessInterval().sameAs(unknownInterval())).be.null();
5011+
should(unknownInterval().sameAs(boundlessInterval())).be.null();
5012+
should(unknownInterval().sameAs(unknownInterval())).be.null();
5013+
});
48885014
});
48895015

48905016
describe('union', () => {
@@ -5029,6 +5155,14 @@ describe('LongInterval', () => {
50295155
it('should throw when the argument is a point', () => {
50305156
should(() => d.zeroToHundredLong.union(300n)).throw(Error);
50315157
});
5158+
5159+
it('should properly handle boundless and unknown intervals', () => {
5160+
boundlessInterval().union(d.zeroToHundredLong.closed).should.eql(boundlessInterval());
5161+
d.zeroToHundredLong.closed.union(boundlessInterval()).should.eql(boundlessInterval());
5162+
boundlessInterval().union(unknownInterval()).should.eql(boundlessInterval());
5163+
unknownInterval().union(boundlessInterval()).should.eql(boundlessInterval());
5164+
should(unknownInterval().union(unknownInterval())).be.null();
5165+
});
50325166
});
50335167

50345168
describe('intersect', () => {
@@ -5165,6 +5299,18 @@ describe('LongInterval', () => {
51655299
it('should throw when the argument is a point', () => {
51665300
should(() => d.zeroToHundredLong.intersect(50n)).throw(Error);
51675301
});
5302+
5303+
it('should properly handle boundless and unknown intervals', () => {
5304+
boundlessInterval()
5305+
.intersect(d.zeroToHundredLong.closed)
5306+
.should.eql(d.zeroToHundredLong.closed);
5307+
d.zeroToHundredLong.closed
5308+
.intersect(boundlessInterval())
5309+
.should.eql(d.zeroToHundredLong.closed);
5310+
boundlessInterval().intersect(unknownInterval()).should.eql(unknownInterval());
5311+
unknownInterval().intersect(boundlessInterval()).should.eql(unknownInterval());
5312+
should(unknownInterval().intersect(unknownInterval())).be.null();
5313+
});
51685314
});
51695315

51705316
describe('except', () => {
@@ -5420,6 +5566,29 @@ describe('LongInterval', () => {
54205566

54215567
uIvl.after(uIvl).should.be.false();
54225568
});
5569+
5570+
it('should properly handle boundless intervals', () => {
5571+
boundlessInterval().after(boundlessInterval()).should.be.false();
5572+
boundlessInterval().after(d.zeroToHundredLong.closed).should.be.false();
5573+
d.zeroToHundredLong.closed.after(boundlessInterval()).should.be.false();
5574+
unknownInterval().after(boundlessInterval()).should.be.false();
5575+
should(unknownInterval().after(unknownInterval())).be.null();
5576+
});
5577+
});
5578+
5579+
describe('sameOrAfter', () => {
5580+
let d: any;
5581+
beforeEach(() => {
5582+
d = data();
5583+
});
5584+
5585+
it('should properly handle boundless and unknown intervals', () => {
5586+
boundlessInterval().sameOrAfter(boundlessInterval()).should.be.true();
5587+
boundlessInterval().sameOrAfter(d.zeroToHundredLong.closed).should.be.false();
5588+
d.zeroToHundredLong.closed.sameOrAfter(boundlessInterval()).should.be.false();
5589+
should(unknownInterval().sameOrAfter(boundlessInterval())).be.null();
5590+
should(unknownInterval().sameOrAfter(unknownInterval())).be.null();
5591+
});
54235592
});
54245593

54255594
describe('before', () => {
@@ -5541,6 +5710,29 @@ describe('LongInterval', () => {
55415710

55425711
uIvl.before(uIvl).should.be.false();
55435712
});
5713+
5714+
it('should properly handle boundless intervals', () => {
5715+
boundlessInterval().before(boundlessInterval()).should.be.false();
5716+
boundlessInterval().before(d.zeroToHundredLong.closed).should.be.false();
5717+
d.zeroToHundredLong.closed.before(boundlessInterval()).should.be.false();
5718+
unknownInterval().before(boundlessInterval()).should.be.false();
5719+
should(unknownInterval().before(unknownInterval())).be.null();
5720+
});
5721+
});
5722+
5723+
describe('sameOrBefore', () => {
5724+
let d: any;
5725+
beforeEach(() => {
5726+
d = data();
5727+
});
5728+
5729+
it('should properly handle boundless and unknown intervals', () => {
5730+
boundlessInterval().sameOrBefore(boundlessInterval()).should.be.true();
5731+
boundlessInterval().sameOrBefore(d.zeroToHundredLong.closed).should.be.false();
5732+
d.zeroToHundredLong.closed.sameOrBefore(boundlessInterval()).should.be.false();
5733+
should(unknownInterval().sameOrBefore(boundlessInterval())).be.null();
5734+
should(unknownInterval().sameOrBefore(unknownInterval())).be.null();
5735+
});
55445736
});
55455737

55465738
describe('meets', () => {
@@ -5662,6 +5854,14 @@ describe('LongInterval', () => {
56625854

56635855
uIvl.meets(uIvl).should.be.false();
56645856
});
5857+
5858+
it('should properly handle boundless intervals', () => {
5859+
boundlessInterval().meets(boundlessInterval()).should.be.false();
5860+
boundlessInterval().meets(d.zeroToHundredLong.closed).should.be.false();
5861+
d.zeroToHundredLong.closed.meets(boundlessInterval()).should.be.false();
5862+
unknownInterval().meets(boundlessInterval()).should.be.false();
5863+
should(unknownInterval().meets(unknownInterval())).be.null();
5864+
});
56655865
});
56665866

56675867
describe('meetsAfter', () => {
@@ -5783,6 +5983,14 @@ describe('LongInterval', () => {
57835983

57845984
uIvl.meetsAfter(uIvl).should.be.false();
57855985
});
5986+
5987+
it('should properly handle boundless intervals', () => {
5988+
boundlessInterval().meetsAfter(boundlessInterval()).should.be.false();
5989+
boundlessInterval().meetsAfter(d.zeroToHundredLong.closed).should.be.false();
5990+
d.zeroToHundredLong.closed.meetsAfter(boundlessInterval()).should.be.false();
5991+
unknownInterval().meetsAfter(boundlessInterval()).should.be.false();
5992+
should(unknownInterval().meetsAfter(unknownInterval())).be.null();
5993+
});
57865994
});
57875995

57885996
describe('meetsBefore', () => {
@@ -5904,6 +6112,14 @@ describe('LongInterval', () => {
59046112

59056113
uIvl.meetsBefore(uIvl).should.be.false();
59066114
});
6115+
6116+
it('should properly handle boundless intervals', () => {
6117+
boundlessInterval().meetsBefore(boundlessInterval()).should.be.false();
6118+
boundlessInterval().meetsBefore(d.zeroToHundredLong.closed).should.be.false();
6119+
d.zeroToHundredLong.closed.meetsBefore(boundlessInterval()).should.be.false();
6120+
unknownInterval().meetsBefore(boundlessInterval()).should.be.false();
6121+
should(unknownInterval().meetsBefore(unknownInterval())).be.null();
6122+
});
59076123
});
59086124
});
59096125

0 commit comments

Comments
 (0)