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..ec4e9d7 100755 --- a/src/debug/ContainerArray.java +++ b/src/debug/ContainerArray.java @@ -2,20 +2,24 @@ public class ContainerArray { - private int initialCapacity = 10; + private static final int LIMIT = 10; private int currentSize = 0; private Object[] internalArray; public ContainerArray () { - this(10); + this(LIMIT); } public ContainerArray (int initialCapacity) { internalArray = new Object[initialCapacity]; + for(int i = 0; i < internalArray.length; i++) + internalArray[i] = "empty"; } - public void add (E element) { + public String add (E element) { + if(currentSize >= LIMIT) return "is full"; internalArray[currentSize++] = element; + return "added"; } public int size () { @@ -23,11 +27,20 @@ public int size () { } public void remove (E objectToRemove) { + int idx =0; + for(Object e: internalArray) { + if(e.equals(objectToRemove)){ + internalArray[idx] = "empty"; + } + idx++; + } currentSize--; } @SuppressWarnings("unchecked") public E get (int index) { + if(index > LIMIT || index < 0) + return (E) "out of bounds"; return (E)internalArray[index]; } } diff --git a/src/debug/ContainerArrayTest.java b/src/debug/ContainerArrayTest.java index c566d50..bf62805 100755 --- a/src/debug/ContainerArrayTest.java +++ b/src/debug/ContainerArrayTest.java @@ -44,4 +44,66 @@ public void testObjectIsRemoved () { myContainer.remove("Bear"); assertEquals("Remove should be same reference", alligator, myContainer.get(0)); } + + @Test + public void testObjectInBounds(){ + String alligator = "Alligator"; + myContainer.add("Alligator"); + myContainer.add("Bear"); + assertEquals("Array out of bounds ", "out of bounds", myContainer.get(11)); + } + + @Test + public void testObjectWithinBounds(){ + String alligator = "Alligator"; + myContainer.add("Alligator"); + myContainer.add("Bear"); + assertEquals("Array in of bounds ", "empty", myContainer.get(2)); + } + + @Test + public void testObjectRemoved(){ + String alligator = "Alligator"; + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.remove(alligator); + assertEquals("Is the object removed ", "empty", myContainer.get(0)); + } + + @Test + public void testContainerFull(){ + String alligator = "Alligator"; + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + assertEquals("Is container full", "is full", myContainer.add("To many")); + } + + @Test + public void testSizeGreaterThanLimit(){ + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + myContainer.add("Bear"); + myContainer.add("Deer"); + myContainer.add("Alligator"); + assertEquals("is the size increasing if full", 10, myContainer.size()); + } + + } diff --git a/src/tdd/Algorithm.java b/src/tdd/Algorithm.java new file mode 100644 index 0000000..9b11738 --- /dev/null +++ b/src/tdd/Algorithm.java @@ -0,0 +1,27 @@ +package tdd; + +public class Algorithm { + + public Algorithm() { + // TODO Auto-generated constructor stub + } + + public String checkValue(String value){ + String temp = value.trim(); + if(temp.matches("-?\\d+(\\.\\d+)?")){ + return temp; + } else { + return value; + } + } + + public static void main(String[] args){ + Algorithm a = new Algorithm(); + String input = " 1345 "; + String input2 = " 99 X"; + String input3 = " "; + String input4 = "1234"; + System.out.println(a.checkValue(input4)); + } + +} diff --git a/src/tdd/Cell.java b/src/tdd/Cell.java new file mode 100644 index 0000000..8533930 --- /dev/null +++ b/src/tdd/Cell.java @@ -0,0 +1,28 @@ +package tdd; + +public class Cell { + + private String name; + private String value; + private String literal; + Algorithm alg = new Algorithm(); + + public Cell(String name, String value) { + this.name = name; + this.literal = value; + this.value = alg.checkValue(value); + } + + public String getName(){ + return name; + } + + public String getLiteral(){ + return literal; + } + + public String getValue(){ + return value; + } + +} diff --git a/src/tdd/Sheet.java b/src/tdd/Sheet.java new file mode 100644 index 0000000..95701a6 --- /dev/null +++ b/src/tdd/Sheet.java @@ -0,0 +1,38 @@ +package tdd; + +import java.util.HashMap; +import java.util.Map; + +public class Sheet { + + private Map map; + + public Sheet() { + map = new HashMap(); + } + + public String get(String input) { + Cell val = map.get(input); + if(val == null) return ""; + return val.getValue(); + } + + public void put(String name, String value) { + Cell n = new Cell(name, value); + map.put(name, n); + } + + public String getLiteral(String theCell) { + return map.get(theCell).getLiteral(); + } + + public static void main(String[] args){ + Sheet s = new Sheet(); + String theCell = "A21"; + + s.put(theCell, "Some string"); + String v = s.getLiteral(theCell); + System.out.println(v); + } + +} diff --git a/src/tdd/TestSheet.java b/src/tdd/TestSheet.java new file mode 100644 index 0000000..28bc254 --- /dev/null +++ b/src/tdd/TestSheet.java @@ -0,0 +1,84 @@ +package tdd; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestSheet { + + @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/GAETest.java b/src/voogasalad/GAETest.java new file mode 100644 index 0000000..3e45309 --- /dev/null +++ b/src/voogasalad/GAETest.java @@ -0,0 +1,66 @@ +package voogasalad; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import backend.FrontEndGameAuthoringEnvironment; + +public class GAETest { + + /** + *////////////////////////////////////////////////////////////////////////////// + *///////////////////GameAuthoringEnvirornment Tester////////////////////////////////////////// + *////////////////////////////////////////////////////////////////////////////// + */ + + @Test + public void testCreateGameObject() { + GameAuthoringEnvironment gae = new GameAuthoringEnvironment(); + GameObject trump = new GameObject(); + assertEquals("is game object created", trump, gae.createGameObject()); + } + + @Test + public void testSetGameObjectWithMockData(){ + FrontEndGameAuthoringEnvironment mockData = FrontEndGameAuthoringEnvironment(); + mockData.createModes( new { + levels = 5, + levels = 4, + levels = 2, + }); + GameAuthoringEnvironment gae = new GameAuthoringEnvironment(); + GameObject trump = new GameObject(mockData); + assertEquals("is game object created", trump, gae.createGameObject(mockData)); + } + + /** + *////////////////////////////////////////////////////////////////////////////// + *///////////////////GameObject Tester////////////////////////////////////////// + *////////////////////////////////////////////////////////////////////////////// + */ + + @Test + public void testInitGameObject() { + GameObject trump = new GameObject(); + int numModes = 1; + int numLevels = 3; + trump.initializeGameObject(numModes, numLevels) + assertEquals("is game object created with right num of modes", numModes, trump.getModes()); + assertEquals("is game object created with right num of levels", numLevels, trump.getLevelsForMode(trump.getModes().get(0))); + } + + @Test + public void testNewLevelToCurrentMode() { + GameObject trump = new GameObject(); + int numModes = 1; + int numLevels = 3; + trump.initializeGameObject(numModes, numLevels); + trump.addNewLevelToCurrentMode(trump.getModes().get(0)); + + assertEquals("did the game object add another level to current mode", numLevels + 1, trump.getLevelsForMode(trump.getModes().get(0))); + + + } + +}