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') 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