aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-03-01 17:38:14 +0100
committerPacien TRAN-GIRARD2016-03-01 17:38:14 +0100
commita111835984e2d6abbf3dcab317cf97c0f5842ba1 (patch)
tree2c6f4baca606b6fd056a2e05e732de5a39bc43fb
parent4745bff1ce9888effe8ec26253e4349d47436a05 (diff)
downloadxblast-a111835984e2d6abbf3dcab317cf97c0f5842ba1.tar.gz
Reformat code and doc-blocks
-rw-r--r--src/ch/epfl/xblast/server/Board.java14
-rw-r--r--test/ch/epfl/xblast/CellTest.java29
-rw-r--r--test/ch/epfl/xblast/DirectionTest.java2
-rw-r--r--test/ch/epfl/xblast/SubCellTest.java25
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck01.java11
-rw-r--r--test/ch/epfl/xblast/namecheck/NameCheck02.java9
-rw-r--r--test/ch/epfl/xblast/server/BlockTest.java5
-rw-r--r--test/ch/epfl/xblast/server/BoardTest.java53
8 files changed, 86 insertions, 62 deletions
diff --git a/src/ch/epfl/xblast/server/Board.java b/src/ch/epfl/xblast/server/Board.java
index bde0ae9..4d2e743 100644
--- a/src/ch/epfl/xblast/server/Board.java
+++ b/src/ch/epfl/xblast/server/Board.java
@@ -1,8 +1,8 @@
1package ch.epfl.xblast.server; 1package ch.epfl.xblast.server;
2 2
3import ch.epfl.cs108.Sq; 3import ch.epfl.cs108.Sq;
4import ch.epfl.xblast.Lists;
5import ch.epfl.xblast.Cell; 4import ch.epfl.xblast.Cell;
5import ch.epfl.xblast.Lists;
6 6
7import java.util.ArrayList; 7import java.util.ArrayList;
8import java.util.List; 8import java.util.List;
@@ -14,6 +14,7 @@ import java.util.List;
14 * @author Timothée FLOURE (257420) 14 * @author Timothée FLOURE (257420)
15 */ 15 */
16public final class Board { 16public final class Board {
17
17 private static final int BLOCKS_LIST_SIZE = 195; 18 private static final int BLOCKS_LIST_SIZE = 195;
18 private static final int BOARD_ROWS = 13; 19 private static final int BOARD_ROWS = 13;
19 private static final int BOARD_COLUMNS = 15; 20 private static final int BOARD_COLUMNS = 15;
@@ -23,10 +24,10 @@ public final class Board {
23 private static final int QUADRANT_COLUMNS = 7; 24 private static final int QUADRANT_COLUMNS = 7;
24 25
25 /** 26 /**
26 * Throw an exeption if the matrix does not have the given number of rows/columns. 27 * Throw an exception if the matrix does not have the given number of rows/columns.
27 * 28 *
28 * @param matrix the tested matrix 29 * @param matrix the tested matrix
29 * @param rows the expected number of rows 30 * @param rows the expected number of rows
30 * @param columns the expected number of columns 31 * @param columns the expected number of columns
31 * @throws IllegalArgumentException if the matrix does not comply with the given sizes. 32 * @throws IllegalArgumentException if the matrix does not comply with the given sizes.
32 */ 33 */
@@ -48,7 +49,7 @@ public final class Board {
48 private List<Sq<Block>> blocks; 49 private List<Sq<Block>> blocks;
49 50
50 /** 51 /**
51 * Instanciates a new Board with the given sequence of blocks. 52 * Instantiates a new Board with the given sequence of blocks.
52 * 53 *
53 * @param blocks sequence containing all the blocks of the Boards 54 * @param blocks sequence containing all the blocks of the Boards
54 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements 55 * @throws IllegalArgumentException if the blocks is not composed of BLOC_LIST_SIZE elements
@@ -85,7 +86,7 @@ public final class Board {
85 * 86 *
86 * @param innerBlocks lists of the internal rows 87 * @param innerBlocks lists of the internal rows
87 * @return a new walled board filled with the given rows 88 * @return a new walled board filled with the given rows
88 * @throws IllegalArgumentException if innerbLocks is not INNER_BOARD_ROWS * INNER_BOARD_COLUMNS 89 * @throws IllegalArgumentException if innerBlocks is not INNER_BOARD_ROWS * INNER_BOARD_COLUMNS
89 */ 90 */
90 public static Board ofInnerBlocksWalled(List<List<Block>> innerBlocks) { 91 public static Board ofInnerBlocksWalled(List<List<Block>> innerBlocks) {
91 checkBlockMatrix(innerBlocks, INNER_BOARD_ROWS, INNER_BOARD_COLUMNS); 92 checkBlockMatrix(innerBlocks, INNER_BOARD_ROWS, INNER_BOARD_COLUMNS);
@@ -147,4 +148,5 @@ public final class Board {
147 public Block blockAt(Cell c) { 148 public Block blockAt(Cell c) {
148 return blocksAt(c).head(); 149 return blocksAt(c).head();
149 } 150 }
151
150} 152}
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 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import org.junit.Test;
4
3import static org.junit.Assert.assertEquals; 5import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse; 6import static org.junit.Assert.assertFalse;
5 7
6import org.junit.Test; 8/**
7 9 * @author EPFL
10 */
8public class CellTest { 11public 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 */
11public class DirectionTest { 11public 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/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 @@
1package ch.epfl.xblast; 1package ch.epfl.xblast;
2 2
3import org.junit.Test;
4
3import static org.junit.Assert.assertEquals; 5import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue; 6import static org.junit.Assert.assertTrue;
5 7
6import org.junit.Test; 8/**
7 9 * @author EPFL
10 */
8public class SubCellTest { 11public 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