Last active
February 27, 2018 12:56
-
-
Save vasily-kirichenko/1c036d448413ec93a6c2a4ff191a0e2d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class Person(name: String, flag: Boolean) | |
def sortedKeyList(xs: List[List[Person]]) = { | |
xs.flatten | |
.map(_.name) | |
.distinct | |
.sortBy(identity) | |
.mkString(", ") match { | |
case "" => "<none>" | |
case s => s | |
} | |
} | |
class Tests extends FunSuite with Matchers { | |
test("sorted key list") { | |
def people(xs: List[String]) = xs.map(Person(_, flag = true)) | |
val data = List( | |
(Nil, Nil, "<none>"), | |
(List("fred"), List("barney", "wilma"), "barney, fred, wilma"), | |
(List("fred"), Nil, "fred"), | |
(List("fred"), List("fred", "barney"), "barney, fred")) | |
for ((a, b, res) <- data) | |
sortedKeyList(List(people(a), people(b))) should equal(res) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment