diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index 94dd4414..b9a71295 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -160,6 +160,24 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. a should be(res0) } + /** You can prepend elements to a List to get a new List: + */ + def addElementsLists(res0: List[Int]) { + val a = List(1, 3, 5, 7) + + 0 :: a should be(res0) + } + + /** Lists can be concatened and Nil is an empty List: + */ + def concatenateLists(res0: List[Int], res1: List[Int]) { + val head = List(1, 3) + val tail = List(5, 7) + + head ::: tail should be(res0) + head ::: Nil should be(res1) + } + /** Lists reuse their tails: */ def reuseTailsLists( @@ -179,5 +197,4 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. b.tail should be(res4) c.tail should be(res5) } - } diff --git a/src/test/scala/stdlib/ListsSpec.scala b/src/test/scala/stdlib/ListsSpec.scala index 3e9260e8..a3003547 100644 --- a/src/test/scala/stdlib/ListsSpec.scala +++ b/src/test/scala/stdlib/ListsSpec.scala @@ -129,6 +129,24 @@ class ListsSpec extends Spec with Checkers { ) } + def `add elements` = { + check( + Test.testSuccess( + Lists.addElementsLists _, + List(0, 1, 3, 5, 7) :: HNil + ) + ) + } + + def `concatenate lists` = { + check( + Test.testSuccess( + Lists.concatenateLists _, + List(1, 3, 5, 7) :: List(1, 3) :: HNil + ) + ) + } + def `lists share tails` = { check( Test.testSuccess(