aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-02-22 16:39:45 +0100
committerPacien TRAN-GIRARD2016-02-22 16:39:45 +0100
commit7574a77482936bf2c56ee904f7d91d64571b0b12 (patch)
tree4d133ac5e5d4e79f9e51450fe3187f9ae78f3173 /test
parent40b90b3647225c4446ef9db523cd474368ef26dd (diff)
downloadxblast-7574a77482936bf2c56ee904f7d91d64571b0b12.tar.gz
Refactor neighbor computation using directional vectors
Diffstat (limited to 'test')
-rw-r--r--test/ch/epfl/xblast/DirectionTest.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/test/ch/epfl/xblast/DirectionTest.java b/test/ch/epfl/xblast/DirectionTest.java
index a2ac9cd..0ebb3b7 100644
--- a/test/ch/epfl/xblast/DirectionTest.java
+++ b/test/ch/epfl/xblast/DirectionTest.java
@@ -1,21 +1,23 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import org.junit.Test; 3import org.junit.Test;
8 4
5import static org.junit.Assert.*;
6
7/**
8 * @author EPFL
9 * @author Pacien TRAN-GIRARD (261948)
10 */
9public class DirectionTest { 11public class DirectionTest {
10 @Test 12 @Test
11 public void oppositeOfOppositeIsIdentity() { 13 public void oppositeOfOppositeIsIdentity() {
12 for (Direction d: Direction.values()) 14 for (Direction d : Direction.values())
13 assertEquals(d, d.opposite().opposite()); 15 assertEquals(d, d.opposite().opposite());
14 } 16 }
15 17
16 @Test 18 @Test
17 public void oppositeIsTwoStepsAway() { 19 public void oppositeIsTwoStepsAway() {
18 for (Direction d: Direction.values()) 20 for (Direction d : Direction.values())
19 assertEquals(2, Math.abs(d.ordinal() - d.opposite().ordinal())); 21 assertEquals(2, Math.abs(d.ordinal() - d.opposite().ordinal()));
20 } 22 }
21 23
@@ -29,8 +31,8 @@ public class DirectionTest {
29 31
30 @Test 32 @Test
31 public void isParallelIsTrueOnlyForOppositeAndSelf() { 33 public void isParallelIsTrueOnlyForOppositeAndSelf() {
32 for (Direction d1: Direction.values()) { 34 for (Direction d1 : Direction.values()) {
33 for (Direction d2: Direction.values()) { 35 for (Direction d2 : Direction.values()) {
34 if (d1 == d2 || d1 == d2.opposite()) 36 if (d1 == d2 || d1 == d2.opposite())
35 assertTrue(d1.isParallelTo(d2)); 37 assertTrue(d1.isParallelTo(d2));
36 else 38 else
@@ -38,4 +40,12 @@ public class DirectionTest {
38 } 40 }
39 } 41 }
40 } 42 }
43
44 @Test
45 public void oppositeVectorSumIsNil() {
46 for (Direction d : Direction.values()) {
47 assertEquals(0, d.xVector() + d.opposite().xVector());
48 assertEquals(0, d.yVector() + d.opposite().yVector());
49 }
50 }
41} 51}