diff --git a/main.py b/main.py index b8c6089..fabba48 100644 --- a/main.py +++ b/main.py @@ -4,14 +4,18 @@ def divide_by_one(num): # Is whole number def divide_by_two(num): # Take last digit, divide by two only on that return _get_last_digit(num) % 2 == 0 -def divide_by_three(num): # Sum each digit in number, then check divisibility of that number +def divide_by_three(num): # Sum each digit in number, then checking that sum is divisible by three return _sum_digits(num) % 3 == 0 def divide_by_five(num): # If last digit is a zero or a five return true last_digit = _get_last_digit(num) return last_digit == 0 or last_digit == 5 -def divide_by_nine(num): # Sum each digit in number, then check divisibility of that number +def divide_by_six(num): # Same rules as dividing by three, and ensure original number is even + num_sum = _sum_digits(num) + return num_sum % 3 == 0 and divide_by_two(num) + +def divide_by_nine(num): # Same rules as dividing by three, but checking that sum is divisible by nine return _sum_digits(num) % 9 == 0 def _get_last_digit(num): diff --git a/tests/six_test.py b/tests/six_test.py new file mode 100644 index 0000000..cb507bc --- /dev/null +++ b/tests/six_test.py @@ -0,0 +1,18 @@ +from main import divide_by_six +import unittest + +class TestDivideBySix(unittest.TestCase): + def test_by_1(self): + self.assertFalse(divide_by_six(1)) + def test_by_2(self): + self.assertFalse(divide_by_six(2)) + def test_by_3(self): + self.assertFalse(divide_by_six(3)) + def test_by_6(self): + self.assertTrue(divide_by_six(6)) + def test_by_10(self): + self.assertFalse(divide_by_six(10)) + def test_by_12(self): + self.assertTrue(divide_by_six(12)) + def test_by_362880(self): + self.assertTrue(divide_by_six(362880))