def test_factorial(self):
        self.assertEqual(math_lib.fact(0), 1)
        self.assertEqual(math_lib.fact(1), 1)
        self.assertEqual(math_lib.fact(5), 120)

        #only defined for positive integers
        self.assertRaises(ValueError, math_lib.fact, 10.5)
        self.assertRaises(ValueError, math_lib.fact, -10)
        self.assertRaises(ValueError, math_lib.fact, -10.5)
예제 #2
0
    def test_fact(self):
        numbers_fact = [
            1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800
        ]
        for i in range(12):
            self.assertEqual(math_lib.fact(i), numbers_fact[i])

        # TESTING ERRORS
        self.assertEqual(math_lib.fact(-1), ValueError)
        self.assertEqual(math_lib.fact(0.1), ValueError)
        self.assertEqual(math_lib.fact(1.5), ValueError)
예제 #3
0
    def test_func_cotan(self):
        self.assertEqual(math_lib.func_cotan(0), ValueError)
        self.assertEqual(math_lib.func_cotan(30), 1.732051)
        self.assertEqual(math_lib.func_cotan(45), 1)
        self.assertEqual(math_lib.func_cotan(90), 0)
        self.assertEqual(math_lib.func_cotan(180), ValueError)

        # TESTING NUMBER
        self.assertEqual(math_lib.func_cotan('a'), ValueError)
        self.assertEqual(math_lib.fact("test"), ValueError)
        self.assertEqual(math_lib.sub("test", "test"), ValueError)
예제 #4
0
def highest_priority_op(result, temp, i):
    if result[i] == '-':
        if ((i - 1) < 0 or not is_float(result[i - 1])) and is_float(
                result[i + 1]):
            temp = -float(result[i + 1])
            replace_binary(result, temp, i)
    if result[i] == '!':
        if is_integer(result[i + 1]) and int(result[i + 1]) >= 0:
            temp = math.fact(int(result[i + 1]))
            replace_binary(result, temp, i)
            i -= 1
        elif not is_integer(result[i + 1]) or int(result[i + 1]) < 0:
            set_err_msg(result, err_msg)
            return 0
    return (i + 1)
예제 #5
0
def calcUnary(a, operator):
    if operator == "!":
        try:
            return math.fact(a)
        except Exception as e:
            return e