<commit_before>/*  ------------------------------------------------------------------------ */

const ccxt     = require ('../../ccxt.js')
    , assert   = require ('assert')
    , log      = require ('ololog')
    , ansi     = require ('ansicolor').nice;

/*  ------------------------------------------------------------------------ */

const chai = require ('chai')
                .use (require ('chai-as-promised'))
                .should ()

/*  ------------------------------------------------------------------------ */

describe ('ccxt base code', () => {

    it ('safeFloat is robust', async () => {

        assert.strictEqual (ccxt.safeFloat ({'float': '1.0'}, 'float'), 1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': '-1.0'}, 'float'), -1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': 1.0}, 'float'), 1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': 0}, 'float'), 0)
        assert.strictEqual (ccxt.safeFloat ({'float': undefined}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({'float': ""}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({'float': ""}, 'float', 0), 0)
        assert.strictEqual (ccxt.safeFloat ({}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({}, 'float', 0), 0)
    })

    it ('setTimeout_safe is working', (done) => {

        const start = Date.now ()
        const calls = []

        const brokenSetTimeout = (done, ms) => {
            calls.push ({ when: Date.now () - start, ms_asked: ms })
            return setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)
        }

        const approxEquals = (a, b) => Math.abs (a - b) <= 10

        // ask to sleep 250ms
        ccxt.setTimeout_safe (() => {
            assert (approxEquals (calls[0].ms_asked, 250))
            assert (approxEquals (calls[1].ms_asked, 150))
            assert (approxEquals (calls[2].ms_asked, 50))
            done ()
        }, 250, brokenSetTimeout)
    })

    it ('setTimeout_safe canceling is working', (done) => {

        const brokenSetTimeout = (done, ms) => setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)<commit_msg>skipping setTimeout_safe test on appveyor<commit_after>/*  ------------------------------------------------------------------------ */

const ccxt     = require ('../../ccxt.js')
    , assert   = require ('assert')
    , log      = require ('ololog')
    , ansi     = require ('ansicolor').nice;

/*  ------------------------------------------------------------------------ */

const chai = require ('chai')
                .use (require ('chai-as-promised'))
                .should ()

/*  ------------------------------------------------------------------------ */

describe ('ccxt base code', () => {

    it ('safeFloat is robust', async () => {

        assert.strictEqual (ccxt.safeFloat ({'float': '1.0'}, 'float'), 1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': '-1.0'}, 'float'), -1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': 1.0}, 'float'), 1.0)
        assert.strictEqual (ccxt.safeFloat ({'float': 0}, 'float'), 0)
        assert.strictEqual (ccxt.safeFloat ({'float': undefined}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({'float': ""}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({'float': ""}, 'float', 0), 0)
        assert.strictEqual (ccxt.safeFloat ({}, 'float'), undefined)
        assert.strictEqual (ccxt.safeFloat ({}, 'float', 0), 0)
    })

    it.skip ('setTimeout_safe is working', (done) => {

        const start = Date.now ()
        const calls = []

        const brokenSetTimeout = (done, ms) => {
            calls.push ({ when: Date.now () - start, ms_asked: ms })
            return setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)
        }

        const approxEquals = (a, b) => Math.abs (a - b) <= 10

        // ask to sleep 250ms
        ccxt.setTimeout_safe (() => {
            assert (approxEquals (calls[0].ms_asked, 250))
            assert (approxEquals (calls[1].ms_asked, 150))
            assert (approxEquals (calls[2].ms_asked, 50))
            done ()
        }, 250, brokenSetTimeout)
    })

    it ('setTimeout_safe canceling is working', (done) => {

        const brokenSetTimeout = (done, ms) => setTimeout (done, 100) // simulates a defect setTimeout implementation that sleeps wrong time (100ms always in this test)
{'fraction_non_alphanumeric': 0.24538945541332177, 'fraction_numerical': 0.021262746799739638, 'mean_word_length': 1.8007290400972054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4851910', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1269, 'n_words': 351}