()
| 2 | import testSharedMethods from '../Exchange/base/test.sharedMethods.js'; |
| 3 | |
| 4 | function testSort () { |
| 5 | |
| 6 | const exchange = new ccxt.Exchange ({ |
| 7 | 'id': 'sampleexchange', |
| 8 | }); |
| 9 | |
| 10 | // empty array |
| 11 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([]), []); |
| 12 | |
| 13 | // single element |
| 14 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 'a' ]), [ 'a' ]); |
| 15 | |
| 16 | // already sorted (idempotent) |
| 17 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 'a', 'b', 'c' ]), [ 'a', 'b', 'c' ]); |
| 18 | |
| 19 | // duplicates |
| 20 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 'b', 'a', 'b', 'c' ]), [ 'a', 'b', 'b', 'c' ]); |
| 21 | |
| 22 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 'b', 'a', 'c', 'd' ]), [ 'a', 'b', 'c', 'd' ]); |
| 23 | |
| 24 | // todo 1: atm, `sort` is only meant for strings. we should update to support numerics |
| 25 | // todo 2: add test for above 10, eg: 1, 2, 10, 20, 21 |
| 26 | |
| 27 | // // integers (single-digit, safe for cross-language lexicographic/numeric consistency) |
| 28 | // testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 3, 1, 2 ]), [ 1, 2, 3 ]); |
| 29 | // testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 5, 3, 1, 4, 2 ]), [ 1, 2, 3, 4, 5 ]); |
| 30 | // testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 0, 3, 1, 2 ]), [ 0, 1, 2, 3 ]); |
| 31 | |
| 32 | // // floats (values chosen so lexicographic order matches numeric order) |
| 33 | // testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 1.5, 0.5, 2.5 ]), [ 0.5, 1.5, 2.5 ]); |
| 34 | // testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', exchange.sort ([ 3.3, 1.1, 2.2 ]), [ 1.1, 2.2, 3.3 ]); |
| 35 | |
| 36 | // immutability - original array should not be modified |
| 37 | const original = [ 'b', 'a', 'c' ]; |
| 38 | exchange.sort (original); |
| 39 | testSharedMethods.assertDeepEqual (exchange, undefined, 'sort', original, [ 'b', 'a', 'c' ]); |
| 40 | } |
| 41 | |
| 42 | export default testSort; |
nothing calls this directly
no test coverage detected
searching dependent graphs…