From 746aafc3f0e8212282a5fbf31de7a83d2a618dc8 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Sat, 27 Feb 2016 12:04:39 +0100 Subject: Add the Lists and Board Class + the Ticks Interface. Add the tests related to the '02_Board' part of the project. --- test/ch/epfl/xblast/ListsTest.java | 32 ++++++ test/ch/epfl/xblast/namecheck/NameCheck02.java | 60 +++++++++++ test/ch/epfl/xblast/server/BlockTest.java | 35 +++++++ test/ch/epfl/xblast/server/BoardTest.java | 137 +++++++++++++++++++++++++ 4 files changed, 264 insertions(+) create mode 100644 test/ch/epfl/xblast/ListsTest.java create mode 100644 test/ch/epfl/xblast/namecheck/NameCheck02.java create mode 100644 test/ch/epfl/xblast/server/BlockTest.java create mode 100644 test/ch/epfl/xblast/server/BoardTest.java (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java new file mode 100644 index 0000000..6a98b3f --- /dev/null +++ b/test/ch/epfl/xblast/ListsTest.java @@ -0,0 +1,32 @@ +package ch.epfl.xblast; + +import java.util.List; +import java.util.Arrays; +import static org.junit.Assert.*; +import org.junit.Test; + +/** +* @author Pacien TRAN-GIRARD (261948) +* @author Timothée FLOURE (257420) +*/ +public class ListsTest { + @Test(expected=IllegalArgumentException.class) + public void isEmptyListThrowingException() { + List sampleList = Arrays.asList(); + Lists.mirrored(sampleList); + } + + @Test(expected=IllegalArgumentException.class) + public void isNullListThrowingException() { + List sampleList = Arrays.asList(); + Lists.mirrored(sampleList); + } + + @Test + public void isListMirrored() { + List sampleList = Arrays.asList(1,2,3,4,5); + List expected = Arrays.asList(1,2,3,4,5,4,3,2,1); + + assertEquals(expected, Lists.mirrored(sampleList)); + } +} diff --git a/test/ch/epfl/xblast/namecheck/NameCheck02.java b/test/ch/epfl/xblast/namecheck/NameCheck02.java new file mode 100644 index 0000000..978526e --- /dev/null +++ b/test/ch/epfl/xblast/namecheck/NameCheck02.java @@ -0,0 +1,60 @@ +package ch.epfl.xblast.namecheck; + +import java.util.List; + +import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Cell; +import ch.epfl.xblast.Lists; +import ch.epfl.xblast.server.Block; +import ch.epfl.xblast.server.Board; +import ch.epfl.xblast.server.Ticks; + +/** + * Classe abstraite utilisant tous les éléments de l'étape 2, pour essayer de + * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est + * pas un test unitaire, et n'a pas pour but d'être exécuté! + */ + +abstract class NameCheck02 { + void checkTicks() { + int x = Ticks.PLAYER_DYING_TICKS + + Ticks.PLAYER_INVULNERABLE_TICKS + + Ticks.BOMB_FUSE_TICKS + + Ticks.EXPLOSION_TICKS + + Ticks.WALL_CRUMBLING_TICKS + + Ticks.BONUS_DISAPPEARING_TICKS; + System.out.println(x); + } + + void checkBlock() { + Block b = Block.FREE; + b = Block.INDESTRUCTIBLE_WALL; + b = Block.DESTRUCTIBLE_WALL; + b = Block.CRUMBLING_WALL; + boolean d = b.isFree() && b.canHostPlayer() && b.castsShadow(); + System.out.println(b + "/" + d); + } + + void checkLists() { + List l1 = null; + List l2 = null; + List> l3 = null; + List l1m = Lists.mirrored(l1); + List l2m = Lists.mirrored(l2); + List> l3m = Lists.>mirrored(l3); + System.out.println("" + l1m + l2m + l3m); + } + + void checkBoard() { + List> q = null; + Board b = Board.ofQuadrantNWBlocksWalled(q); + b = Board.ofInnerBlocksWalled(q); + b = Board.ofRows(q); + List> cells = null; + b = new Board(cells); + Cell c = null; + Sq bs = b.blocksAt(c); + Block l = b.blockAt(c); + System.out.println(bs + "/" + l); + } +} diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java new file mode 100644 index 0000000..bbe4376 --- /dev/null +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -0,0 +1,35 @@ +package ch.epfl.xblast.server; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author Timothée FLOURE (257420) + * @author pacien TRAN-GIRARD (261948) + */ +public class BlockTest { + @Test + public void free() { + assertFalse(Block.INDESTRUCTIBLE_WALL.isFree()); + assertFalse(Block.DESTRUCTIBLE_WALL.isFree()); + assertFalse(Block.CRUMBLING_WALL.isFree()); + assertTrue(Block.FREE.isFree()); + } + + @Test + public void canHostPlayer() { + assertFalse(Block.INDESTRUCTIBLE_WALL.canHostPlayer()); + assertFalse(Block.DESTRUCTIBLE_WALL.canHostPlayer()); + assertFalse(Block.CRUMBLING_WALL.canHostPlayer()); + assertTrue(Block.FREE.canHostPlayer()); + } + + @Test + public void castSadhow() { + assertTrue(Block.INDESTRUCTIBLE_WALL.castsShadow()); + assertTrue(Block.DESTRUCTIBLE_WALL.castsShadow()); + assertTrue(Block.CRUMBLING_WALL.castsShadow()); + assertFalse(Block.FREE.castsShadow()); + } +} diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java new file mode 100644 index 0000000..7868e70 --- /dev/null +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -0,0 +1,137 @@ +package ch.epfl.xblast.server; + +import java.util.List; +import java.util.ArrayList; +import org.junit.Test; +import ch.epfl.cs108.Sq; + +import static org.junit.Assert.*; + +/** + * @author Timothée FLOURE (257420) + * @author Pacien TRAN-GIRARD (261948) + */ +public class BoardTest { + + @Test(expected=IllegalArgumentException.class) + public void isBoardBuilderEmptyInputThrowingException() { + List> blocks = new ArrayList>(); + new Board(blocks); + + } + + + @Test(expected=IllegalArgumentException.class) + public void isBoardBuilderIllegalInputThrowingException() { + List> blocks = new ArrayList>(); + + for (int i = 0;i<8;i++) { + blocks.add(Sq.constant(Block.FREE)); + } + + new Board(blocks); + + } + + @Test(expected=IllegalArgumentException.class) + public void isOfRowsEmptyInputMatrixThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofRows(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfRowsIllegalInputThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofRows(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromRowsMatrix() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 13; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 15; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofRows(rowsList) instanceof Board); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfInnerBlocksWalledEmptyInputMatrixThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofInnerBlocksWalled(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isOfInnerBlocksWalledIllegalInputThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromInnerBlocks() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 11; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 13; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + } + + @Test(expected=IllegalArgumentException.class) + public void isBuildWithEmptyQuadrantThrowingException() { + List> rowsList = new ArrayList>(); + Board.ofQuadrantNWBlocksWalled(rowsList); + } + + @Test(expected=IllegalArgumentException.class) + public void isBuildWithIllegalQuadrantThrowingException() { + List> rowsList = new ArrayList>(); + List sampleRow = new ArrayList(); + + for (int i = 0;i < 8 ;i++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + + assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + } + + @Test + public void buildBoardFromNWQuadrant() { + List> rowsList = new ArrayList>() ; + + for (int i = 0; i < 6; i++) { + List sampleRow = new ArrayList(); + for (int j = 0; j < 7; j++) { + sampleRow.add(Block.FREE); + } + rowsList.add(sampleRow); + } + + assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + } +} -- cgit v1.2.3 From 3fd6365255ba761f45f34bff3fef27a28b3a1785 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 29 Feb 2016 13:54:26 +0100 Subject: Fix typo in comment + remove tests on null input --- test/ch/epfl/xblast/ListsTest.java | 6 ------ test/ch/epfl/xblast/server/BoardTest.java | 2 -- 2 files changed, 8 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 6a98b3f..42b317f 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -16,12 +16,6 @@ public class ListsTest { Lists.mirrored(sampleList); } - @Test(expected=IllegalArgumentException.class) - public void isNullListThrowingException() { - List sampleList = Arrays.asList(); - Lists.mirrored(sampleList); - } - @Test public void isListMirrored() { List sampleList = Arrays.asList(1,2,3,4,5); diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 7868e70..e40769b 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -12,7 +12,6 @@ import static org.junit.Assert.*; * @author Pacien TRAN-GIRARD (261948) */ public class BoardTest { - @Test(expected=IllegalArgumentException.class) public void isBoardBuilderEmptyInputThrowingException() { List> blocks = new ArrayList>(); @@ -20,7 +19,6 @@ public class BoardTest { } - @Test(expected=IllegalArgumentException.class) public void isBoardBuilderIllegalInputThrowingException() { List> blocks = new ArrayList>(); -- cgit v1.2.3 From 7c19be7f34b932d696d839a092f05617400589f6 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:25:37 +0100 Subject: Rewrite list mirroring function and add test --- test/ch/epfl/xblast/ListsTest.java | 40 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 42b317f..0a2f5f9 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -1,26 +1,42 @@ package ch.epfl.xblast; -import java.util.List; -import java.util.Arrays; -import static org.junit.Assert.*; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; + /** -* @author Pacien TRAN-GIRARD (261948) -* @author Timothée FLOURE (257420) -*/ + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public class ListsTest { - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void isEmptyListThrowingException() { - List sampleList = Arrays.asList(); - Lists.mirrored(sampleList); + List emptyList = new ArrayList<>(); + Lists.mirrored(emptyList); } @Test public void isListMirrored() { - List sampleList = Arrays.asList(1,2,3,4,5); - List expected = Arrays.asList(1,2,3,4,5,4,3,2,1); + List sampleList = Arrays.asList(1, 2, 3, 4, 5); + List expected = Arrays.asList(1, 2, 3, 4, 5, 4, 3, 2, 1); + + assertEquals(expected, Lists.mirrored(sampleList)); + } - assertEquals(expected, Lists.mirrored(sampleList)); + @Test + public void mirrorElementsAreEqual() { + List sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); + List mirrored = Lists.mirrored(sampleList); + + for (int i = 0; i < mirrored.size() / 2; ++i) + assertEquals(mirrored.get(i), mirrored.get(mirrored.size() - 1 - i)); } + } -- cgit v1.2.3 From 7d26df97d90532b7fa094def157ea38c13a8c0f9 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:32:05 +0100 Subject: Add mirrored list size test --- test/ch/epfl/xblast/ListsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 0a2f5f9..b898399 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -30,6 +30,15 @@ public class ListsTest { assertEquals(expected, Lists.mirrored(sampleList)); } + @Test + public void mirroredListSizeIsCorrect() { + int sampleSize = 10; + List sampleList = IntStream.range(0, sampleSize).boxed().collect(Collectors.toList()); + List mirrored = Lists.mirrored(sampleList); + + assertEquals(sampleSize * 2 - 1, mirrored.size()); + } + @Test public void mirrorElementsAreEqual() { List sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); -- cgit v1.2.3 From e25492f5f71b4ad4e09e485fe46b5dd60a568994 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:37:56 +0100 Subject: Remove redundant explicit type declaration --- test/ch/epfl/xblast/server/BoardTest.java | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index e40769b..673ab3b 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -14,14 +14,14 @@ import static org.junit.Assert.*; public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isBoardBuilderEmptyInputThrowingException() { - List> blocks = new ArrayList>(); + List> blocks = new ArrayList<>(); new Board(blocks); } @Test(expected=IllegalArgumentException.class) public void isBoardBuilderIllegalInputThrowingException() { - List> blocks = new ArrayList>(); + List> blocks = new ArrayList<>(); for (int i = 0;i<8;i++) { blocks.add(Sq.constant(Block.FREE)); @@ -33,14 +33,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isOfRowsEmptyInputMatrixThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofRows(rowsList); } @Test(expected=IllegalArgumentException.class) public void isOfRowsIllegalInputThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -52,10 +52,10 @@ public class BoardTest { @Test public void buildBoardFromRowsMatrix() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 13; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 15; j++) { sampleRow.add(Block.FREE); } @@ -67,14 +67,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isOfInnerBlocksWalledEmptyInputMatrixThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofInnerBlocksWalled(rowsList); } @Test(expected=IllegalArgumentException.class) public void isOfInnerBlocksWalledIllegalInputThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -86,10 +86,10 @@ public class BoardTest { @Test public void buildBoardFromInnerBlocks() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 11; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 13; j++) { sampleRow.add(Block.FREE); } @@ -101,14 +101,14 @@ public class BoardTest { @Test(expected=IllegalArgumentException.class) public void isBuildWithEmptyQuadrantThrowingException() { - List> rowsList = new ArrayList>(); + List> rowsList = new ArrayList<>(); Board.ofQuadrantNWBlocksWalled(rowsList); } @Test(expected=IllegalArgumentException.class) public void isBuildWithIllegalQuadrantThrowingException() { - List> rowsList = new ArrayList>(); - List sampleRow = new ArrayList(); + List> rowsList = new ArrayList<>(); + List sampleRow = new ArrayList<>(); for (int i = 0;i < 8 ;i++) { sampleRow.add(Block.FREE); @@ -120,10 +120,10 @@ public class BoardTest { @Test public void buildBoardFromNWQuadrant() { - List> rowsList = new ArrayList>() ; + List> rowsList = new ArrayList<>() ; for (int i = 0; i < 6; i++) { - List sampleRow = new ArrayList(); + List sampleRow = new ArrayList<>(); for (int j = 0; j < 7; j++) { sampleRow.add(Block.FREE); } -- cgit v1.2.3 From 55e19228a2b9119f136f62b050421ac91cdecf53 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:38:27 +0100 Subject: Fix typo in function name --- test/ch/epfl/xblast/server/BlockTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java index bbe4376..6cfc853 100644 --- a/test/ch/epfl/xblast/server/BlockTest.java +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -26,7 +26,7 @@ public class BlockTest { } @Test - public void castSadhow() { + public void castShadow() { assertTrue(Block.INDESTRUCTIBLE_WALL.castsShadow()); assertTrue(Block.DESTRUCTIBLE_WALL.castsShadow()); assertTrue(Block.CRUMBLING_WALL.castsShadow()); -- cgit v1.2.3 From 80143bb3522007a903f2a34967e0cf5b0d6b20e0 Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Tue, 1 Mar 2016 16:59:56 +0100 Subject: Add the test related to the blockAt() method --- test/ch/epfl/xblast/server/BoardTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 673ab3b..b23ac06 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.ArrayList; import org.junit.Test; import ch.epfl.cs108.Sq; +import ch.epfl.xblast.Cell; import static org.junit.Assert.*; @@ -132,4 +133,22 @@ public class BoardTest { assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); } + + @Test + public void isBlockAtReturningTheRightBlock() { + Cell sampleCell = new Cell(0,0); + Cell sampleCell2 = new Cell(3,4); + + List> blocksList = new ArrayList<>(); + + blocksList.add(Sq.constant(Block.INDESTRUCTIBLE_WALL)); + for (int i = 0; i < 194; i++) { + blocksList.add(Sq.constant(Block.FREE)); + } + Board sampleBoard = new Board(blocksList); + + assertTrue(sampleBoard.blockAt(sampleCell) == Block.INDESTRUCTIBLE_WALL); + assertTrue(sampleBoard.blockAt(sampleCell2) == Block.FREE); + } + } -- cgit v1.2.3 From a111835984e2d6abbf3dcab317cf97c0f5842ba1 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 1 Mar 2016 17:38:14 +0100 Subject: Reformat code and doc-blocks --- test/ch/epfl/xblast/CellTest.java | 29 ++++++++------ test/ch/epfl/xblast/DirectionTest.java | 2 + test/ch/epfl/xblast/SubCellTest.java | 25 +++++++----- test/ch/epfl/xblast/namecheck/NameCheck01.java | 11 ++++-- test/ch/epfl/xblast/namecheck/NameCheck02.java | 9 +++-- test/ch/epfl/xblast/server/BlockTest.java | 5 ++- test/ch/epfl/xblast/server/BoardTest.java | 53 +++++++++++++------------- 7 files changed, 78 insertions(+), 56 deletions(-) (limited to 'test/ch/epfl') 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 @@ package ch.epfl.xblast; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import org.junit.Test; - +/** + * @author EPFL + */ public class CellTest { + @Test public void rowMajorIndexCorrespondsToOrder() { int i = 0; - for (Cell c: Cell.ROW_MAJOR_ORDER) + for (Cell c : Cell.ROW_MAJOR_ORDER) assertEquals(i++, c.rowMajorIndex()); assertEquals(Cell.COUNT, i); } @@ -19,7 +23,7 @@ public class CellTest { assertEquals(Cell.COUNT, Cell.SPIRAL_ORDER.size()); boolean[] cellSeen = new boolean[Cell.COUNT]; - for (Cell c: Cell.SPIRAL_ORDER) { + for (Cell c : Cell.SPIRAL_ORDER) { assertFalse(cellSeen[c.rowMajorIndex()]); cellSeen[c.rowMajorIndex()] = true; } @@ -28,9 +32,9 @@ public class CellTest { @Test public void spiralOrderNeighborsAreSpatialNeighbors() { Cell pred = Cell.SPIRAL_ORDER.get(0); - for (Cell c: Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { + for (Cell c : Cell.SPIRAL_ORDER.subList(1, Cell.SPIRAL_ORDER.size())) { int areNeighborsCount = 0; - for (Direction d: Direction.values()) { + for (Direction d : Direction.values()) { if (pred.equals(c.neighbor(d))) areNeighborsCount += 1; } @@ -51,18 +55,19 @@ public class CellTest { @Test public void neighborsOfOriginAreCorrect() { Cell c = new Cell(0, 0); - assertEquals(new Cell( 0, 12), c.neighbor(Direction.N)); - assertEquals(new Cell( 1, 0), c.neighbor(Direction.E)); - assertEquals(new Cell( 0, 1), c.neighbor(Direction.S)); - assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); + assertEquals(new Cell(0, 12), c.neighbor(Direction.N)); + assertEquals(new Cell(1, 0), c.neighbor(Direction.E)); + assertEquals(new Cell(0, 1), c.neighbor(Direction.S)); + assertEquals(new Cell(14, 0), c.neighbor(Direction.W)); } @Test public void oppositeNeighborOfNeighborIsThis() { - for (Cell c: Cell.ROW_MAJOR_ORDER) { - for (Direction d: Direction.values()) { + for (Cell c : Cell.ROW_MAJOR_ORDER) { + for (Direction d : Direction.values()) { assertEquals(c, c.neighbor(d).neighbor(d.opposite())); } } } + } 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.*; * @author Pacien TRAN-GIRARD (261948) */ public class DirectionTest { + @Test public void oppositeOfOppositeIsIdentity() { for (Direction d : Direction.values()) @@ -48,4 +49,5 @@ public class DirectionTest { assertEquals(0, d.yVector() + d.opposite().yVector()); } } + } 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 @@ package ch.epfl.xblast; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.junit.Test; - +/** + * @author EPFL + */ public class SubCellTest { + @Test public void centralSubCellOfKnowCellIsCorrect() { SubCell c = SubCell.centralSubCellOf(new Cell(2, 1)); @@ -15,13 +19,13 @@ public class SubCellTest { @Test public void centralSubCellIsCentral() { - for (Cell c: Cell.ROW_MAJOR_ORDER) + for (Cell c : Cell.ROW_MAJOR_ORDER) assertTrue(SubCell.centralSubCellOf(c).isCentral()); } @Test public void distanceToCentralOfCentralIsZero() { - for (Cell c: Cell.ROW_MAJOR_ORDER) + for (Cell c : Cell.ROW_MAJOR_ORDER) assertEquals(0, SubCell.centralSubCellOf(c).distanceToCentral()); } @@ -43,18 +47,19 @@ public class SubCellTest { @Test public void neighborsOfOriginAreCorrect() { SubCell c = new SubCell(0, 0); - assertEquals(new SubCell( 0, 207), c.neighbor(Direction.N)); - assertEquals(new SubCell( 1, 0), c.neighbor(Direction.E)); - assertEquals(new SubCell( 0, 1), c.neighbor(Direction.S)); - assertEquals(new SubCell(239, 0), c.neighbor(Direction.W)); + assertEquals(new SubCell(0, 207), c.neighbor(Direction.N)); + assertEquals(new SubCell(1, 0), c.neighbor(Direction.E)); + assertEquals(new SubCell(0, 1), c.neighbor(Direction.S)); + assertEquals(new SubCell(239, 0), c.neighbor(Direction.W)); } @Test public void containingCellOfCentralsNeighborIsCorrect() { - for (Cell c: Cell.ROW_MAJOR_ORDER) { + for (Cell c : Cell.ROW_MAJOR_ORDER) { SubCell s = SubCell.centralSubCellOf(c); - for (Direction d: Direction.values()) + for (Direction d : Direction.values()) assertEquals(c, s.neighbor(d).containingCell()); } } + } diff --git a/test/ch/epfl/xblast/namecheck/NameCheck01.java b/test/ch/epfl/xblast/namecheck/NameCheck01.java index 278d85b..7d079c5 100644 --- a/test/ch/epfl/xblast/namecheck/NameCheck01.java +++ b/test/ch/epfl/xblast/namecheck/NameCheck01.java @@ -1,18 +1,20 @@ package ch.epfl.xblast.namecheck; -import java.util.List; - import ch.epfl.xblast.Cell; import ch.epfl.xblast.Direction; import ch.epfl.xblast.SubCell; +import java.util.List; + /** * Classe abstraite utilisant tous les éléments de l'étape 1, pour essayer de * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est * pas un test unitaire, et n'a pas pour but d'être exécuté! + * + * @author EPFL */ - abstract class NameCheck01 { + void checkDirection() { Direction d = Direction.N; d = Direction.E; @@ -36,7 +38,7 @@ abstract class NameCheck01 { } void checkSubCell() { - SubCell c = SubCell.centralSubCellOf(new Cell(0,0)); + SubCell c = SubCell.centralSubCellOf(new Cell(0, 0)); c = new SubCell(0, 0); int t = c.x() + c.y() + c.distanceToCentral(); if (t < 10 && c.isCentral()) @@ -46,4 +48,5 @@ abstract class NameCheck01 { System.out.println(cc); } } + } diff --git a/test/ch/epfl/xblast/namecheck/NameCheck02.java b/test/ch/epfl/xblast/namecheck/NameCheck02.java index 978526e..47c4281 100644 --- a/test/ch/epfl/xblast/namecheck/NameCheck02.java +++ b/test/ch/epfl/xblast/namecheck/NameCheck02.java @@ -1,7 +1,5 @@ package ch.epfl.xblast.namecheck; -import java.util.List; - import ch.epfl.cs108.Sq; import ch.epfl.xblast.Cell; import ch.epfl.xblast.Lists; @@ -9,13 +7,17 @@ import ch.epfl.xblast.server.Block; import ch.epfl.xblast.server.Board; import ch.epfl.xblast.server.Ticks; +import java.util.List; + /** * Classe abstraite utilisant tous les éléments de l'étape 2, pour essayer de * garantir que ceux-ci ont le bon nom et les bons types. Attention, ceci n'est * pas un test unitaire, et n'a pas pour but d'être exécuté! + * + * @author EPFL */ - abstract class NameCheck02 { + void checkTicks() { int x = Ticks.PLAYER_DYING_TICKS + Ticks.PLAYER_INVULNERABLE_TICKS @@ -57,4 +59,5 @@ abstract class NameCheck02 { Block l = b.blockAt(c); System.out.println(bs + "/" + l); } + } diff --git a/test/ch/epfl/xblast/server/BlockTest.java b/test/ch/epfl/xblast/server/BlockTest.java index 6cfc853..31fd08a 100644 --- a/test/ch/epfl/xblast/server/BlockTest.java +++ b/test/ch/epfl/xblast/server/BlockTest.java @@ -2,13 +2,15 @@ package ch.epfl.xblast.server; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Timothée FLOURE (257420) * @author pacien TRAN-GIRARD (261948) */ public class BlockTest { + @Test public void free() { assertFalse(Block.INDESTRUCTIBLE_WALL.isFree()); @@ -32,4 +34,5 @@ public class BlockTest { assertTrue(Block.CRUMBLING_WALL.castsShadow()); assertFalse(Block.FREE.castsShadow()); } + } diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index b23ac06..5cf2aef 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -1,49 +1,50 @@ package ch.epfl.xblast.server; -import java.util.List; -import java.util.ArrayList; -import org.junit.Test; import ch.epfl.cs108.Sq; import ch.epfl.xblast.Cell; +import org.junit.Test; -import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertTrue; /** * @author Timothée FLOURE (257420) * @author Pacien TRAN-GIRARD (261948) */ public class BoardTest { - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void isBoardBuilderEmptyInputThrowingException() { List> blocks = new ArrayList<>(); new Board(blocks); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isBoardBuilderIllegalInputThrowingException() { List> blocks = new ArrayList<>(); - for (int i = 0;i<8;i++) { + for (int i = 0; i < 8; i++) { blocks.add(Sq.constant(Block.FREE)); } new Board(blocks); - } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isOfRowsEmptyInputMatrixThrowingException() { List> rowsList = new ArrayList<>(); Board.ofRows(rowsList); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isOfRowsIllegalInputThrowingException() { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0;i < 8 ;i++) { + for (int i = 0; i < 8; i++) { sampleRow.add(Block.FREE); } rowsList.add(sampleRow); @@ -53,7 +54,7 @@ public class BoardTest { @Test public void buildBoardFromRowsMatrix() { - List> rowsList = new ArrayList<>() ; + List> rowsList = new ArrayList<>(); for (int i = 0; i < 13; i++) { List sampleRow = new ArrayList<>(); @@ -66,18 +67,18 @@ public class BoardTest { assertTrue(Board.ofRows(rowsList) instanceof Board); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isOfInnerBlocksWalledEmptyInputMatrixThrowingException() { List> rowsList = new ArrayList<>(); Board.ofInnerBlocksWalled(rowsList); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isOfInnerBlocksWalledIllegalInputThrowingException() { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0;i < 8 ;i++) { + for (int i = 0; i < 8; i++) { sampleRow.add(Block.FREE); } rowsList.add(sampleRow); @@ -87,31 +88,31 @@ public class BoardTest { @Test public void buildBoardFromInnerBlocks() { - List> rowsList = new ArrayList<>() ; + List> rowsList = new ArrayList<>(); for (int i = 0; i < 11; i++) { List sampleRow = new ArrayList<>(); for (int j = 0; j < 13; j++) { - sampleRow.add(Block.FREE); + sampleRow.add(Block.FREE); } - rowsList.add(sampleRow); + rowsList.add(sampleRow); } assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isBuildWithEmptyQuadrantThrowingException() { List> rowsList = new ArrayList<>(); Board.ofQuadrantNWBlocksWalled(rowsList); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void isBuildWithIllegalQuadrantThrowingException() { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0;i < 8 ;i++) { + for (int i = 0; i < 8; i++) { sampleRow.add(Block.FREE); } rowsList.add(sampleRow); @@ -121,14 +122,14 @@ public class BoardTest { @Test public void buildBoardFromNWQuadrant() { - List> rowsList = new ArrayList<>() ; + List> rowsList = new ArrayList<>(); for (int i = 0; i < 6; i++) { List sampleRow = new ArrayList<>(); for (int j = 0; j < 7; j++) { - sampleRow.add(Block.FREE); + sampleRow.add(Block.FREE); } - rowsList.add(sampleRow); + rowsList.add(sampleRow); } assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); @@ -136,8 +137,8 @@ public class BoardTest { @Test public void isBlockAtReturningTheRightBlock() { - Cell sampleCell = new Cell(0,0); - Cell sampleCell2 = new Cell(3,4); + Cell sampleCell = new Cell(0, 0); + Cell sampleCell2 = new Cell(3, 4); List> blocksList = new ArrayList<>(); -- cgit v1.2.3 From e80fc8044f9628c4d8d246eb764cb83a64f8d5dc Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 1 Mar 2016 18:36:32 +0100 Subject: Automatic code cleanup --- test/ch/epfl/xblast/server/BoardTest.java | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 5cf2aef..014bd17 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -26,9 +26,8 @@ public class BoardTest { public void isBoardBuilderIllegalInputThrowingException() { List> blocks = new ArrayList<>(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) blocks.add(Sq.constant(Block.FREE)); - } new Board(blocks); } @@ -44,9 +43,9 @@ public class BoardTest { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); assertTrue(Board.ofRows(rowsList) instanceof Board); @@ -58,9 +57,9 @@ public class BoardTest { for (int i = 0; i < 13; i++) { List sampleRow = new ArrayList<>(); - for (int j = 0; j < 15; j++) { + for (int j = 0; j < 15; j++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); } @@ -78,9 +77,9 @@ public class BoardTest { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); @@ -92,9 +91,9 @@ public class BoardTest { for (int i = 0; i < 11; i++) { List sampleRow = new ArrayList<>(); - for (int j = 0; j < 13; j++) { + for (int j = 0; j < 13; j++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); } @@ -112,9 +111,9 @@ public class BoardTest { List> rowsList = new ArrayList<>(); List sampleRow = new ArrayList<>(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 8; i++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); @@ -126,9 +125,9 @@ public class BoardTest { for (int i = 0; i < 6; i++) { List sampleRow = new ArrayList<>(); - for (int j = 0; j < 7; j++) { + for (int j = 0; j < 7; j++) sampleRow.add(Block.FREE); - } + rowsList.add(sampleRow); } @@ -143,9 +142,9 @@ public class BoardTest { List> blocksList = new ArrayList<>(); blocksList.add(Sq.constant(Block.INDESTRUCTIBLE_WALL)); - for (int i = 0; i < 194; i++) { + for (int i = 0; i < 194; i++) blocksList.add(Sq.constant(Block.FREE)); - } + Board sampleBoard = new Board(blocksList); assertTrue(sampleBoard.blockAt(sampleCell) == Block.INDESTRUCTIBLE_WALL); -- cgit v1.2.3 From cc88afb9fe448b759966e94b07692fb6a154b2bf Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 1 Mar 2016 18:41:39 +0100 Subject: Disambiguate test assertions --- test/ch/epfl/xblast/server/BoardTest.java | 68 ++++++++++++++++++------------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/server/BoardTest.java b/test/ch/epfl/xblast/server/BoardTest.java index 014bd17..a7794d1 100644 --- a/test/ch/epfl/xblast/server/BoardTest.java +++ b/test/ch/epfl/xblast/server/BoardTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Timothée FLOURE (257420) @@ -48,22 +48,26 @@ public class BoardTest { rowsList.add(sampleRow); - assertTrue(Board.ofRows(rowsList) instanceof Board); + Board.ofRows(rowsList); } @Test public void buildBoardFromRowsMatrix() { - List> rowsList = new ArrayList<>(); + try { + List> rowsList = new ArrayList<>(); - for (int i = 0; i < 13; i++) { - List sampleRow = new ArrayList<>(); - for (int j = 0; j < 15; j++) - sampleRow.add(Block.FREE); + for (int i = 0; i < 13; i++) { + List sampleRow = new ArrayList<>(); + for (int j = 0; j < 15; j++) + sampleRow.add(Block.FREE); - rowsList.add(sampleRow); - } + rowsList.add(sampleRow); + } - assertTrue(Board.ofRows(rowsList) instanceof Board); + assertNotNull(Board.ofRows(rowsList)); + } catch (Exception e) { + fail(e.getMessage()); + } } @Test(expected = IllegalArgumentException.class) @@ -82,22 +86,26 @@ public class BoardTest { rowsList.add(sampleRow); - assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + Board.ofInnerBlocksWalled(rowsList); } @Test public void buildBoardFromInnerBlocks() { - List> rowsList = new ArrayList<>(); + try { + List> rowsList = new ArrayList<>(); - for (int i = 0; i < 11; i++) { - List sampleRow = new ArrayList<>(); - for (int j = 0; j < 13; j++) - sampleRow.add(Block.FREE); + for (int i = 0; i < 11; i++) { + List sampleRow = new ArrayList<>(); + for (int j = 0; j < 13; j++) + sampleRow.add(Block.FREE); - rowsList.add(sampleRow); - } + rowsList.add(sampleRow); + } - assertTrue(Board.ofInnerBlocksWalled(rowsList) instanceof Board); + assertNotNull(Board.ofInnerBlocksWalled(rowsList)); + } catch (Exception e) { + fail(e.getMessage()); + } } @Test(expected = IllegalArgumentException.class) @@ -116,22 +124,26 @@ public class BoardTest { rowsList.add(sampleRow); - assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + Board.ofQuadrantNWBlocksWalled(rowsList); } @Test public void buildBoardFromNWQuadrant() { - List> rowsList = new ArrayList<>(); + try { + List> rowsList = new ArrayList<>(); - for (int i = 0; i < 6; i++) { - List sampleRow = new ArrayList<>(); - for (int j = 0; j < 7; j++) - sampleRow.add(Block.FREE); + for (int i = 0; i < 6; i++) { + List sampleRow = new ArrayList<>(); + for (int j = 0; j < 7; j++) + sampleRow.add(Block.FREE); - rowsList.add(sampleRow); - } + rowsList.add(sampleRow); + } - assertTrue(Board.ofQuadrantNWBlocksWalled(rowsList) instanceof Board); + assertNotNull(Board.ofQuadrantNWBlocksWalled(rowsList)); + } catch (Exception e) { + fail(e.getMessage()); + } } @Test -- cgit v1.2.3