def calcular(msg): #default message is "<metodo> <op1> <op2>" campos = msg.split(" ") if campos[0] == "add": try: resp = operations.add(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "sub": try: resp = operations.sub(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "mpy": try: resp = operations.mpy(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "div": try: resp = operations.div(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "pot": try: resp = operations.pot(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "mod": try: resp = operations.mod(campos[1], campos[2]) except IndexError: resp = "Error: the message isn't correct" pass elif campos[0] == "sqrt": try: resp = operations.sqrt(campos[1]) except IndexError: resp = "Error: the message isn't correct" pass else: resp = "Error: informed method unknown" pass return resp
import operations as ops import fit import exptree import random import functools import itertools x = sympy.symbols('x') ''' Note: prototype functions CAN NOT use ci (for int i) constant names''' j, k, l, m, n, o, p = sympy.symbols('j k l m n o p') '''List of function prototypes and their constants''' basic_functions = [x, x**2, ops.sqrt(x + j), ops.log(x + k), ops.exp(x*l), ops.sin(x*m +n), ops.atan(x*o + p)] def cross_multiply(l, k): '''Given a list, return a list of all possible product combinations (Up to k) ''' result = l for i in range(2, k + 1): if i > len(l): break combos = list(itertools.combinations(l, i)) for j in range(0, len(combos)): combos[j] = functools.reduce(lambda x, y: x*y, combos[j]) result = result + combos
def test_sqrt_minus_1(): assert sqrt(-1) == "error"
def test_sqrt_0(): assert sqrt(0) == 0
def test_sqrt_4(): assert sqrt(4) == 2
def test_sqrt_1(): assert sqrt(1) == 1
def test_sqrt_1(x, y): assert sqrt(x) == y