-
Write a
partition
method that takes alist
andsize
parameters and returns a list of sublists, where each sublist has at mostsize
elements.Example inputs and outputs:
- Example 1:
partition([1,2,3,4,5], 2)
returns:[ [1,2], [3,4], [5] ]
- Example 2:
partition([1,2,3,4,5], 3)
returns:[ [1,2,3], [4,5] ]
- Example 3:
partition([1,2,3,4,5], 1)
returns:[ [1], [2], [3], [4], [5] ]
- Example 1:
-
Write unit tests using JUnit4 to verify your implementation.
Important: Assume that your implementation will be part of a library used by many applications (in production).