Created
June 1, 2010 01:29
-
-
Save jamescarr/420451 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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