Exemplo n.º 1
0
 def test(self):
     for n, answer in ((2, 1), (3, 1), (5, 3),  (1,0)):
         sequence = compute_operations(n)
         self.assertEqual(answer, len(sequence) - 1)
         self.assertEqual(sequence[0], 1)
         self.assertEqual(sequence[-1], n)
         for i in range(len(sequence) - 1):
             if sequence[i + 1] != sequence[i] + 1 and sequence[i + 1] != 2 * sequence[i]:
                 self.assertEqual(sequence[i + 1], 3 * sequence[i])
 def test(self):
     for n, answer in (
         (2, 1),
         (3, 1),
         (5, 3),
     ):
         print(n)
         sequence = compute_operations(n)
         print('check length')
         self.assertEqual(answer, len(sequence) - 1)
         print('check first value')
         self.assertEqual(sequence[0], 1)
         print('check last value')
         self.assertEqual(sequence[-1], n)
         print('check order')
         for i in range(len(sequence) - 1):
             if sequence[i + 1] != sequence[i] + 1 and sequence[
                     i + 1] != 2 * sequence[i]:
                 self.assertEqual(sequence[i + 1], 3 * sequence[i])
Exemplo n.º 3
0
from test_helper import run_common_tests, failed, passed, check_tests_pass
from primitive_calculator import compute_operations

if __name__ == '__main__':
    run_common_tests()
    check_tests_pass("primitive_calculator_unit_tests.py")

    all_tests_passed = True

    for n, answer in ((20, 4), (200, 8), (239, 10), (69006, 19)):
        sequence = compute_operations(n)
        if len(sequence) - 1 != answer:
            all_tests_passed = False
            failed("Wrong answer for n={}".format(n))
            break

    if all_tests_passed:
        passed()