Skip to content

unittests

holzkohlengrill edited this page Dec 15, 2023 · 2 revisions
import unittest

def is_prime(x):
    return x == 2 or all([x % 2 != 0] + [x % i != 0 for i in range(3, max(x - 1, 3), 2)])

class TestMagic(unittest.TestCase):
    def test_prime(self):  # each method must start with test
        self.assertTrue(is_prime(5))

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

See also here

Clone this wiki locally