* Corrected small typos around resistor bands. * Due to failing CI, alterations to the test generator script were needed. The generated vs submitted diff now skips the first three lines of the file so that the generation date is not picked up and flagged as needing regeneration. Sadly, a workaround was also needed to prevent Python difflib from noting the difference anyways and producing an empty "false positive" diff. All templates and test files also needed to be altered to ensure that the first three lines of every test file will always be the autogeneration comment and date. Hopefully, this will now stop the CI failures without creating any subtle additional bugs. * Touch up to bowling template. Added back the error raising utility. * Touch up to two-bucket template to add back in error raising utility. [no important files changed]
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# 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")
|