@@ -2,10 +2,10 @@ import getMiniDecimal, {
2
2
BigIntDecimal ,
3
3
DecimalClass ,
4
4
NumberDecimal ,
5
- roundDownUnsignedDecimal ,
6
- roundUpUnsignedDecimal ,
5
+ roundUnsignedDecimal ,
7
6
toFixed ,
8
7
ValueType ,
8
+ lessEquals ,
9
9
} from '../src/utils/MiniDecimal' ;
10
10
11
11
jest . mock ( '../src/utils/supportUtil' ) ;
@@ -154,19 +154,36 @@ describe('InputNumber.Util', () => {
154
154
} ) ;
155
155
156
156
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' ) ;
157
+ expect ( roundUnsignedDecimal ( '0' , 0 , false ) ) . toEqual ( '0' ) ;
158
+ expect ( roundUnsignedDecimal ( '77.89' , 1 , false ) ) . toEqual ( '77.8' ) ;
159
+ expect ( roundUnsignedDecimal ( '77.1' , 2 , false ) ) . toEqual ( '77.10' ) ;
160
+ expect ( roundUnsignedDecimal ( '77.81' , 1 , false ) ) . toEqual ( '77.8' ) ;
161
+ expect ( roundUnsignedDecimal ( '77.50' , 1 , false ) ) . toEqual ( '77.5' ) ;
162
+ expect ( roundUnsignedDecimal ( '77.5999' , 0 , false ) ) . toEqual ( '77' ) ;
163
+ expect ( roundUnsignedDecimal ( '77.0001' , 0 , false ) ) . toEqual ( '77' ) ;
163
164
} )
165
+
164
166
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' ) ;
167
+ expect ( roundUnsignedDecimal ( '0' , 0 , true ) ) . toEqual ( '0' ) ;
168
+ expect ( roundUnsignedDecimal ( '77.89' , 1 , true ) ) . toEqual ( '77.9' ) ;
169
+ expect ( roundUnsignedDecimal ( '77.81' , 1 , true ) ) . toEqual ( '77.9' ) ;
170
+ expect ( roundUnsignedDecimal ( '77.89' , 0 , true ) ) . toEqual ( '78' ) ;
171
+ expect ( roundUnsignedDecimal ( '77.599' , 0 , true ) ) . toEqual ( '78' ) ;
172
+ expect ( roundUnsignedDecimal ( '77.01' , 0 , true ) ) . toEqual ( '78' ) ;
173
+ } )
174
+
175
+ it ( 'lessEquals' , ( ) => {
176
+ expect ( new NumberDecimal ( 3 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeTruthy ( ) ;
177
+ expect ( new NumberDecimal ( 2 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeTruthy ( ) ;
178
+ expect ( new NumberDecimal ( 4 ) . lessEquals ( new NumberDecimal ( 3 ) ) ) . toBeFalsy ( ) ;
179
+ } )
180
+
181
+ it ( 'add operation on an invalid decimal' , ( ) => {
182
+ expect ( new NumberDecimal ( 'XXX' ) . add ( 3 ) . toNumber ( ) ) . toEqual ( 3 ) ;
183
+ } )
184
+
185
+ it ( 'add NaN' , ( ) => {
186
+ expect ( new NumberDecimal ( 10 ) . add ( NaN ) . toNumber ( ) ) . toEqual ( 10 ) ;
170
187
} )
171
188
} ) ;
172
189
} ) ;
0 commit comments