Created
August 14, 2019 13:02
-
-
Save gatarelib/7c9e9d537ae5b464dcd379a5411b2e6d to your computer and use it in GitHub Desktop.
Andela - Python D2 Software Developer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def splitInteger(num,parts): | |
quotient, remainder = divmod(num, parts) | |
lower_elements = [quotient] * (parts - remainder) | |
higher_elements = [quotient + 1] * remainder | |
return lower_elements + higher_elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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