forked from ubedjunejo/se-ws19-exercise-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vec3DTest.java
69 lines (59 loc) · 1.89 KB
/
Vec3DTest.java
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package exercise;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class Vec3DTest {
//allows precision loss
final static double DELTA = 0.01;
@Test
public void Vec3DtoStringTest() {
Vec3D vector = new Vec3D(1.0, 2.0, 3.0);
String result = vector.toString();
assertEquals("[ 1.0, 2.0, 3.0 ]", result);
}
@Test
public void Vec3DTestLen() {
Vec3D v1 = new Vec3D(1, 0, 0);
Vec3D v2 = new Vec3D(3, 0, 4);
assertEquals(v1.len(), 1.0, DELTA);
assertEquals(v2.len(), 5.0, DELTA);
}
@Test
public void Vec3DTestCross1() {
Vec3D v1 = new Vec3D(1, 1, 0);
Vec3D v2 = new Vec3D(0, 1, 0);
Vec3D v3 = v1.cross(v2);
assertEquals(v3.x, 0.0, DELTA);
assertEquals(v3.y, 0.0, DELTA);
assertEquals(v3.z, 1.0, DELTA);
}
@Test
public void Vec3DTestCross2() {
Vec3D v1 = new Vec3D(1, 1, 0);
Vec3D v2 = new Vec3D(0, 1, 0);
Vec3D v3 = v2.cross(v1);
assertEquals(v3.x, 0.0, DELTA);
assertEquals(v3.y, 0.0, DELTA);
assertEquals(v3.z, -1.0, DELTA);
}
@Test
public void Vec3DTestNormalize1() {
Vec3D v1 = new Vec3D(1, 0, 0);
assertEquals(1.0f, v1.normalize().x, DELTA);
assertEquals(0, v1.normalize().y, DELTA);
assertEquals(0, v1.normalize().z, DELTA);
}
@Test
public void Vec3DTestNormalize2() {
Vec3D v1 = new Vec3D(1, 1, 1);
assertEquals(0.58f, v1.normalize().x, DELTA);
assertEquals(0.58f, v1.normalize().y, DELTA);
assertEquals(0.58f, v1.normalize().z, DELTA);
}
@Test
public void Vec3DTestNormalize3() {
Vec3D v1 = new Vec3D(3, 4, 5);
assertEquals(0.42f, v1.normalize().x, DELTA);
assertEquals(0.57f, v1.normalize().y, DELTA);
assertEquals(0.71f, v1.normalize().z, DELTA);
}
}