@@ -2,8 +2,7 @@ import getMiniDecimal, {
2
2
BigIntDecimal ,
3
3
DecimalClass ,
4
4
NumberDecimal ,
5
- roundDownUnsignedDecimal ,
6
- roundUpUnsignedDecimal ,
5
+ roundUnsignedDecimal ,
7
6
toFixed ,
8
7
ValueType ,
9
8
} from '../src/utils/MiniDecimal' ;
@@ -154,19 +153,36 @@ describe('InputNumber.Util', () => {
154
153
} ) ;
155
154
156
155
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' ) ;
163
163
} )
164
+
164
165
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 ) ;
170
186
} )
171
187
} ) ;
172
188
} ) ;
0 commit comments