Created
November 15, 2014 13:43
-
-
Save tamizhgeek/6e09fbb4d6e448bea213 to your computer and use it in GitHub Desktop.
Tests for bootcamp week-1 list problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import assignments.ListUtils._ | |
import org.scalatest.FlatSpec | |
class ListUtilsTest extends FlatSpec { | |
behavior of "ListUtils" | |
it should "find last of the list" in { | |
assert(findLast(List(1,2,3,4,5)) == 5) | |
assert(findLast(List(1)) == 1) | |
} | |
it should "find len of the list" in { | |
assert(lenCustom(List(1,2,3)) == 3) | |
assert(lenCustom(List(1)) == 1) | |
} | |
it should "find penultimate of the list" in { | |
assert(penultimate(List(1,3,4)) == 3) | |
assert(penultimate(List(1,2)) == 1) | |
} | |
it should "reverse the list" in { | |
assert(reverse(List(1,2,3)) == List(3,2,1)) | |
} | |
it should "remove duplicates in the list" in { | |
assert(removeDuplicates(List(1,1,1,1,2,2,2,1,1,3,3,4,4,1,1,3,3,3,3,6)) == List(1, 2, 1, 3, 4, 1, 3, 6)) | |
} | |
it should "remove every nth element from list" in { | |
assert(drop(2, List(1,2,3,4,5,6,7,8)) == List(1,3,5,7)) | |
assert(drop(2, List(1,2,3,4,5,6,7,8,9)) == List(1,3,5,7,9)) | |
} | |
it should "slice the list from start to end" in { | |
assert(slice(2,4, List(1,2,3,4,5,6,7,8)) == List(3,4)) | |
assert(slice(0,1, List(1,2,3,4,5,6,7,8)) == List(1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could've also used the
ShouldMatchers
that would make the Tests even more elegant and readable. I use assert for boolean conditions alone.