def SSE(dp, var, equ): if !checkDPFormat(dp): print "ERROR: invalid dotplot (dp) format in SSE" return -1 if !calc.checkVarFormat(var): print "ERROR: invalid var format in SSE" return -2 if 'x' not in equ: print "ERROR: must have x in equ. in SSE" return -3 r = 0 for i in dp: var["x"] = i[0] r += (i[1] - calc.solve(var, equ)) ** 2 return r
def test_calc(expr: str, result: str): assert solve(expr) == result
def test_exception_not_found(expr: str): with pytest.raises(AssertionError): solve(expr)
def test_solve_5(): assert solve([ 25, 4, '*', 3, '*', 10, '/', 5, 6, '*', 3, '/', 4, '*', '-', 10, 11, '*', 12, '*', 15, '/', '+' ]) == 78
def test_solve_4(): assert solve([1, 2, '*', 3, '*', 4, '*', 5, '*']) == 120
def test_solve_3(): assert solve([45, 5, '-']) == 40
def test_solve_1(): assert solve([45, 5, '+']) == 50
def test_solve_0(): assert solve([45, 5, 9, '*', '-', 6, 2, '/', '+']) == 3