import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
sys.path.append(root)

# ----------------------------------------------------------------------------

# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

# ----------------------------------------------------------------------------
# -*- coding: utf-8 -*-

import ccxt  # noqa: F402

def equals(a, b):
    return a == b

def test_safe_methods():
    exchange = ccxt.Exchange({
        'id': 'regirock',
    })
    input_dict = {
        'i': 1,
        'f': 0.123,
        'bool': True,
        'list': [1, 2, 3],
        'dict': {
            'a': 1,
        },
        'str': 'heLlo',
        'strNumber': '3',
        'zeroNumeric': 0,
        'zeroString': '0',
        'undefined': None,
        'emptyString': '',
        'floatNumeric': 0.123,
        'floatString': '0.123',
    }
    input_list = ['Hi', 2]
    compare_dict = {
        'a': 1,
    }
    compare_list = [1, 2, 3]
    factor = 10
    # safeValue
    assert exchange.safe_value(input_dict, 'i') == 1
    assert exchange.safe_value(input_dict, 'f') == 0.123
    assert exchange.safe_value(input_dict, 'bool')
    assert equals(exchange.safe_value(input_dict, 'list'), compare_list)
    dict_object = exchange.safe_value(input_dict, 'dict')
    assert equals(dict_object, compare_dict)
    assert exchange.safe_value(input_dict, 'str') == 'heLlo'
    assert exchange.safe_value(input_dict, 'strNumber') == '3'
    assert exchange.safe_value(input_list, 0) == 'Hi'
    # safeValue2
    assert exchange.safe_value_2(input_dict, 'a', 'i') == 1
    assert exchange.safe_value_2(input_dict, 'a', 'f') == 0.123
    assert exchange.safe_value_2(input_dict, 'a', 'bool')
    assert equals(exchange.safe_value_2(input_dict, 'a', 'list'), compare_list)
    dict_object = exchange.safe_value_2(input_dict, 'a', 'dict')
    assert equals(dict_object, compare_dict)
    assert exchange.safe_value_2(input_dict, 'a', 'str') == 'heLlo'
    assert exchange.safe_value_2(input_dict, 'a', 'strNumber') == '3'
    assert exchange.safe_value_2(input_list, 2, 0) == 'Hi'
    # safeValueN
    assert exchange.safe_value_n(input_dict, ['a', 'b', 'i']) == 1
    assert exchange.safe_value_n(input_dict, ['a', 'b', 'f']) == 0.123
    assert exchange.safe_value_n(input_dict, ['a', 'b', 'bool'])
    assert equals(exchange.safe_value_n(input_dict, ['a', 'b', 'list']), compare_list)
    dict_object = exchange.safe_value_n(input_dict, ['a', 'b', 'dict'])
    assert equals(dict_object, compare_dict)
    assert exchange.safe_value_n(input_dict, ['a', 'b', 'str']) == 'heLlo'
    assert exchange.safe_value_n(input_dict, ['a', 'b', 'strNumber']) == '3'
    assert exchange.safe_value_n(input_list, [3, 2, 0]) == 'Hi'
    # safeDict
    dict_object = exchange.safe_dict(input_dict, 'dict')
    assert equals(dict_object, compare_dict)
    list_object = exchange.safe_dict(input_dict, 'list')
    assert list_object is None
    assert exchange.safe_dict(input_list, 1) is None
    # safeDict2
    dict_object = exchange.safe_dict_2(input_dict, 'a', 'dict')
    assert equals(dict_object, compare_dict)
    list_object = exchange.safe_dict_2(input_dict, 'a', 'list')
    assert list_object is None
    # @ts-expect-error
    assert exchange.safe_dict_2(input_list, 2, 1) is None
    # safeDictN
    dict_object = exchange.safe_dict_n(input_dict, ['a', 'b', 'dict'])
    assert equals(dict_object, compare_dict)
    list_object = exchange.safe_dict_n(input_dict, ['a', 'b', 'list'])
    assert list_object is None
    assert exchange.safe_dict_n(input_list, [3, 2, 1]) is None
    # safeList
    list_object = exchange.safe_list(input_dict, 'list')
    assert equals(dict_object, compare_dict)
    assert exchange.safe_list(input_dict, 'dict') is None
    assert exchange.safe_list(input_list, 1) is None
    # safeList2
    list_object = exchange.safe_list_2(input_dict, 'a', 'list')
    assert equals(dict_object, compare_dict)
    assert exchange.safe_list_2(input_dict, 'a', 'dict') is None
    # @ts-expect-error
    assert exchange.safe_list_2(input_list, 2, 1) is None
    # safeListN
    list_object = exchange.safe_list_n(input_dict, ['a', 'b', 'list'])
    assert equals(dict_object, compare_dict)
    assert exchange.safe_list_n(input_dict, ['a', 'b', 'dict']) is None
    assert exchange.safe_list_n(input_list, [3, 2, 1]) is None
    # safeString
    assert exchange.safe_string(input_dict, 'i') == '1'
    assert exchange.safe_string(input_dict, 'f') == '0.123'
    # assert (exchange.safeString (inputDict, 'bool') === 'true'); returns True in python and 'true' in js
    assert exchange.safe_string(input_dict, 'str') == 'heLlo'
    assert exchange.safe_string(input_dict, 'strNumber') == '3'
    assert exchange.safe_string(input_list, 0) == 'Hi'
    # safeString2
    assert exchange.safe_string_2(input_dict, 'a', 'i') == '1'
    assert exchange.safe_string_2(input_dict, 'a', 'f') == '0.123'
    assert exchange.safe_string_2(input_dict, 'a', 'str') == 'heLlo'
    assert exchange.safe_string_2(input_dict, 'a', 'strNumber') == '3'
    assert exchange.safe_string_2(input_list, 2, 0) == 'Hi'
    # safeStringN
    assert exchange.safe_string_n(input_dict, ['a', 'b', 'i']) == '1'
    assert exchange.safe_string_n(input_dict, ['a', 'b', 'f']) == '0.123'
    assert exchange.safe_string_n(input_dict, ['a', 'b', 'str']) == 'heLlo'
    assert exchange.safe_string_n(input_dict, ['a', 'b', 'strNumber']) == '3'
    assert exchange.safe_string_n(input_list, [3, 2, 0]) == 'Hi'
    # safeStringLower
    assert exchange.safe_string_lower(input_dict, 'i') == '1'
    assert exchange.safe_string_lower(input_dict, 'f') == '0.123'
    assert exchange.safe_string_lower(input_dict, 'str') == 'hello'
    assert exchange.safe_string_lower(input_dict, 'strNumber') == '3'
    assert exchange.safe_string_lower(input_list, 0) == 'hi'
    # safeStringLower2
    assert exchange.safe_string_lower_2(input_dict, 'a', 'i') == '1'
    assert exchange.safe_string_lower_2(input_dict, 'a', 'f') == '0.123'
    assert exchange.safe_string_lower_2(input_dict, 'a', 'str') == 'hello'
    assert exchange.safe_string_lower_2(input_dict, 'a', 'strNumber') == '3'
    assert exchange.safe_string_lower_2(input_list, 2, 0) == 'hi'
    # safeStringLowerN
    assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'i']) == '1'
    assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'f']) == '0.123'
    assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'str']) == 'hello'
    assert exchange.safe_string_lower_n(input_dict, ['a', 'b', 'strNumber']) == '3'
    assert exchange.safe_string_lower_n(input_list, [3, 2, 0]) == 'hi'
    # safeStringUpper
    assert exchange.safe_string_upper(input_dict, 'i') == '1'
    assert exchange.safe_string_upper(input_dict, 'f') == '0.123'
    assert exchange.safe_string_upper(input_dict, 'str') == 'HELLO'
    assert exchange.safe_string_upper(input_dict, 'strNumber') == '3'
    assert exchange.safe_string_upper(input_list, 0) == 'HI'
    # safeStringUpper2
    assert exchange.safe_string_upper_2(input_dict, 'a', 'i') == '1'
    assert exchange.safe_string_upper_2(input_dict, 'a', 'f') == '0.123'
    assert exchange.safe_string_upper_2(input_dict, 'a', 'str') == 'HELLO'
    assert exchange.safe_string_upper_2(input_dict, 'a', 'strNumber') == '3'
    assert exchange.safe_string_upper_2(input_list, 2, 0) == 'HI'
    # safeStringUpperN
    assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'i']) == '1'
    assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'f']) == '0.123'
    assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'str']) == 'HELLO'
    assert exchange.safe_string_upper_n(input_dict, ['a', 'b', 'strNumber']) == '3'
    assert exchange.safe_string_upper_n(input_list, [3, 2, 0]) == 'HI'
    # safeInteger
    assert exchange.safe_integer(input_dict, 'i') == 1
    assert exchange.safe_integer(input_dict, 'f') == 0
    assert exchange.safe_integer(input_dict, 'strNumber') == 3
    assert exchange.safe_integer(input_list, 1) == 2
    # safeInteger2
    assert exchange.safe_integer_2(input_dict, 'a', 'i') == 1
    assert exchange.safe_integer_2(input_dict, 'a', 'f') == 0
    assert exchange.safe_integer_2(input_dict, 'a', 'strNumber') == 3
    assert exchange.safe_integer_2(input_list, 2, 1) == 2
    # safeIntegerN
    assert exchange.safe_integer_n(input_dict, ['a', 'b', 'i']) == 1
    assert exchange.safe_integer_n(input_dict, ['a', 'b', 'f']) == 0
    assert exchange.safe_integer_n(input_dict, ['a', 'b', 'strNumber']) == 3
    assert exchange.safe_integer_n(input_list, [3, 2, 1]) == 2
    # safeIntegerOmitZero
    assert exchange.safe_integer_omit_zero(input_dict, 'i') == 1
    assert exchange.safe_integer_omit_zero(input_dict, 'f') is None
    assert exchange.safe_integer_omit_zero(input_dict, 'strNumber') == 3
    assert exchange.safe_integer_omit_zero(input_list, 1) == 2
    # safeIntegerProduct
    assert exchange.safe_integer_product(input_dict, 'i', factor) == 10
    assert exchange.safe_integer_product(input_dict, 'f', factor) == 1  # NB the result is 1
    assert exchange.safe_integer_product(input_dict, 'strNumber', factor) == 30
    assert exchange.safe_integer_product(input_list, 1, factor) == 20
    # safeIntegerProduct2
    assert exchange.safe_integer_product_2(input_dict, 'a', 'i', factor) == 10
    assert exchange.safe_integer_product_2(input_dict, 'a', 'f', factor) == 1  # NB the result is 1
    assert exchange.safe_integer_product_2(input_dict, 'a', 'strNumber', factor) == 30
    assert exchange.safe_integer_product_2(input_list, 2, 1, factor) == 20
    # safeIntegerProductN
    assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'i'], factor) == 10
    assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'f'], factor) == 1  # NB the result is 1
    assert exchange.safe_integer_product_n(input_dict, ['a', 'b', 'strNumber'], factor) == 30
    assert exchange.safe_integer_product_n(input_list, [3, 2, 1], factor) == 20
    # safeTimestamp
    assert exchange.safe_timestamp(input_dict, 'i') == 1000
    assert exchange.safe_timestamp(input_dict, 'f') == 123
    assert exchange.safe_timestamp(input_dict, 'strNumber') == 3000
    assert exchange.safe_timestamp(input_list, 1) == 2000
    # safeTimestamp2
    assert exchange.safe_timestamp_2(input_dict, 'a', 'i') == 1000
    assert exchange.safe_timestamp_2(input_dict, 'a', 'f') == 123
    assert exchange.safe_timestamp_2(input_dict, 'a', 'strNumber') == 3000
    assert exchange.safe_timestamp_2(input_list, 2, 1) == 2000
    # safeTimestampN
    assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'i']) == 1000
    assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'f']) == 123
    assert exchange.safe_timestamp_n(input_dict, ['a', 'b', 'strNumber']) == 3000
    assert exchange.safe_timestamp_n(input_list, [3, 2, 1]) == 2000
    # safeFloat
    # @ts-expect-error
    assert exchange.safe_float(input_dict, 'i') == float(1)
    assert exchange.safe_float(input_dict, 'f') == 0.123
    # @ts-expect-error
    assert exchange.safe_float(input_dict, 'strNumber') == float(3)
    # @ts-expect-error
    assert exchange.safe_float(input_list, 1) == float(2)
    # safeFloat2
    # @ts-expect-error
    assert exchange.safe_float_2(input_dict, 'a', 'i') == float(1)
    assert exchange.safe_float_2(input_dict, 'a', 'f') == 0.123
    # @ts-expect-error
    assert exchange.safe_float_2(input_dict, 'a', 'strNumber') == float(3)
    # @ts-expect-error
    assert exchange.safe_float_2(input_list, 2, 1) == float(2)
    # safeFloatN
    # @ts-expect-error
    assert exchange.safe_float_n(input_dict, ['a', 'b', 'i']) == float(1)
    assert exchange.safe_float_n(input_dict, ['a', 'b', 'f']) == 0.123
    # @ts-expect-error
    assert exchange.safe_float_n(input_dict, ['a', 'b', 'strNumber']) == float(3)
    # @ts-expect-error
    assert exchange.safe_float_n(input_list, [3, 2, 1]) == float(2)
    # safeNumber
    assert exchange.safe_number(input_dict, 'i') == exchange.parse_number(1)
    assert exchange.safe_number(input_dict, 'f') == exchange.parse_number(0.123)
    assert exchange.safe_number(input_dict, 'strNumber') == exchange.parse_number(3)
    assert exchange.safe_number(input_list, 1) == exchange.parse_number(2)
    assert exchange.safe_number(input_list, 'bool') is None
    assert exchange.safe_number(input_list, 'list') is None
    assert exchange.safe_number(input_list, 'dict') is None
    assert exchange.safe_number(input_list, 'str') is None
    # safeNumber2
    assert exchange.safe_number_2(input_dict, 'a', 'i') == exchange.parse_number(1)
    assert exchange.safe_number_2(input_dict, 'a', 'f') == exchange.parse_number(0.123)
    assert exchange.safe_number_2(input_dict, 'a', 'strNumber') == exchange.parse_number(3)
    assert exchange.safe_number_2(input_list, 2, 1) == exchange.parse_number(2)
    # safeNumberN
    assert exchange.safe_number_n(input_dict, ['a', 'b', 'i']) == exchange.parse_number(1)
    assert exchange.safe_number_n(input_dict, ['a', 'b', 'f']) == exchange.parse_number(0.123)
    assert exchange.safe_number_n(input_dict, ['a', 'b', 'strNumber']) == exchange.parse_number(3)
    assert exchange.safe_number_n(input_list, [3, 2, 1]) == exchange.parse_number(2)
    # safeBool
    assert exchange.safe_bool(input_dict, 'bool')
    assert exchange.safe_bool(input_list, 1) is None
    # safeBool2
    assert exchange.safe_bool_2(input_dict, 'a', 'bool')
    assert exchange.safe_bool_2(input_list, 2, 1) is None
    # safeBoolN
    assert exchange.safe_bool_n(input_dict, ['a', 'b', 'bool'])
    assert exchange.safe_bool_n(input_list, [3, 2, 1]) is None
    # safeNumberOmitZero
    assert exchange.safe_number_omit_zero(input_dict, 'zeroNumeric') is None
    assert exchange.safe_number_omit_zero(input_dict, 'zeroString') is None
    assert exchange.safe_number_omit_zero(input_dict, 'undefined') is None
    assert exchange.safe_number_omit_zero(input_dict, 'emptyString') is None
    assert exchange.safe_number_omit_zero(input_dict, 'floatNumeric') is not None
    assert exchange.safe_number_omit_zero(input_dict, 'floatString') is not None
