old_contents: from sys     import argv
  from decimal import Decimal
  from Formula import calculatePurchaseReturn
  
  
  def formulaTest(_supply, _reserveBalance, _reserveRatio, _amount):
      fixed = calculatePurchaseReturn(_supply, _reserveBalance, _reserveRatio, _amount)
      real  = Decimal(_supply)*((1+Decimal(_amount)/Decimal(_reserveBalance))**(Decimal(_reserveRatio)/100)-1)
      if fixed > real:
          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))
          error.append('fixed result    = {}'.format(fixed))
          error.append('real  result    = {}'.format(real))
          raise BaseException('\n'.join(error))
      return float(fixed / real)
  
  
  size = int(argv[1]) if len(argv) > 1 else 0
  if size == 0:
      size = input('How many test-cases would you like to execute? ')
  
  
  bgn = 10**14
  end = 10**23
  gap = (end-bgn)/size
  
  
  n = 0
  worstAccuracy = 1
  numOfFailures = 0
  while n < size: # avoid creating a large range in memory
      _supply         = 10**26
      _reserveBalance = 10**23
      _reserveRatio   = 10
      _amount         = bgn+gap*n
      try:
          accuracy = formulaTest(_supply, _reserveBalance, _reserveRatio, _amount)
          worstAccuracy = min(worstAccuracy,accuracy)
      except Exception,error:
          accuracy = 0
          numOfFailures += 1
      except BaseException,error:
          print error
          break
      print 'Test #{}: amount = {:23d}, accuracy = {:.12f}, worst accuracy = {:.12f}, num of failures = {}'.format(n,_amount,accuracy,worstAccuracy,numOfFailures)
      n += 1
  
new_contents: from sys     import argv
  from decimal import Decimal
  from Formula import calculatePurchaseReturn
  
  
  def formulaTest(supply,reserve,ratio,amount):
      fixed = Decimal(calculatePurchaseReturn(supply,reserve,ratio,amount))
      real  = Decimal(supply)*((1+Decimal(amount)/Decimal(reserve))**(Decimal(ratio)/100)-1)
      if fixed > real:
          error = []
          error.append('error occurred on:')
          error.append('supply  = {}'.format(supply))
          error.append('reserve = {}'.format(reserve))
          error.append('ratio   = {}'.format(ratio))
          error.append('amount  = {}'.format(amount))
          error.append('fixed   = {}'.format(fixed))
          error.append('real    = {}'.format(real))
          raise BaseException('\n'.join(error))
      return fixed/real
  
  
  size = int(argv[1]) if len(argv) > 1 else 0
  if size == 0:
      size = input('How many test-cases would you like to execute? ')
  
  
  bgn = 10**14
  end = 10**23
  gap = (end-bgn)/size
  
  
  n = 0
  worstAccuracy = 1
  numOfFailures = 0
  while n < size: # avoid creating a large range in memory
      supply  = 10**26
      reserve = 10**23
      ratio   = 10
      amount  = bgn+gap*n
      try:
          accuracy = formulaTest(supply,reserve,ratio,amount)
          worstAccuracy = min(worstAccuracy,accuracy)
      except Exception,error:
          accuracy = 0
          numOfFailures += 1
      except BaseException,error:
          print error
          break
      print 'Test #{}: amount = {:23d}, accuracy = {:.12f}, worst accuracy = {:.12f}, num of failures = {}'.format(n,amount,accuracy,worstAccuracy,numOfFailures)
      n += 1
  
subject: Update python test