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..455ea8f 100755
--- a/src/debug/ContainerArray.java
+++ b/src/debug/ContainerArray.java
@@ -2,7 +2,7 @@
public class ContainerArray {
- private int initialCapacity = 10;
+ private int limit = 10;
private int currentSize = 0;
private Object[] internalArray;
@@ -10,11 +10,15 @@ public ContainerArray () {
this(10);
}
- public ContainerArray (int initialCapacity) {
- internalArray = new Object[initialCapacity];
+ public ContainerArray (int limit) {
+ internalArray = new Object[limit];
}
public void add (E element) {
+ if(currentSize == limit) {
+ limit *= 2;
+ internalArray = new Object[limit];
+ }
internalArray[currentSize++] = element;
}
@@ -23,8 +27,18 @@ public int size () {
}
public void remove (E objectToRemove) {
+ for(int i=0;i();
+ myContainer = new ContainerArray();
+ }
+
+ @Test
+ public void testSizeLimit() {
+ for(int i = 0; i < 11; i++) {
+ myContainer.add(i + "TapDancers");
+ }
}
@Test
@@ -44,4 +51,13 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}
+ @Test
+ public void testObjectProperlyRemoved(){
+ String alligator = "Alligator";
+ myContainer.add("Alligator");
+ myContainer.add("Bear");
+ myContainer.add("Deer");
+ myContainer.remove("Alligator");
+ assertEquals("Remove should be same reference","Bear", myContainer.get(0));
+ }
}
diff --git a/src/tdd/Sheet.java b/src/tdd/Sheet.java
new file mode 100644
index 0000000..00319d2
--- /dev/null
+++ b/src/tdd/Sheet.java
@@ -0,0 +1,33 @@
+package tdd;
+
+import java.util.HashMap;
+
+public class Sheet {
+ private HashMap myMap;
+ public Sheet() {
+ // TODO Auto-generated constructor stub
+ myMap=new HashMap();
+ }
+ public String get(String string) {
+ if(myMap.get(string)==null){
+ return "";
+ }
+ try{
+ String copy = "" + myMap.get(string);
+ copy = copy.trim();
+ Integer.parseInt(copy);
+ return copy;
+ } catch (Exception e) {
+ return myMap.get(string);
+ }
+ }
+
+ public void put(String key, String value){
+ myMap.put(key, value);
+ }
+
+ public String getLiteral(String key) {
+ return myMap.get(key);
+ }
+
+}
diff --git a/src/tdd/TestSheet.java b/src/tdd/TestSheet.java
new file mode 100644
index 0000000..7461f96
--- /dev/null
+++ b/src/tdd/TestSheet.java
@@ -0,0 +1,85 @@
+package tdd;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestSheet {
+
+ @Test
+ public void test() {
+ testThatCellsAreEmptyByDefault();
+ testThatTextCellsAreStored();
+ testThatManyCellsExist();
+ testThatNumericCellsAreIdentifiedAndStored();
+ testThatWeHaveAccessToCellLiteralValuesForEditing();
+ }
+
+ public void testThatCellsAreEmptyByDefault() {
+ Sheet sheet = new Sheet();
+ assertEquals("", sheet.get("A1"));
+ assertEquals("", sheet.get("ZX347"));
+ }
+ 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));
+ }
+ 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"));
+ }
+ 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));
+ }
+
+ 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));
+ }
+
+}