-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEx02Spec.scala
42 lines (36 loc) · 1.1 KB
/
Ex02Spec.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 matrix
import math.Interpolation.given
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class Ex02Spec extends AnyFlatSpec with Matchers:
"LinearInterpolation" should "interpolate correct values for Double" in {
(0.0, 1.0).interpolateBy(0.0) shouldBe 0.0
(0.0, 1.0).interpolateBy(1.0) shouldBe 1.0
(0.0, 1.0).interpolateBy(0.5) shouldBe 0.5
(21.0, 42.0).interpolateBy(0.3) shouldBe 27.3
}
it should "interpolate correct Vectors of Double" in {
val v1 = Vector.of(2.0, 1.0)
val v2 = Vector.of(4.0, 2.0)
(v1, v2).interpolateBy(0.3) shouldBe Vector.of(2.6, 1.3)
}
it should "interpolate correct Matrices of Double" in {
val m1 = Matrix[2, 2, Double] {
Vector.of(
Vector.of(2.0, 1.0),
Vector.of(3.0, 4.0),
)
}
val m2 = Matrix[2, 2, Double] {
Vector.of(
Vector.of(20.0, 10.0),
Vector.of(30.0, 40.0),
)
}
(m1, m2).interpolateBy(0.5) shouldBe Matrix[2, 2, Double] {
Vector.of(
Vector.of(11.0, 5.5),
Vector.of(16.5, 22.0),
)
}
}