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.160 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.159 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.158 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.157 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.156 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.155 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.154 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.153 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.152 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.151 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.150 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.149 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.148 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.147 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.146 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.145 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.144 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.143 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.142 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py
trackler-2.2.1.141 tracks/python/exercises/collatz-conjecture/collatz_conjecture_test.py