turner-townsend-backend-ass.../collatz/test_collatz.py

27 lines
881 B
Python

import pytest
from collatz import CollatzCalculator
def test_calculate_steps_for_1():
calc = CollatzCalculator()
assert calc.calculate_steps(1) == 0
def test_calculate_steps_for_2():
calc = CollatzCalculator()
assert calc.calculate_steps(2) == 2 # 2 -> 1 (even), returns 2 steps
def test_calculate_steps_for_3():
calc = CollatzCalculator()
assert calc.calculate_steps(3) == 8 # 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
def test_calculate_steps_for_6():
calc = CollatzCalculator()
assert calc.calculate_steps(6) == 9 # 6 -> 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
def test_calculate_steps_for_large_number():
calc = CollatzCalculator()
assert calc.calculate_steps(27) == 112
def test_calculate_steps_for_zero_and_negative():
calc = CollatzCalculator()
assert calc.calculate_steps(0) == 0
assert calc.calculate_steps(-5) == 0