Skip to content

Commit

Permalink
Merge pull request #83 from Yaskier/patch-1
Browse files Browse the repository at this point in the history
Concatenate and add elements examples for Lists.scala
  • Loading branch information
juanpedromoreno committed Apr 11, 2017
2 parents b81f080 + 4ddc0b6 commit 13aa90a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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

0 comments on commit 13aa90a

Please sign in to comment.