From 38a7eee7e9ef04053383cc8a4fc488ada7c768db Mon Sep 17 00:00:00 2001 From: MICHAEL FIGUEIRAS Date: Thu, 7 Apr 2016 17:34:28 -0400 Subject: [PATCH] mdf15 cmt57 --- .classpath | 7 +++ src/debug/ContainerArray.java | 18 +++++-- src/debug/ContainerArrayTest.java | 20 +++++++ src/tdd/Sheet.java | 58 ++++++++++++++++++++ src/tdd/TestSheet.java | 88 +++++++++++++++++++++++++++++++ src/voogasalad/Testing1.java | 57 ++++++++++++++++++++ src/voogasalad/Testing2.java | 58 ++++++++++++++++++++ 7 files changed, 302 insertions(+), 4 deletions(-) create mode 100644 .classpath create mode 100644 src/tdd/Sheet.java create mode 100644 src/tdd/TestSheet.java create mode 100644 src/voogasalad/Testing1.java create mode 100644 src/voogasalad/Testing2.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3e0fb27 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/debug/ContainerArray.java b/src/debug/ContainerArray.java index 124ece6..957d6a3 100755 --- a/src/debug/ContainerArray.java +++ b/src/debug/ContainerArray.java @@ -2,12 +2,12 @@ public class ContainerArray { - private int initialCapacity = 10; + private static int initialCapacity = 10; private int currentSize = 0; private Object[] internalArray; public ContainerArray () { - this(10); + this(initialCapacity); } public ContainerArray (int initialCapacity) { @@ -15,7 +15,9 @@ public ContainerArray (int initialCapacity) { } public void add (E element) { - internalArray[currentSize++] = element; + if(currentSize < initialCapacity) { + internalArray[currentSize++] = element; + } } public int size () { @@ -23,7 +25,15 @@ public int size () { } public void remove (E objectToRemove) { - currentSize--; + + for (int i=0; i myMap; + Map myInput; + + public Sheet() { + // TODO Auto-generated constructor stub + myMap = new HashMap(); + myInput = new HashMap(); + } + + public String get(String string){ + if(myMap.get(string) == null) return ""; + else{ + + return myMap.get(string); + } + } + + public void put(String cell, String value){ + myInput.put(cell, value); + if (isNumeric(value.trim())) + myMap.put(cell, value.trim()); + else + myMap.put(cell, value); + } + + + public String getLiteral(String key){ + return myInput.get(key); + } + private boolean isNumeric(String value){ + + if (value.equals("")) + return false; + + String numbers = "0123456789"; + + boolean numeric = true; + + for(int i=0; i < value.length(); i++) { + if (!numbers.contains(value.substring(i, i+1))) { + numeric = false; + } + } + + return numeric; + + } + + + +} diff --git a/src/tdd/TestSheet.java b/src/tdd/TestSheet.java new file mode 100644 index 0000000..e6aa1b6 --- /dev/null +++ b/src/tdd/TestSheet.java @@ -0,0 +1,88 @@ +package tdd; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestSheet { + + public TestSheet() { + // TODO Auto-generated constructor stub + } + + @Test + public void testThatCellsAreEmptyByDefault() { + Sheet sheet = new Sheet(); + assertEquals("", sheet.get("A1")); + assertEquals("", sheet.get("ZX347")); + } + + @Test + public void testThatTextCellsAreStored() { + Sheet sheet = new Sheet(); + String theCell = "A21"; + + sheet.put(theCell, "A string"); + assertEquals("A string", sheet.get(theCell)); + + sheet.put(theCell, "A different string"); + assertEquals("A different string", sheet.get(theCell)); + + sheet.put(theCell, ""); + assertEquals("", sheet.get(theCell)); + } + + @Test + public void testThatManyCellsExist() { + Sheet sheet = new Sheet(); + sheet.put("A1", "First"); + sheet.put("X27", "Second"); + sheet.put("ZX901", "Third"); + + assertEquals("A1", "First", sheet.get("A1")); + assertEquals("X27", "Second", sheet.get("X27")); + assertEquals("ZX901", "Third", sheet.get("ZX901")); + + sheet.put("A1", "Fourth"); + assertEquals("A1 after", "Fourth", sheet.get("A1")); + assertEquals("X27 same", "Second", sheet.get("X27")); + assertEquals("ZX901 same", "Third", sheet.get("ZX901")); + } + + @Test + public void testThatNumericCellsAreIdentifiedAndStored() { + Sheet sheet = new Sheet(); + String theCell = "A21"; + + sheet.put(theCell, "X99"); // "Obvious" string + assertEquals("X99", sheet.get(theCell)); + + sheet.put(theCell, "14"); // "Obvious" number + assertEquals("14", sheet.get(theCell)); + + sheet.put(theCell, " 99 X"); // Whole string must be numeric + assertEquals(" 99 X", sheet.get(theCell)); + + sheet.put(theCell, " 1234 "); // Blanks ignored + assertEquals("1234", sheet.get(theCell)); + + sheet.put(theCell, " "); // Just a blank + assertEquals(" ", sheet.get(theCell)); + } + + @Test + public void testThatWeHaveAccessToCellLiteralValuesForEditing() { + Sheet sheet = new Sheet(); + String theCell = "A21"; + + sheet.put(theCell, "Some string"); + assertEquals("Some string", sheet.getLiteral(theCell)); + + sheet.put(theCell, " 1234 "); + assertEquals(" 1234 ", sheet.getLiteral(theCell)); + + sheet.put(theCell, "=7"); // Foreshadowing formulas:) + assertEquals("=7", sheet.getLiteral(theCell)); + } + +} diff --git a/src/voogasalad/Testing1.java b/src/voogasalad/Testing1.java new file mode 100644 index 0000000..6bea77d --- /dev/null +++ b/src/voogasalad/Testing1.java @@ -0,0 +1,57 @@ +package voogasalad; + + +import static org.junit.Assert.*; + +import org.junit.Test; + + +import java.lang.reflect.InvocationTargetException; + +import org.junit.Before; + +import gameplayer.view.SplashScreen; +import javafx.scene.control.Button; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + + +/* + * This class does not compile because we had issues with testing in the lab_testing package + * so we decided to create a package within our voogasalad project called lab_testing + * that implements JUnit tests and we worked on that side. + */ + +public class Testing1 { + + private SplashScreen mySplash = null; + + public Testing1() { + // TODO Auto-generated constructor stub + } + + @Before + public void setUP(){ + mySplash = new SplashScreen(new Stage()); + } + + @Test + public void testElement(){ + try { + mySplash.setButtonsUp(new HBox()); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertEquals("Adding buttons", mySplash.getRoot().getChildren().contains(new Button())); + } + + @Test + public void testSwitch(){ + mySplash.edit(); + assertEquals("Screen switch", "GUIMain", mySplash.getClass()); + } + +} + diff --git a/src/voogasalad/Testing2.java b/src/voogasalad/Testing2.java new file mode 100644 index 0000000..21ddbf0 --- /dev/null +++ b/src/voogasalad/Testing2.java @@ -0,0 +1,58 @@ +package voogasalad; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import javafx.stage.Stage; +/* + * This class does not compile because we had issues with testing in the lab_testing package + * so we decided to create a package within our voogasalad project called lab_testing + * that implements JUnit tests and we worked on that side. + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +import org.junit.Before; +import org.junit.Test; +import org.xml.sax.SAXException; + +import gamedata.controller.CreatorController; +import gamedata.controller.ParserController; +import gameengine.controller.Game; +import gameengine.controller.GameInfo; +import gameengine.controller.Level; + +public class Testing2 { + + Game myGame; + CreatorController myCreatorController; + ParserController myParserController; + + + public Testing2() { + // TODO Auto-generated constructor stub + } + + @Before + public void initialize() { + List levels = new ArrayList<>(); + levels.add(new Level()); + myGame = new Game(null, new GameInfo(), levels); + } + + @Test + public void testCreationandParsingWorks() throws ParserConfigurationException, SAXException, IOException, TransformerException { + File f = new File("src/resources/test.xml"); + myCreatorController.saveForPlaying(f); + Game g = myParserController.loadforPlaying(f); + assertEquals("Testing parser produces game from created XML", myGame, g); + } +} +