Sha256: 29ce451074465912262def08488057b071b8b615766e983369941e78c0d2b37a

Contents?: true

Size: 1.14 KB

Versions: 52

Compression:

Stored size: 1.14 KB

Contents

import unittest

from collatz_conjecture import collatz_steps


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0

class CollatzConjectureTests(unittest.TestCase):

    def test_zero_steps_for_one(self):
        self.assertEqual(collatz_steps(1), 0)

    def test_divide_if_even(self):
        self.assertEqual(collatz_steps(16), 4)

    def test_even_and_odd_steps(self):
        self.assertEqual(collatz_steps(12), 9)

    def test_large_number_of_even_and_odd_steps(self):
        self.assertEqual(collatz_steps(1000000), 152)

    def test_zero_is_invalid_input(self):
        with self.assertRaisesWithMessage(ValueError):
            collatz_steps(0)

    def test_negative_number_is_invalid_input(self):
        with self.assertRaisesWithMessage(ValueError):
            collatz_steps(-15)

    # Utility functions
    def setUp(self):
        try:
            self.assertRaisesRegex
        except AttributeError:
            self.assertRaisesRegex = self.assertRaisesRegexp

    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")


if __name__ == '__main__':
    unittest.main()

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
trackler-2.2.1.140 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.139 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.138 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.137 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.136 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.135 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.134 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.133 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.132 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.131 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.130 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.129 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.128 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.127 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.126 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.125 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.124 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.123 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.122 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.121 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py