Last active
February 27, 2018 12:56
Revisions
-
vasily-kirichenko revised this gist
Feb 27, 2018 . 1 changed file with 10 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,16 +11,17 @@ def sortedKeyList(xs: List[List[Person]]) = { } } 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) } } -
vasily-kirichenko created this gist
Feb 27, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ 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 } } def `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")) data.foreach { case (a, b, res) => sortedKeyList(List(people(a), people(b))).equals(res) } }