@@ -2,8 +2,7 @@ import getMiniDecimal, {
22 BigIntDecimal ,
33 DecimalClass ,
44 NumberDecimal ,
5- roundDownUnsignedDecimal ,
6- roundUpUnsignedDecimal ,
5+ roundUnsignedDecimal ,
76 toFixed ,
87 ValueType ,
98} from '../src/utils/MiniDecimal' ;
@@ -154,19 +153,36 @@ describe('InputNumber.Util', () => {
154153 } ) ;
155154
156155 it ( 'round down' , ( ) => {
157- expect ( roundDownUnsignedDecimal ( '77.89' , 1 ) ) . toEqual ( '77.8' ) ;
158- expect ( roundDownUnsignedDecimal ( '77.1' , 2 ) ) . toEqual ( '77.10' ) ;
159- expect ( roundDownUnsignedDecimal ( '77.81' , 1 ) ) . toEqual ( '77.8' ) ;
160- expect ( roundDownUnsignedDecimal ( '77.50' , 1 ) ) . toEqual ( '77.5' ) ;
161- expect ( roundDownUnsignedDecimal ( '77.5999' , 0 ) ) . toEqual ( '77' ) ;
162- expect ( roundDownUnsignedDecimal ( '77.0001' , 0 ) ) . toEqual ( '77' ) ;
156+ expect ( roundUnsignedDecimal ( '0' , 0 , false ) ) . toEqual ( '0' ) ;
157+ expect ( roundUnsignedDecimal ( '77.89' , 1 , false ) ) . toEqual ( '77.8' ) ;
158+ expect ( roundUnsignedDecimal ( '77.1' , 2 , false ) ) . toEqual ( '77.10' ) ;
159+ expect ( roundUnsignedDecimal ( '77.81' , 1 , false ) ) . toEqual ( '77.8' ) ;
160+ expect ( roundUnsignedDecimal ( '77.50' , 1 , false ) ) . toEqual ( '77.5' ) ;
161+ expect ( roundUnsignedDecimal ( '77.5999' , 0 , false ) ) . toEqual ( '77' ) ;
162+ expect ( roundUnsignedDecimal ( '77.0001' , 0 , false ) ) . toEqual ( '77' ) ;
163163 } )
164+
164165 it ( 'round up' , ( ) => {
165- expect ( roundUpUnsignedDecimal ( '77.89' , 1 ) ) . toEqual ( '77.9' ) ;
166- expect ( roundUpUnsignedDecimal ( '77.81' , 1 ) ) . toEqual ( '77.9' ) ;
167- expect ( roundUpUnsignedDecimal ( '77.89' , 0 ) ) . toEqual ( '78' ) ;
168- expect ( roundUpUnsignedDecimal ( '77.599' , 0 ) ) . toEqual ( '78' ) ;
169- expect ( roundUpUnsignedDecimal ( '77.01' , 0 ) ) . toEqual ( '78' ) ;
166+ expect ( roundUnsignedDecimal ( '0' , 0 , true ) ) . toEqual ( '0' ) ;
167+ expect ( roundUnsignedDecimal ( '77.89' , 1 , true ) ) . toEqual ( '77.9' ) ;
168+ expect ( roundUnsignedDecimal ( '77.81' , 1 , true ) ) . toEqual ( '77.9' ) ;
169+ expect ( roundUnsignedDecimal ( '77.89' , 0 , true ) ) . toEqual ( '78' ) ;
170+ expect ( roundUnsignedDecimal ( '77.599' , 0 , true ) ) . toEqual ( '78' ) ;
171+ expect ( roundUnsignedDecimal ( '77.01' , 0 , true ) ) . toEqual ( '78' ) ;
172+ } )
173+
174+ it ( 'lessEquals' , ( ) => {
175+ expect ( new NumberDecimal ( 3 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeTruthy ( ) ;
176+ expect ( new NumberDecimal ( 2 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeTruthy ( ) ;
177+ expect ( new NumberDecimal ( 4 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeFalsy ( ) ;
178+ } )
179+
180+ it ( 'add operation on an invalid decimal' , ( ) => {
181+ expect ( new NumberDecimal ( 'XXX' ) . add ( 3 ) . toNumber ( ) ) . toEqual ( 3 ) ;
182+ } )
183+
184+ it ( 'add NaN' , ( ) => {
185+ expect ( new NumberDecimal ( 10 ) . add ( NaN ) . toNumber ( ) ) . toEqual ( 10 ) ;
170186 } )
171187 } ) ;
172188} ) ;
0 commit comments