Skip to content

Instantly share code, notes, and snippets.

@gatarelib
Created August 14, 2019 13:02
Show Gist options
  • Save gatarelib/7c9e9d537ae5b464dcd379a5411b2e6d to your computer and use it in GitHub Desktop.
Save gatarelib/7c9e9d537ae5b464dcd379a5411b2e6d to your computer and use it in GitHub Desktop.
Andela - Python D2 Software Developer
def splitInteger(num,parts):
quotient, remainder = divmod(num, parts)
lower_elements = [quotient] * (parts - remainder)
higher_elements = [quotient + 1] * remainder
return lower_elements + higher_elements
import unittest
class Test(unittest.TestCase):
def test_should_handle_evenly_distributed_cases(self):
self.assertEqual(splitInteger(10, 1), [10])
self.assertEqual(splitInteger(2, 2), [1,1])
self.assertEqual(splitInteger(20, 5), [4,4,4,4,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment