Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/main/scala/stdlib/Lists.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -179,5 +197,4 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions.
b.tail should be(res4)
c.tail should be(res5)
}

}
18 changes: 18 additions & 0 deletions src/test/scala/stdlib/ListsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down