示例#1
0
 def test_service(self):
     self.assertEquals(float(cmd.execute_microservice(1, 2, "div.py")), 0.5)
     self.assertEquals(float(cmd.execute_microservice(10, 2, "div.py")), 5)
     self.assertIn("cannot divide by zero",
                   str(cmd.execute_microservice(1, 0, "div.py")))
     self.assertIn("NaN",
                   str(cmd.execute_microservice("dd", "ddd", "div.py")))
 def test_service(self):
     self.assertEqual(float(cmd.execute_microservice(1, 2, "plus.py")), 3)
     self.assertEqual(float(cmd.execute_microservice(0, 1, "plus.py")), 1)
     self.assertIn("not enough args",
                   str(cmd.execute_microservice("", "1", "plus.py")))
     self.assertIn("NaN",
                   str(cmd.execute_microservice("da", "1", "plus.py")))
 def test_service(self):
     self.assertEquals(float(cmd.execute_microservice(1, 2, "minus.py")),
                       -1)
     self.assertEquals(float(cmd.execute_microservice(5, 3, "minus.py")), 2)
     self.assertIn("NaN",
                   str(cmd.execute_microservice("rrr", "ff", "minus.py")))
     self.assertIn("not enough args",
                   str(cmd.execute_microservice("", 2, "minus.py")))
def mult(a, b):
    c = 0
    if (b < 0):
        a = float(execute_microservice(0, a, minus))
        b = float(execute_microservice(0, b, minus))
    for _ in range(int(b)):
        c = float(execute_microservice(c, a, plus))
    return c
示例#5
0
 def test_service(self):
     self.assertAlmostEqual(float(
         cmd.execute_microservice(1, 2, "bisection_method.py")),
                            2**0.5,
                            delta=epsilon)
     self.assertAlmostEqual(float(
         cmd.execute_microservice("", "2", "bisection_method.py")),
                            2**0.5,
                            delta=epsilon)
 def test_service(self):
     self.assertEquals(float(cmd.execute_microservice(11, 3, "modulo.py")),
                       2)
     self.assertEquals(float(cmd.execute_microservice(5, 2, "modulo.py")),
                       1)
     self.assertEquals(float(cmd.execute_microservice(1, 2, "modulo.py")),
                       1)
     self.assertIn("cannot modulo by zero",
                   str(cmd.execute_microservice(0, 0, "modulo.py")))
     self.assertIn("NaN",
                   str(cmd.execute_microservice("e", "z", "modulo.py")))
示例#7
0
 def test_service(self):
     self.assertEqual(
         float(cmd.execute_microservice(5, 5, "multWithPlus.py")), 25)
     self.assertEqual(
         float(cmd.execute_microservice(6, -1, "multWithPlus.py")), -6)
     self.assertIn(
         "<b> not Integer",
         str(cmd.execute_microservice(-1.5, 1.5, "multWithPlus.py")))
     self.assertEqual(
         float(cmd.execute_microservice(10, 0, "multWithPlus.py")), 0)
     self.assertEqual(
         float(cmd.execute_microservice(-10.5, 3, "multWithPlus.py")),
         -31.5)
示例#8
0
def bisection_method(aX, bX, f, epsilon=10**-4):
    if (f(aX) * f(bX) > 0):
        return "Error! f(a) and f(b) don't have opposite signs"
    num_iteration = optimal_iteration(aX, bX, epsilon)
    count = 0
    p = float(cmd.execute_microservice(aX, bX, "plus.py"))
    mX = float(cmd.execute_microservice(p, 2, "div.py"))
    while (count < num_iteration and abs(f(mX)) > epsilon):
        if (f(aX) * f(mX) < 0):
            bX = mX
        else:
            aX = mX
        count += 1
        mX = (aX + bX) / 2.0
    return str(mX)
def service():
    param = getParam()
    if isinstance(param, str): return param
    a, b = param
    if (abs(float(execute_microservice(b, int(b), minus))) > 0):
        return "<b> not Integer"
    return mult(a, b)
def secant_method(f, x0, x1, epsilon=10**-4, nMax=100):
    n = 1
    while n <= nMax:
        temp1 = float(cmd.execute_microservice(f(x1), f(x0), minusService))
        x2 = x1 - f(x1) * ((x1 - x0) / temp1)
        if (abs(f(x2)) < epsilon):
            return x2
        else:
            x0 = x1
            x1 = x2
    return False
示例#11
0
 def test_service(self):
     self.assertEqual(float(cmd.execute_microservice(5, 5, "mult.py")), 25)
     self.assertEqual(float(cmd.execute_microservice(6, -1, "mult.py")), -6)
     self.assertEqual(float(cmd.execute_microservice(-1.5, 1.5, "mult.py")),
                      -2.25)
     self.assertEqual(float(cmd.execute_microservice(10, 0, "mult.py")), 0)