From ef9f68fc3928442270b5d44cb9501d4644aaf6dd Mon Sep 17 00:00:00 2001 From: Rafael Ruiz Date: Tue, 11 Apr 2017 15:24:44 +0200 Subject: [PATCH 1/5] Concatenate and add elements examples for Lists.scala --- src/main/scala/stdlib/Lists.scala | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index 94dd4414..bba0dc5a 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -159,6 +159,30 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. val a = (1 to 5).toList a should be(res0) } + + /** You can add elements to a List and get a new List: + */ + def addElementsLists( + res0: List[Int], + res1: List[Int]) { + val a = List(1, 3, 5, 7) + + 0 :: a should be(res0) + a :: 9 should be(res1) + } + + /** 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: */ @@ -179,5 +203,4 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. b.tail should be(res4) c.tail should be(res5) } - } From 2c7be0e5a32aee4031b18c501bdae9cc7749591e Mon Sep 17 00:00:00 2001 From: Rafael Ruiz Date: Tue, 11 Apr 2017 15:35:50 +0200 Subject: [PATCH 2/5] Update Lists.scala --- src/main/scala/stdlib/Lists.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index bba0dc5a..7c66c49f 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -162,13 +162,10 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. /** You can add elements to a List and get a new List: */ - def addElementsLists( - res0: List[Int], - res1: List[Int]) { + def addElementsLists(res0: List[Int]) { val a = List(1, 3, 5, 7) - 0 :: a should be(res0) - a :: 9 should be(res1) + a :: 9 should be(res0) } /** Lists can be concatened and Nil is an empty List: From 43b0c622814dcfa97318b61c89442c1de1e01e63 Mon Sep 17 00:00:00 2001 From: Rafael Ruiz Date: Tue, 11 Apr 2017 15:42:38 +0200 Subject: [PATCH 3/5] Update Lists.scala I really should download the project and not edit online that often. --- src/main/scala/stdlib/Lists.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index 7c66c49f..00ec4aa9 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -165,7 +165,7 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. def addElementsLists(res0: List[Int]) { val a = List(1, 3, 5, 7) - a :: 9 should be(res0) + 0 :: a should be(res0) } /** Lists can be concatened and Nil is an empty List: From e3af6d2f1a50fe9acab344c7fd05c791ea659d45 Mon Sep 17 00:00:00 2001 From: Rafael Ruiz Date: Tue, 11 Apr 2017 15:45:05 +0200 Subject: [PATCH 4/5] Update Lists.scala --- src/main/scala/stdlib/Lists.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index 00ec4aa9..85be660c 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -160,7 +160,7 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. a should be(res0) } - /** You can add elements to a List and get a new List: + /** You can prepend elements to a List to get a new List: */ def addElementsLists(res0: List[Int]) { val a = List(1, 3, 5, 7) From 4ddc0b654c6090a39f87796f53ad0e6cf15828bd Mon Sep 17 00:00:00 2001 From: yaskier Date: Tue, 11 Apr 2017 17:26:31 +0200 Subject: [PATCH 5/5] edit online feature is the #1 enemy of TDD --- src/main/scala/stdlib/Lists.scala | 7 ++----- src/test/scala/stdlib/ListsSpec.scala | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/scala/stdlib/Lists.scala b/src/main/scala/stdlib/Lists.scala index 85be660c..b9a71295 100644 --- a/src/main/scala/stdlib/Lists.scala +++ b/src/main/scala/stdlib/Lists.scala @@ -159,7 +159,7 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. val a = (1 to 5).toList a should be(res0) } - + /** You can prepend elements to a List to get a new List: */ def addElementsLists(res0: List[Int]) { @@ -170,9 +170,7 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. /** Lists can be concatened and Nil is an empty List: */ - def concatenateLists( - res0: List[Int], - res1: List[Int]) { + def concatenateLists(res0: List[Int], res1: List[Int]) { val head = List(1, 3) val tail = List(5, 7) @@ -180,7 +178,6 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions. head ::: Nil should be(res1) } - /** Lists reuse their tails: */ def reuseTailsLists( 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(