Problem 17
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
import scala.annotation.tailrec
|
||||||
|
|
||||||
|
object Problem17:
|
||||||
|
def splitList(n: Int, list: List[Any]): Tuple2[List[Any],List[Any]] =
|
||||||
|
(Problem18.slice(0, n, list), Problem18.slice(n, list.length, list))
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
class Problem17Suite extends munit.FunSuite:
|
||||||
|
List(
|
||||||
|
((0, List(1, 2, 3, 4)), (List(), List(1, 2, 3, 4))),
|
||||||
|
((1, List(1, 2, 3, 4)), (List(1), List(2, 3, 4))),
|
||||||
|
((2, List(1, 2, 3, 4)), (List(1, 2), List(3, 4))),
|
||||||
|
((3, List(1, 2, 3, 4)), (List(1, 2, 3), List(4))),
|
||||||
|
((4, List(1, 2, 3, 4)), (List(1, 2, 3, 4), List())),
|
||||||
|
).foreach:
|
||||||
|
case ((firstPartlength, list), expected) =>
|
||||||
|
test(s"splitList returns [$expected]"):
|
||||||
|
assertEquals(Problem17.splitList(firstPartlength, list), expected)
|
||||||
Reference in New Issue
Block a user