you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 1 year ago* (last edited 1 year ago) (3 children)

Unittest in Python, enjoy! If you pass it with a function like the one in OPs picture, you have earned it.

import unittest
import random

class TestOddEven(unittest.TestCase):
    def test_is_odd(self):
        for _ in range(100):
            num = random.randint(-2**63, 2**63 - 1)

            odd_num = num | 1
            even_num = num >> 1 << 1

            self.assertTrue(is_odd(odd_num))
            self.assertFalse(is_odd(even_num))

    def test_is_even(self):
        for _ in range(100):
            num = random.randint(-2**63, 2**63 - 1)

            odd_num = num | 1
            even_num = num >> 1 << 1

            self.assertTrue(is_even(even_num))
            self.assertFalse(is_even(odd_num))

if __name__ == '__main__':
    unittest.main()
  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 1 year ago (2 children)

    I don't want unseeded randomness in my tests, ever.

    Seed the tests, and making these pass would be trivial.

  • source
  • parent
  • hideshow 2 child comments