@@ -1933,6 +1933,83 @@ 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 return the point value for a unit interval with open low bound' , ( ) => {
1954+ const point = DateTime . parse ( '2012-01-01T00:00:00.0+00' ) ;
1955+ const ivl = new Interval ( point . predecessor ( ) , point , false , true ) ;
1956+
1957+ ivl . pointFrom ( ) . should . eql ( point ) ;
1958+ } ) ;
1959+
1960+ it ( 'should return the point value for a unit interval with open high bound' , ( ) => {
1961+ const point = DateTime . parse ( '2012-01-01T00:00:00.0+00' ) ;
1962+ const ivl = new Interval ( point , point . successor ( ) , true , false ) ;
1963+
1964+ ivl . pointFrom ( ) . should . eql ( point ) ;
1965+ } ) ;
1966+
1967+ it ( 'should throw for a non-unit interval with closed high bound' , ( ) => {
1968+ const point = DateTime . parse ( '2012-01-01T00:00:00.0+00' ) ;
1969+ const ivl = new Interval ( point , point . successor ( ) , true , true ) ;
1970+
1971+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
1972+ } ) ;
1973+
1974+ it ( 'should return the value for a unit interval with null (max) high bound' , ( ) => {
1975+ const ivl = new Interval ( MAX_DATETIME_VALUE , null ) ;
1976+
1977+ ivl . pointFrom ( ) . should . eql ( MAX_DATETIME_VALUE ) ;
1978+ } ) ;
1979+
1980+ it ( 'should return the value for a unit interval with null (min) low bound' , ( ) => {
1981+ const ivl = new Interval ( null , MIN_DATETIME_VALUE ) ;
1982+
1983+ ivl . pointFrom ( ) . should . eql ( MIN_DATETIME_VALUE ) ;
1984+ } ) ;
1985+
1986+ it ( 'should return the point value for a unit interval with limited precision' , ( ) => {
1987+ const point = DateTime . parse ( '2012-01-01' ) ;
1988+ const ivl = new Interval ( point , point ) ;
1989+
1990+ ivl . pointFrom ( ) . should . eql ( point ) ;
1991+ } ) ;
1992+
1993+ it ( 'should throw for an interval with closed null high bound' , function ( ) {
1994+ const ivl = new Interval ( DateTime . parse ( '2012-01-01T00:00:00.0+00' ) , null ) ;
1995+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
1996+ } ) ;
1997+
1998+ it ( 'should throw for an interval with open null high bound' , function ( ) {
1999+ const ivl = new Interval ( DateTime . parse ( '2012-01-01T00:00:00.0+00' ) , null , true , false ) ;
2000+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
2001+ } ) ;
2002+
2003+ it ( 'should throw for an interval with closed null low bound' , function ( ) {
2004+ const ivl = new Interval ( null , DateTime . parse ( '2012-01-01T00:00:00.0+00' ) ) ;
2005+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
2006+ } ) ;
2007+
2008+ it ( 'should throw for an interval with open null low bound' , function ( ) {
2009+ const ivl = new Interval ( null , DateTime . parse ( '2012-01-01T00:00:00.0+00' ) , false , true ) ;
2010+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
2011+ } ) ;
2012+ } ) ;
19362013} ) ;
19372014
19382015describe ( 'IntegerInterval' , ( ) => {
@@ -3713,6 +3790,43 @@ describe('IntegerInterval', () => {
37133790 uIvl . meetsBefore ( uIvl ) . should . be . false ( ) ;
37143791 } ) ;
37153792 } ) ;
3793+
3794+ describe ( 'pointFrom' , ( ) => {
3795+ it ( 'should return the point value for a unit interval' , ( ) => {
3796+ const ivl = new Interval ( 0 , 0 ) ;
3797+ ivl . pointFrom ( ) . should . eql ( 0 ) ;
3798+ } ) ;
3799+
3800+ it ( 'should throw on pointFrom call if not a unit interval' , ( ) => {
3801+ const ivl = new Interval ( 0 , 1 ) ;
3802+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
3803+ } ) ;
3804+
3805+ it ( 'should return the point value for a unit interval' , ( ) => {
3806+ const ivl = new Interval ( 12 , 12 ) ;
3807+ ivl . pointFrom ( ) . should . eql ( 12 ) ;
3808+ } ) ;
3809+
3810+ it ( 'should throw on pointFrom call if not a unit interval' , ( ) => {
3811+ const ivl = new Interval ( 8 , 9 ) ;
3812+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
3813+ } ) ;
3814+
3815+ it ( 'should return the point from an interval with an open high bound' , async function ( ) {
3816+ const ivl = new Interval ( 100 , 101 , true , false ) ;
3817+ ivl . pointFrom ( ) . should . eql ( 100 ) ;
3818+ } ) ;
3819+
3820+ it ( 'should throw for an interval with null high bound' , function ( ) {
3821+ const ivl = new Interval ( 23 , null ) ;
3822+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
3823+ } ) ;
3824+
3825+ it ( 'should throw for an interval with undefined width' , function ( ) {
3826+ const ivl = new Interval ( 0 , 0 , false , false ) ;
3827+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
3828+ } ) ;
3829+ } ) ;
37163830} ) ;
37173831
37183832describe ( 'LongInterval' , ( ) => {
@@ -5493,6 +5607,33 @@ describe('LongInterval', () => {
54935607 uIvl . meetsBefore ( uIvl ) . should . be . false ( ) ;
54945608 } ) ;
54955609 } ) ;
5610+
5611+ describe ( 'pointFrom' , ( ) => {
5612+ it ( 'should return the point value for a unit interval' , ( ) => {
5613+ const ivl = new Interval ( 10n , 10n ) ;
5614+ ivl . pointFrom ( ) . should . eql ( 10n ) ;
5615+ } ) ;
5616+
5617+ it ( 'should throw on pointFrom call if not a unit interval' , ( ) => {
5618+ const ivl = new Interval ( 0n , 1n ) ;
5619+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
5620+ } ) ;
5621+
5622+ it ( 'should return the point from an interval with an open high bound' , async function ( ) {
5623+ const ivl = new Interval ( 5n , 6n , true , false ) ;
5624+ ivl . pointFrom ( ) . should . eql ( 5n ) ;
5625+ } ) ;
5626+
5627+ it ( 'should throw for an interval with null high bound' , function ( ) {
5628+ const ivl = new Interval ( 0n , null ) ;
5629+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
5630+ } ) ;
5631+
5632+ it ( 'should throw for an interval with undefined width' , function ( ) {
5633+ const ivl = new Interval ( 0n , 0n , false , false ) ;
5634+ should ( ( ) => ivl . pointFrom ( ) ) . throw ( Error ) ;
5635+ } ) ;
5636+ } ) ;
54965637} ) ;
54975638
54985639describe ( 'DecimalInterval' , ( ) => {
0 commit comments