def collatz_length(self, n): length = 1 term = n while term != 1: if is_even(term): term = int(term / 2) if term in self.tree: length += self.tree[term] break else: length += 1 else: term = 3 * term + 1 if term in self.tree: length += self.tree[term] break else: length += 1 self.tree[n] = length return length
def test1(): assert is_even(4) == True
def test3(): assert is_even(5) == False
def test2(): assert is_even(3) == False
def test_functions(self): even = 4 odd = 1 self.assertEqual(functions.is_even(even), True) self.assertFalse(functions.is_even(odd), True)
import functions import data # opdracht 2 functions.is_odd(2) functions.is_odd(3) functions.is_even(2) functions.is_even(3) functions.is_palindrome("foo") functions.is_palindrome("foof") print(dir(data)) print(data) # 2 print(f"-----------check lst1 -------------") lst1 = data.lst1 functions.contains_only_ints(lst1) functions.sum_list(lst1) print(f"-----------check lst2 -------------") lst2 = data.lst2 functions.contains_only_ints(data.lst2)
import functions print(functions.is_palindrome("mayam")) print(functions.is_palindrome("apple")) print(functions.is_even(8)) print(functions.is_even(7)) print(functions.is_odd(8)) print(functions.is_odd(7))
else: err_msg(test_Case_msg("3", "is_int()")) if not functions.is_int(True): pass_msg(test_Case_msg("4", "is_int()")) total_passed += 1 else: err_msg(test_Case_msg("4", "is_int()")) # Printing a newline print("") # Testing is_even() function prep_msg("is_even()") if functions.is_even(90): pass_msg(test_Case_msg("1", "is_even()")) total_passed += 1 else: err_msg(test_Case_msg("1", "is_even()")) if not functions.is_even(17999079): pass_msg(test_Case_msg("2", "is_even()")) total_passed += 1 else: err_msg(test_Case_msg("2", "is_even()")) if not functions.is_even(3.14): pass_msg(test_Case_msg("3", "is_even()")) total_passed += 1 else: