<commit_before>from sys     import argv
from decimal import Decimal
from random  import randrange
from Formula import calculateSaleReturn
from Formula import calculatePurchaseReturn


def formulaTest(_supply, _reserveBalance, _reserveRatio, _amount):
    _new_amount = calculatePurchaseReturn(_supply, _reserveBalance, _reserveRatio, _amount)
    _old_amount = calculateSaleReturn(_supply+_new_amount, _reserveBalance+_amount, _reserveRatio, _new_amount)	
    if _old_amount > _amount:
        error = []
        error.append('error occurred on:')
        error.append('_supply         = {}'.format(_supply))
        error.append('_reserveBalance = {}'.format(_reserveBalance))
        error.append('_reserveRatio   = {}'.format(_reserveRatio))
        error.append('_amount         = {}'.format(_amount))
        raise BaseException('\n'.join(error))
    return float(Decimal(_old_amount) / Decimal(_amount))


size = int(argv[1]) if len(argv) > 1 else 0
if size == 0:
    size = input('How many test-cases would you like to execute? ')


n = 0
worstGain = 1
while n < size: # avoid creating a large range in memory
    _supply         = randrange(1,10**26)
    _reserveBalance = randrange(1,10**23)
    _reserveRatio   = randrange(1,99)
    _amount         = randrange(1,_supply)
    try:
        gain = formulaTest(_supply, _reserveBalance, _reserveRatio, _amount)
        if worstGain > gain:
            worstGain = gain
        print 'gain = {:.12f}, worst gain = {:.12f}'.format(gain,worstGain)
        n += 1
    except Exception,error:
        pass
    except BaseException,error:
        print error
        break<commit_msg>Add some info to the printouts<commit_after>from sys     import argv
from decimal import Decimal
from random  import randrange
from Formula import calculateSaleReturn
from Formula import calculatePurchaseReturn


def formulaTest(_supply, _reserveBalance, _reserveRatio, _amount):
    _new_amount = calculatePurchaseReturn(_supply, _reserveBalance, _reserveRatio, _amount)
    _old_amount = calculateSaleReturn(_supply+_new_amount, _reserveBalance+_amount, _reserveRatio, _new_amount)
    if _old_amount > _amount:
        error = []
        error.append('error occurred on:')
        error.append('_supply         = {}'.format(_supply))
        error.append('_reserveBalance = {}'.format(_reserveBalance))
        error.append('_reserveRatio   = {}'.format(_reserveRatio))
        error.append('_amount         = {}'.format(_amount))
        raise BaseException('\n'.join(error))
    return float(Decimal(_old_amount) / Decimal(_amount))


size = int(argv[1]) if len(argv) > 1 else 0
if size == 0:
    size = input('How many test-cases would you like to execute? ')


n = 0
worstGain = 1
numOfFailures = 0
while n < size: # avoid creating a large range in memory
    _supply         = randrange(1,10**26)
    _reserveBalance = randrange(1,10**23)
    _reserveRatio   = randrange(1,99)
    _amount         = randrange(1,_supply)
    try:
        gain = formulaTest(_supply, _reserveBalance, _reserveRatio, _amount)
        worstGain = min(worstGain,gain)
    except Exception,error:
        gain = 0
        numOfFailures += 1
    except BaseException,error:
        print error
        break
    print 'Test #{}: gain = {:.12f}, worst gain = {:.12f}, num of failures = {}'.format(n,gain,worstGain,numOfFailures)
    n += 1
{'fraction_non_alphanumeric': 0.1051534107834376, 'fraction_numerical': 0.015787905868334822, 'mean_word_length': 3.316195372750643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4213942', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1039, 'n_words': 257}