def test_factorial_returns_correct_value_for_an_integer(self): math_object = MathFunctions.MathFunction() self.assertEqual(1, math_object.factorial(1)) self.assertEqual(2, math_object.factorial(2)) self.assertEqual(120, math_object.factorial(5)) self.assertEqual(3628800, math_object.factorial(10)) self.assertEqual(1, math_object.factorial(0))
def find_permutations(self, string): math_object = MathFunctions.MathFunction() array_permutations = [] len_of_string = len(string) if len_of_string >= 3: for char_start in string: end_string = string.replace(char_start, "") end_string_permutations = self.find_permutations(end_string) for i in range(0, math_object.factorial(len(end_string))): array_permutations.append(char_start + end_string_permutations[i]) if len_of_string == 2: array_permutations.append(string[0] + string[1]) array_permutations.append(string[1] + string[0]) if len_of_string == 1: array_permutations.append(string) return sorted(array_permutations)
def test_sum_of_individual_digits_for_an_integer_is_correct_value(self): math_object = MathFunctions.MathFunction() self.assertEqual(9, math_object.add_each_digit(540)) self.assertEqual(27, math_object.add_each_digit(3628800))