예제 #1
0
def calculate(numbers):
    pr.enable()
    N = len(numbers)
    sequenceSum = 0
    avg = mathlib.div(sum(numbers), N)
    for i in range(N):
        sequenceSum = mathlib.sum(sequenceSum,
                                  mathlib.pow(numbers[i] - avg, 2))
    s = mathlib.root(2, mathlib.mul(mathlib.div(1, N), sequenceSum))
    pr.disable()
예제 #2
0
 def test_mul(self):
     self.assertEqual(mathlib.mul(3, 0), 0)
     self.assertEqual(mathlib.mul(-5, -2), 10)
     self.assertEqual(mathlib.mul(8645, 0), 0)
     self.assertEqual(mathlib.mul(0.5, 0), 0)
     self.assertEqual(mathlib.mul(2, 1.5), 3)
     self.assertEqual(mathlib.mul(32, -1), -32)
예제 #3
0
def result():
    global operation
    global firstNumber
    global numberString
    res = ""
    if operation == "+":
        res = str(
            mathlib.add(float(firstNumber.replace(',', '.')),
                        float(numberString.replace(',', '.'))))
    if operation == "-":
        res = str(
            mathlib.sub(float(firstNumber.replace(',', '.')),
                        float(numberString.replace(',', '.'))))
    if operation == "×":
        res = str(
            mathlib.mul(float(firstNumber.replace(',', '.')),
                        float(numberString.replace(',', '.'))))
    if operation == "÷":
        res = str(
            mathlib.div(float(firstNumber.replace(',', '.')),
                        float(numberString.replace(',', '.'))))
    if operation == "√":
        res = str(
            AdvancedMathFunctions.root(float(numberString.replace(',', '.')),
                                       float(firstNumber.replace(',', '.'))))
    if operation == "^":
        res = str(
            AdvancedMathFunctions.power(float(firstNumber.replace(',', '.')),
                                        float(numberString.replace(',', '.'))))
    if operation == "!":
        res = str(
            AdvancedMathFunctions.factorial(
                float(firstNumber.replace(',', '.'))))
    print(res)
    firstNumber = res
    return res.replace('.', ',')
예제 #4
0
def test_mul_dummy():
    total = mathlib.mul(5, 4)
    assert total == 20
예제 #5
0
 def test_Mul(self):
     """Tests mathlib.mul"""
     self.assertEqual(mathlib.mul(0, 0), 0)
     self.assertEqual(mathlib.mul(1, 6), 6)
     self.assertEqual(mathlib.mul(0, 4), 0)
     self.assertEqual(mathlib.mul(8, 0), 0)
     self.assertEqual(mathlib.mul(8, 5), 40)
     self.assertEqual(mathlib.mul(-5, 5), -25)
     self.assertEqual(mathlib.mul(3, -5), -15)
     self.assertEqual(mathlib.mul(-6, -9), 54)
     self.assertEqual(mathlib.mul(-7, 0), 0)
     self.assertEqual(mathlib.mul(0, -7), 0)
     self.assertEqual(mathlib.mul(self.randFLOAT1, self.randFLOAT2),
                      self.randFLOAT1 * self.randFLOAT2)
     self.assertEqual(mathlib.mul(self.randINT1, self.randINT2),
                      self.randINT1 * self.randINT2)