-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEx05Spec.scala
40 lines (29 loc) · 1.09 KB
/
Ex05Spec.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
package matrix
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class Ex05Spec extends AnyFlatSpec with Matchers:
"Vector.angleCos" should "return correct cosine for the identical vectors" in {
val v1 = Vector.of(1.0, 0.0)
val v2 = Vector.of(1.0, 0.0)
Vector.angleCos(v1, v2) shouldBe 1.0
}
it should "return correct cosine for perpendicular vectors" in {
val v1 = Vector.of(1.0, 0.0)
val v2 = Vector.of(0.0, 1.0)
Vector.angleCos(v1, v2) shouldBe 0.0
}
it should "return correct cosine for vectors with angle = 180 degree" in {
val v1 = Vector.of(-1.0, 1.0)
val v2 = Vector.of(1.0, -1.0)
Vector.angleCos(v1, v2) shouldBe -1.0 +- 1e-9
}
it should "return correct cosine for similar scaled vectors" in {
val v1 = Vector.of(2.0, 1.0)
val v2 = Vector.of(4.0, 2.0)
Vector.angleCos(v1, v2) shouldBe 1.0 +- 1e-9
}
it should "return correct cosine for random vectors" in {
val v1 = Vector.of(1.0, 2.0, 3.0)
val v2 = Vector.of(4.0, 5.0, 6.0)
Vector.angleCos(v1, v2) shouldBe 0.974631846 +- 1e-9
}