Skip to content

Commit 50afee8

Browse files
committed
add extra tests
1 parent 16de73e commit 50afee8

2 files changed

Lines changed: 95 additions & 0 deletions

File tree

test/datatypes/interval-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ export default () => {
8989
DateTime.parse('2012-01-01T00:00:00.0'),
9090
DateTime.parse('2012-07-01T00:00:00.0')
9191
);
92+
data['unitIvl'] = new TestInterval(
93+
DateTime.parse('2012-01-01T00:00:00.0'),
94+
DateTime.parse('2012-01-01T00:00:00.0')
95+
);
9296
data['bef2012'] = TestDateTime.parse('2011-06-01T00:00:00.0');
9397
data['beg2012'] = TestDateTime.parse('2012-01-01T00:00:00.0');
9498
data['mid2012'] = TestDateTime.parse('2012-06-01T00:00:00.0');

test/datatypes/interval-test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,33 @@ describe('DateTimeInterval', () => {
19331933
x.toYear.meetsBefore(y.closed).should.be.false();
19341934
});
19351935
});
1936+
1937+
describe('pointFrom', () => {
1938+
it('should return the point value for a unit interval', () => {
1939+
const point = DateTime.parse('2012-01-01T00:00:00.0+00');
1940+
const ivl = new Interval(point, point);
1941+
1942+
ivl.pointFrom().should.eql(point);
1943+
});
1944+
1945+
it('should throw on pointFrom call if not a unit interval', () => {
1946+
const ivl = new Interval(
1947+
DateTime.parse('2012-01-01T00:00:00.0+00'),
1948+
DateTime.parse('2025-01-01T00:00:00.0+00')
1949+
);
1950+
should(() => ivl.pointFrom()).throw(Error);
1951+
});
1952+
1953+
it('should throw for an interval with null high bound', function () {
1954+
const ivl = new Interval(DateTime.parse('2012-01-01T00:00:00.0+00'), null);
1955+
should(() => ivl.pointFrom()).throw(Error);
1956+
});
1957+
1958+
it('should throw for an interval with undefined width', function () {
1959+
const ivl = new Interval(0, 0, false, false);
1960+
should(() => ivl.pointFrom()).throw(Error);
1961+
});
1962+
});
19361963
});
19371964

19381965
describe('IntegerInterval', () => {
@@ -3713,6 +3740,43 @@ describe('IntegerInterval', () => {
37133740
uIvl.meetsBefore(uIvl).should.be.false();
37143741
});
37153742
});
3743+
3744+
describe('pointFrom', () => {
3745+
it('should return the point value for a unit interval', () => {
3746+
const ivl = new Interval(0, 0);
3747+
ivl.pointFrom().should.eql(0);
3748+
});
3749+
3750+
it('should throw on pointFrom call if not a unit interval', () => {
3751+
const ivl = new Interval(0, 1);
3752+
should(() => ivl.pointFrom()).throw(Error);
3753+
});
3754+
3755+
it('should return the point value for a unit interval', () => {
3756+
const ivl = new Interval(12, 12);
3757+
ivl.pointFrom().should.eql(12);
3758+
});
3759+
3760+
it('should throw on pointFrom call if not a unit interval', () => {
3761+
const ivl = new Interval(8, 9);
3762+
should(() => ivl.pointFrom()).throw(Error);
3763+
});
3764+
3765+
it('should return the point from an interval with an open high bound', async function () {
3766+
const ivl = new Interval(100, 101, true, false);
3767+
ivl.pointFrom().should.eql(100);
3768+
});
3769+
3770+
it('should throw for an interval with null high bound', function () {
3771+
const ivl = new Interval(23, null);
3772+
should(() => ivl.pointFrom()).throw(Error);
3773+
});
3774+
3775+
it('should throw for an interval with undefined width', function () {
3776+
const ivl = new Interval(0, 0, false, false);
3777+
should(() => ivl.pointFrom()).throw(Error);
3778+
});
3779+
});
37163780
});
37173781

37183782
describe('LongInterval', () => {
@@ -5493,6 +5557,33 @@ describe('LongInterval', () => {
54935557
uIvl.meetsBefore(uIvl).should.be.false();
54945558
});
54955559
});
5560+
5561+
describe('pointFrom', () => {
5562+
it('should return the point value for a unit interval', () => {
5563+
const ivl = new Interval(10n, 10n);
5564+
ivl.pointFrom().should.eql(10n);
5565+
});
5566+
5567+
it('should throw on pointFrom call if not a unit interval', () => {
5568+
const ivl = new Interval(0n, 1n);
5569+
should(() => ivl.pointFrom()).throw(Error);
5570+
});
5571+
5572+
it('should return the point from an interval with an open high bound', async function () {
5573+
const ivl = new Interval(5n, 6n, true, false);
5574+
ivl.pointFrom().should.eql(5n);
5575+
});
5576+
5577+
it('should throw for an interval with null high bound', function () {
5578+
const ivl = new Interval(0n, null);
5579+
should(() => ivl.pointFrom()).throw(Error);
5580+
});
5581+
5582+
it('should throw for an interval with undefined width', function () {
5583+
const ivl = new Interval(0n, 0n, false, false);
5584+
should(() => ivl.pointFrom()).throw(Error);
5585+
});
5586+
});
54965587
});
54975588

54985589
describe('DecimalInterval', () => {

0 commit comments

Comments
 (0)