Skip to content

Instantly share code, notes, and snippets.

@MasseGuillaume
Created May 23, 2012 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasseGuillaume/2772931 to your computer and use it in GitHub Desktop.
Save MasseGuillaume/2772931 to your computer and use it in GitHub Desktop.
Scala Kata: Test & Implementation
// source: http://aperiodic.net/phil/scala/s-99/
def isPalindrome[A](in: List[A]):Boolean = in == in.reverse
// source: https://github.com/dadrox/scala.katas (adapted for spec2)
import org.junit._
import org.specs2.matcher._
class NinetyNineScalaProblems extends JUnitMustMatchers {
@test def P06
{
isPalindrome Nil must beTrue
isPalindrome List(1) must beTrue
isPalindrome List(1, 1) must beTrue
isPalindrome List(1, 2, 1) must beTrue
isPalindrome List("Madam, I'm Adam") must beTrue
isPalindrome List("foo", "bar", "foo") must beTrue
isPalindrome List(1, 2) must beFalse
isPalindrome List("foo", "bar", "baz") must beFalse
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment