diff options
Diffstat (limited to 'Scala/example/src/test')
-rw-r--r-- | Scala/example/src/test/scala/example/ListsSuite.scala | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/Scala/example/src/test/scala/example/ListsSuite.scala b/Scala/example/src/test/scala/example/ListsSuite.scala index 4a52667..5973369 100644 --- a/Scala/example/src/test/scala/example/ListsSuite.scala +++ b/Scala/example/src/test/scala/example/ListsSuite.scala @@ -19,7 +19,7 @@ import org.scalatest.junit.JUnitRunner * inside eclipse using the built-in JUnit test runner. * * You have two options for running this test suite: - * + * * - Start the sbt console and run the "test" command * - Right-click this file in eclipse and chose "Run As" - "JUnit Test" */ @@ -47,7 +47,7 @@ class ListsSuite extends FunSuite { * This allows tests to be written in a more readable manner: */ test("one plus one is three?") { - assert(1 + 1 == 3) // This assertion fails! Go ahead and fix it. + assert(1 + 1 == 2) // This assertion fails! Go ahead and fix it. } @@ -72,7 +72,7 @@ class ListsSuite extends FunSuite { * We recommend to always use the `===` equality operator when writing tests. */ test("details why one plus one is not three") { - assert(1 + 1 === 3) // Fix me, please! + assert(1 + 1 === 2) // Fix me, please! } @@ -99,9 +99,9 @@ class ListsSuite extends FunSuite { * Now we finally write some tests for the list functions that have to be * implemented for this assignment. We fist import all members of the * `List` object. - */ + */ import Lists._ - + /** * We only provide two very basic tests for you. Write more tests to make @@ -114,11 +114,45 @@ class ListsSuite extends FunSuite { * however it is recommended to write an individual `test` statement for * every tested aspect of a method. */ + test("sum of a 1 number list") { + assert(sum(List(666)) === 666) + } + test("sum of a few numbers") { assert(sum(List(1,2,0)) === 3) } - + + test("sum of an empty list") { + assert(sum(List()) === 0) + } + + test("sum of a same numbers") { + assert(sum(List(2,2,2,2,2)) === 10) + } + + test("sum of a few positives and negatives numbers") { + assert(sum(List(1,2,0,-3,-8)) === -8) + } + + test("max of a 1 number list") { + assert(max(List(666)) === 666) + } + + test("max of an empty list throws NoSuchElementException") { + intercept[NoSuchElementException] { + max(List()) + } + } + test("max of a few numbers") { assert(max(List(3, 7, 2)) === 7) } + + test("max of negatives numbers") { + assert(max(List(-3, -7, -2, -5)) === -2) + } + + test("max of a few positives and negatives numbers") { + assert(max(List(3, 7, 0, -5)) === 7) + } } |