-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.spec.js
More file actions
29 lines (28 loc) · 806 Bytes
/
api.spec.js
File metadata and controls
29 lines (28 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const {getNumeratorAndDenominatorFromPrice, scientificToString} = require('./algodex_api');
const Big = require('big.js')
it('should return sciToString', ()=>{
expect(scientificToString(new Big(2.22))).toEqual("2.22")
expect(scientificToString(new Big(1e-7))).toEqual("0.0000001")
})
it('getNumeratorAndDenominatorFromPrice', ()=>{
expect(getNumeratorAndDenominatorFromPrice(2.22)).toEqual({
d: 222,
n: 100,
});
expect(getNumeratorAndDenominatorFromPrice(1e-7)).toEqual({
d: 1,
n: 10000000,
});
expect(getNumeratorAndDenominatorFromPrice(0.45)).toEqual({
d: 45,
n: 100,
})
expect(getNumeratorAndDenominatorFromPrice(10.45)).toEqual({
d: 1045,
n: 100
});
expect(getNumeratorAndDenominatorFromPrice(0.0171)).toEqual({
d: 171,
n: 10000
});
});