Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created June 1, 2010 01:29
Show Gist options
  • Save jamescarr/420451 to your computer and use it in GitHub Desktop.
Save jamescarr/420451 to your computer and use it in GitHub Desktop.
FactorialSpec.scala:
import org.specs._
class FactorialSpec extends Specification{
"polynomial" should {
"return 1 for n = 1" in {
Factorial(1) must be (1)
}
"return 2 for n = 2" in {
Factorial(2) must be (2*1)
}
"return 6 for n = 3" in {
Factorial(3) must be (3*2*1)
}
"return 6*5*4*3*2*1 for n = 6" in {
Factorial(6) must be (6*5*4*3*2*1)
}
"handle large factorial" in {
Factorial(10) must be(3628800)
}
}
}
Factorial.scala:
object Factorial extends (Int => Int){
override def apply(n:Int) = (1 to n).foldRight(1)(_ * _)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment