-
-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathFibbonacciSpec.scala
42 lines (31 loc) · 1.3 KB
/
FibbonacciSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Others
import org.scalatest.FlatSpec
class FibbonacciSpec extends FlatSpec {
"recursive solution" should "start from 1" in {
assert(Fibbonacci.nthNumberRecursive(0) === 1)
}
it should "calculate some fibbonacci number" in {
assert(Fibbonacci.nthNumberRecursive(4) === 5)
}
it should "return sum of two previous numbers" in {
for (i <- 2 to 10) assert(Fibbonacci.nthNumberRecursive(i) === Fibbonacci.nthNumberRecursive(i - 1) + Fibbonacci.nthNumberRecursive(i - 2))
}
"iterative solution" should "start from 1" in {
assert(Fibbonacci.nthNumberIterative(0) === 1)
}
it should "calculate some fibbonacci number" in {
assert(Fibbonacci.nthNumberIterative(4) === 5)
}
it should "return sum of two previous numbers" in {
for (i <- 2 to 20) assert(Fibbonacci.nthNumberIterative(i) === Fibbonacci.nthNumberIterative(i - 1) + Fibbonacci.nthNumberIterative(i - 2))
}
"tail recursive solution" should "start from 1" in {
assert(Fibbonacci.nthNumberTailRec(0) === 1)
}
it should "calculate some fibbonacci number" in {
assert(Fibbonacci.nthNumberTailRec(4) === 5)
}
it should "return sum of two previous numbers" in {
for (i <- 2 to 20) assert(Fibbonacci.nthNumberTailRec(i) === Fibbonacci.nthNumberTailRec(i - 1) + Fibbonacci.nthNumberTailRec(i - 2))
}
}