diff options
author | Pacien | 2016-03-01 18:45:54 +0100 |
---|---|---|
committer | Pacien | 2016-03-01 18:45:54 +0100 |
commit | 264fec2ec938a6c525ca6f569692118a8216ca19 (patch) | |
tree | 0cf7fe569b6de16c4bd4dc8776fb82dfeeda312e /test/ch | |
parent | 45880b06c053e75e1778a598245015c65440a5bc (diff) | |
parent | cc88afb9fe448b759966e94b07692fb6a154b2bf (diff) | |
download | xblast-264fec2ec938a6c525ca6f569692118a8216ca19.tar.gz |
Merge branch '02_board' into 'master'
02_board
02 board
See merge request !1
Diffstat (limited to 'test/ch')
-rw-r--r-- | test/ch/epfl/xblast/CellTest.java | 29 | ||||
-rw-r--r-- | test/ch/epfl/xblast/DirectionTest.java | 2 | ||||
-rw-r--r-- | test/ch/epfl/xblast/ListsTest.java | 51 | ||||
-rw-r--r-- | test/ch/epfl/xblast/SubCellTest.java | 25 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck01.java | 11 | ||||
-rw-r--r-- | test/ch/epfl/xblast/namecheck/NameCheck02.java | 63 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BlockTest.java | 38 | ||||
-rw-r--r-- | test/ch/epfl/xblast/server/BoardTest.java | 166 |
8 files changed, 359 insertions, 26 deletions
diff --git a/test/ch/epfl/xblast/CellTest.java b/test/ch/epfl/xblast/CellTest.java index ba8becc..c5d93e8 100644 --- a/test/ch/epfl/xblast/CellTest.java +++ b/test/ch/epfl/xblast/CellTest.java | |||
@@ -1,15 +1,19 @@ | |||
1 | package ch.epfl.xblast; | 1 | package ch.epfl.xblast; |
2 | 2 | ||
3 | import org.junit.Test; | ||
4 | |||
3 | import static org.junit.Assert.assertEquals; | 5 | import static org.junit.Assert.assertEquals; |
4 | import static org.junit.Assert.assertFalse; | 6 | import static org.junit.Assert.assertFalse; |
5 | 7 | ||
6 | import org.junit.Test; | 8 | /** |
7 | 9 | * @author EPFL | |
10 | */ | ||
8 | public class CellTest { | 11 | public class CellTest { |
12 | |||
9 | @Test | 13 | @Test |
10 | public void rowMajorIndexCorrespondsToOrder() { | 14 | public void rowMajorIndexCorrespondsToOrder() { |
11 | int i = 0; | 15 | int i = 0; |
12 | for (Cell c: Cell.ROW_MAJOR_ORDER) | 16 | for (Cell c : Cell.ROW_MAJOR_ORDER) |
13 | assertEquals(i++, c.rowMajorIndex()); | 17 | assertEquals(i++, c.rowMajorIndex()); |
14 | assertEquals(Cell.COUNT, i); | 18 | assertEquals(Cell.COUNT, i); |
15 | } | 19 | } |
@@ -19,7 +23,7 @@ public class CellTest { | |||
19 | assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size()); | 23 | assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size()); |
20 | 24 | ||
21 | boolean[] cellSeen = new boolean[Cell.COUNT]; | 25 | boolean[] cellSeen = new boolean[Cell.COUNT]; |
22 | for (Cell c: Cell.SPIRAL_ORDER) { | 26 | for (Cell c : Cell.SPIRAL_ORDER) { |
23 | assertFalse(cellSeen[c.rowMajorIndex()]); | 27 | assertFalse(cellSeen[c.rowMajorIndex()]); |
24 | cellSeen[c.rowMajorIndex()] = true; | 28 | cellSeen[c.rowMajorIndex()] = true; |
25 | } | 29 | } |
@@ -28,9 +32,9 @@ public class CellTest { | |||
28 | @Test | 32 | @Test |
29 | public void spiralOrderNeighborsAreSpatialNeighbors() { | 33 | public void spiralOrderNeighborsAreSpatialNeighbors() { |
30 | Cell pred = Cell.SPIRAL_ORDER.get(0); | 34 | Cell pred = Cell.SPIRAL_ORDER.get(0); |
31 | for (Cell c: Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { | 35 | for (Cell c : Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { |
32 | int areNeighborsCount = 0; | 36 | int areNeighborsCount = 0; |
33 | for (Direction d: Direction.values()) { | 37 | for (Direction d : Direction.values()) { |
34 | if (pred.equals(c.neighbor(d))) | 38 | if (pred.equals(c.neighbor(d))) |
35 | areNeighborsCount += 1; | 39 | areNeighborsCount += 1; |
36 | } | 40 | } |
@@ -51,18 +55,19 @@ public class CellTest { | |||
51 | @Test | 55 | @Test |
52 | public void neighborsOfOriginAreCorrect() { | 56 | public void neighborsOfOriginAreCorrect() { |
53 | Cell c = new Cell(0, 0); | 57 | Cell c = new Cell(0, 0); |
54 | assertEquals(new Cell( 0, 12), c.neighbor(Direction.N)); | 58 | assertEquals(new Cell(0, 12), c.neighbor(Direction.N)); |
55 | assertEquals(new Cell( 1, 0), c.neighbor(Direction.E)); | 59 | assertEquals(new Cell(1, 0), c.neighbor(Direction.E)); |
56 | assertEquals(new Cell( 0, 1), c.neighbor(Direction.S)); | 60 | assertEquals(new Cell(0, 1), c.neighbor(Direction.S)); |
57 | assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); | 61 | assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); |
58 | } | 62 | } |
59 | 63 | ||
60 | @Test | 64 | @Test |
61 | public void oppositeNeighborOfNeighborIsThis() { | 65 | public void oppositeNeighborOfNeighborIsThis() { |
62 | for (Cell c: Cell.ROW_MAJOR_ORDER) { | 66 | for (Cell c : Cell.ROW_MAJOR_ORDER) { |
63 | for (Direction d: Direction.values()) { | 67 | for (Direction d : Direction.values()) { |
64 | assertEquals(c, c.neighbor(d).neighbor(d.opposite())); | 68 | assertEquals(c, c.neighbor(d).neighbor(d.opposite())); |
65 | } | 69 | } |
66 | } | 70 | } |
67 | } | 71 | } |
72 | |||
68 | } | 73 | } |
diff --git a/test/ch/epfl/xblast/DirectionTest.java b/test/ch/epfl/xblast/DirectionTest.java index 0ebb3b7..49cf4be 100644 --- a/test/ch/epfl/xblast/DirectionTest.java +++ b/test/ch/epfl/xblast/DirectionTest.java | |||
@@ -9,6 +9,7 @@ import static org.junit.Assert.*; | |||
9 | * @author Pacien TRAN-GIRARD (261948) | 9 | * @author Pacien TRAN-GIRARD (261948) |
10 | */ | 10 | */ |
11 | public class DirectionTest { | 11 | public class DirectionTest { |
12 | |||
12 | @Test | 13 | @Test |
13 | public void oppositeOfOppositeIsIdentity() { | 14 | public void oppositeOfOppositeIsIdentity() { |
14 | for (Direction d : Direction.values()) | 15 | for (Direction d : Direction.values()) |
@@ -48,4 +49,5 @@ public class DirectionTest { | |||
48 | assertEquals(0, d.yVector() + d.opposite().yVector()); | 49 | assertEquals(0, d.yVector() + d.opposite().yVector()); |
49 | } | 50 | } |
50 | } | 51 | } |
52 | |||
51 | } | 53 | } |
diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java new file mode 100644 index 0000000..b898399 --- /dev/null +++ b/test/ch/epfl/xblast/ListsTest.java | |||
@@ -0,0 +1,51 @@ | |||
1 | package ch.epfl.xblast; | ||
2 | |||
3 | import org.junit.Test; | ||
4 | |||
5 | import java.util.ArrayList; | ||
6 | import java.util.Arrays; | ||
7 | import java.util.List; | ||
8 | import java.util.stream.Collectors; | ||
9 | import java.util.stream.IntStream; | ||
10 | |||
11 | import static org.junit.Assert.assertEquals; | ||
12 | |||
13 | /** | ||
14 | * @author Pacien TRAN-GIRARD (261948) | ||
15 | * @author Timothée FLOURE (257420) | ||
16 | */ | ||
17 | public class ListsTest { | ||
18 | |||
19 | @Test(expected = IllegalArgumentException.class) | ||
20 | public void isEmptyListThrowingException() { | ||
21 | List<Integer> emptyList = new ArrayList<>(); | ||
22 | Lists.mirrored(emptyList); | ||
23 | } | ||
24 | |||
25 | @Test | ||
26 | public void isListMirrored() { | ||
27 | List<Integer> sampleList = Arrays.asList(1, 2, 3, 4, 5); | ||
28 | List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5, 4, 3, 2, 1); | ||
29 | |||
30 | assertEquals(expected, Lists.mirrored(sampleList)); | ||
31 | } | ||
32 | |||
33 | @Test | ||
34 | public void mirroredListSizeIsCorrect() { | ||
35 | int sampleSize = 10; | ||
36 | List<Integer> sampleList = IntStream.range(0, sampleSize).boxed().collect(Collectors.toList()); | ||
37 | List<Integer> mirrored = Lists.mirrored(sampleList); | ||
38 | |||
39 | assertEquals(sampleSize * 2 - 1, mirrored.size()); | ||
40 | } | ||
41 | |||
42 | @Test | ||
43 | public void mirrorElementsAreEqual() { | ||
44 | List<Integer> sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); | ||
45 | List<Integer> mirrored = Lists.mirrored(sampleList); | ||
46 | |||
47 | for (int i = 0; i < mirrored.size() / 2; ++i) | ||
48 | assertEquals(mirrored.get(i), mirrored.get(mirrored.size() - 1 - i)); | ||
49 | } | ||
50 | |||
51 | } | ||
diff --git a/test/ch/epfl/xblast/SubCellTest.java b/test/ch/epfl/xblast/SubCellTest.java index 1c79791..b3450e1 100644 --- a/test/ch/epfl/xblast/SubCellTest.java +++ b/test/ch/epfl/xblast/SubCellTest.java | |||
@@ -1,11 +1,15 @@ | |||
1 | package ch.epfl.xblast; | 1 | package ch.epfl.xblast; |
2 | 2 | ||
3 | import org.junit.Test; | ||
4 | |||
3 | import static org.junit.Assert.assertEquals; | 5 | import static org.junit.Assert.assertEquals; |
4 | import static org.junit.Assert.assertTrue; | 6 | import static org.junit.Assert.assertTrue; |
5 | 7 | ||
6 | import org.junit.Test; | 8 | /** |
7 | 9 | * @author EPFL | |
10 | */ | ||
8 | public class SubCellTest { | 11 | public class SubCellTest { |
12 | |||
9 | @Test | 13 | @Test |
10 | public void centralSubCellOfKnowCellIsCorrect() { | 14 | public void centralSubCellOfKnowCellIsCorrect() { |
11 | SubCell c = SubCell.centralSubCellOf(new Cell(2, 1)); | 15 | SubCell c = SubCell.centralSubCellOf(new Cell(2, 1)); |
@@ -15,13 +19,13 @@ public class SubCellTest { | |||
15 | 19 | ||
16 | @Test | 20 | @Test |
17 | public void centralSubCellIsCentral() { | 21 | public void centralSubCellIsCentral() { |
18 | for (Cell c: Cell.ROW_MAJOR_ORDER) | 22 | for (Cell c : Cell.ROW_MAJOR_ORDER) |
19 | assertTrue(SubCell.centralSubCellOf(c).isCentral()); | 23 | assertTrue(SubCell.centralSubCellOf(c).isCentral()); |
20 | } | 24 | } |
21 | 25 | ||
22 | @Test | 26 | @Test |
23 | public void distanceToCentralOfCentralIsZero() { | 27 | public void distanceToCentralOfCentralIsZero() { |
24 | for (Cell c: Cell.ROW_MAJOR_ORDER) | 28 | for (Cell c : Cell.ROW_MAJOR_ORDER) |
25 | assertEquals(0, SubCell.centralSubCellOf(c).distanceToCentral()); | 29 | assertEquals(0, SubCell.centralSubCellOf(c).distanceToCentral()); |
26 | } | 30 | } |
27 | 31 | ||
@@ -43,18 +47,19 @@ public class SubCellTest { | |||
43 | @Test | 47 | @Test |
44 | public void neighborsOfOriginAreCorrect() { | 48 | public void neighborsOfOriginAreCorrect() { |
45 | SubCell c = new SubCell(0, 0); | 49 | SubCell c = new SubCell(0, 0); |
46 | assertEquals(new SubCell( 0, 207), c.neighbor(Direction.N)); | 50 | assertEquals(new SubCell(0, 207), c.neighbor(Direction.N)); |
47 | assertEquals(new SubCell( 1, 0), c.neighbor(Direction.E)); | 51 | assertEquals(new SubCell(1, 0), c.neighbor(Direction.E)); |
48 | assertEquals(new SubCell( 0, 1), c.neighbor(Direction.S)); | 52 | assertEquals(new SubCell(0, 1), c.neighbor(Direction.S)); |
49 | assertEquals(new SubCell(239, 0), c.neighbor(Direction.W)); | 53 | assertEquals(new SubCell(239, 0), c.neighbor(Direction.W)); |
50 | } | 54 | } |
51 | 55 | ||
52 | @Test | 56 | @Test |
53 | public void containingCellOfCentralsNeighborIsCorrect() { | 57 | public void containingCellOfCentralsNeighborIsCorrect() { |
54 | for (Cell c: Cell.ROW_MAJOR_ORDER) { |