()
| 12 | return true; |
| 13 | } |
| 14 | function testSafeMethods() { |
| 15 | const exchange = new ccxt.Exchange({ |
| 16 | 'id': 'regirock', |
| 17 | }); |
| 18 | const inputDict = { |
| 19 | 'i': 1, |
| 20 | 'f': 0.123, |
| 21 | 'bool': true, |
| 22 | 'list': [1, 2, 3], |
| 23 | 'dict': { 'a': 1 }, |
| 24 | 'listOfDicts': [{ 'a': 1 }], |
| 25 | 'str': 'heLlo', |
| 26 | 'strNumber': '3', |
| 27 | // |
| 28 | 'zeroNumeric': 0, |
| 29 | 'zeroString': '0', |
| 30 | 'undefined': undefined, |
| 31 | 'emptyString': '', |
| 32 | 'floatNumeric': 0.123, |
| 33 | 'floatString': '0.123', |
| 34 | 'longInt': 123456789012345, |
| 35 | }; |
| 36 | const inputList = ['Hi', 2]; |
| 37 | const compareDict = { |
| 38 | 'a': 1, |
| 39 | }; |
| 40 | const compareList = [1, 2, 3]; |
| 41 | const factor = 10; |
| 42 | // safeValue |
| 43 | assert(exchange.safeValue(inputDict, 'i') === 1); |
| 44 | assert(exchange.safeValue(inputDict, 'f') === 0.123); |
| 45 | assert(exchange.safeValue(inputDict, 'bool') === true); |
| 46 | assert(equals(exchange.safeValue(inputDict, 'list'), compareList)); |
| 47 | let dictObject = exchange.safeValue(inputDict, 'dict'); |
| 48 | assert(equals(dictObject, compareDict)); |
| 49 | assert(exchange.safeValue(inputDict, 'str') === 'heLlo'); |
| 50 | assert(exchange.safeValue(inputDict, 'strNumber') === '3'); |
| 51 | assert(exchange.safeValue(inputList, 0) === 'Hi'); |
| 52 | // safeValue2 |
| 53 | assert(exchange.safeValue2(inputDict, 'a', 'i') === 1); |
| 54 | assert(exchange.safeValue2(inputDict, 'a', 'f') === 0.123); |
| 55 | assert(exchange.safeValue2(inputDict, 'a', 'bool') === true); |
| 56 | assert(equals(exchange.safeValue2(inputDict, 'a', 'list'), compareList)); |
| 57 | dictObject = exchange.safeValue2(inputDict, 'a', 'dict'); |
| 58 | assert(equals(dictObject, compareDict)); |
| 59 | assert(exchange.safeValue2(inputDict, 'a', 'str') === 'heLlo'); |
| 60 | assert(exchange.safeValue2(inputDict, 'a', 'strNumber') === '3'); |
| 61 | assert(exchange.safeValue2(inputList, 2, 0) === 'Hi'); |
| 62 | // safeValueN |
| 63 | assert(exchange.safeValueN(inputDict, ['a', 'b', 'i']) === 1); |
| 64 | assert(exchange.safeValueN(inputDict, ['a', 'b', 'f']) === 0.123); |
| 65 | assert(exchange.safeValueN(inputDict, ['a', 'b', 'bool']) === true); |
| 66 | assert(equals(exchange.safeValueN(inputDict, ['a', 'b', 'list']), compareList)); |
| 67 | dictObject = exchange.safeValueN(inputDict, ['a', 'b', 'dict']); |
| 68 | assert(equals(dictObject, compareDict)); |
| 69 | assert(exchange.safeValueN(inputDict, ['a', 'b', 'str']) === 'heLlo'); |
| 70 | assert(exchange.safeValueN(inputDict, ['a', 'b', 'strNumber']) === '3'); |
| 71 | assert(exchange.safeValueN(inputList, [3, 2, 0]) === 'Hi'); |
no test coverage detected
searching dependent graphs…