forked from reingart/exercism
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcollatz_conjecture_test.py
35 lines (26 loc) · 1.14 KB
/
collatz_conjecture_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/collatz-conjecture/canonical-data.json
# File last updated on 2023-07-20
import unittest
from collatz_conjecture import (
steps,
)
class CollatzConjectureTest(unittest.TestCase):
def test_zero_steps_for_one(self):
self.assertEqual(steps(1), 0)
def test_divide_if_even(self):
self.assertEqual(steps(16), 4)
def test_even_and_odd_steps(self):
self.assertEqual(steps(12), 9)
def test_large_number_of_even_and_odd_steps(self):
self.assertEqual(steps(1000000), 152)
def test_zero_is_an_error(self):
with self.assertRaises(ValueError) as err:
steps(0)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Only positive integers are allowed")
def test_negative_value_is_an_error(self):
with self.assertRaises(ValueError) as err:
steps(-15)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Only positive integers are allowed")