Problem 23
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
import scala.util.Random
|
||||||
|
|
||||||
|
object Problem23:
|
||||||
|
def randomSelect(n: Int, list: List[Any]): List[Any] =
|
||||||
|
Problem18.slice(0, n, Random.shuffle(list))
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package ninetyNineScalaProblems
|
||||||
|
|
||||||
|
class Problem23Suite extends munit.FunSuite:
|
||||||
|
List(
|
||||||
|
((1, List(1)), 1),
|
||||||
|
((0, List()), 0),
|
||||||
|
((0, List(1)), 0),
|
||||||
|
((0, List(1, 2, 3, 4, 5)), 0),
|
||||||
|
((3, List(1, 2, 3, 4, 5)), 3),
|
||||||
|
).foreach:
|
||||||
|
case ((n, list), expectedLength) =>
|
||||||
|
test(s"randomSelect returns [$expectedLength]"):
|
||||||
|
assertEquals(Problem23.randomSelect(n, list).length, expectedLength)
|
||||||
Reference in New Issue
Block a user