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..53ef641 100755
--- a/src/debug/ContainerArray.java
+++ b/src/debug/ContainerArray.java
@@ -1,17 +1,21 @@
package debug;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import java.util.List;
public class ContainerArray {
- private int initialCapacity = 10;
+ private int limit = 10;
private int currentSize = 0;
- private Object[] internalArray;
+ private E[] internalArray;
public ContainerArray () {
this(10);
}
public ContainerArray (int initialCapacity) {
- internalArray = new Object[initialCapacity];
+ internalArray = (E[]) new Object[initialCapacity];
}
public void add (E element) {
@@ -23,11 +27,19 @@ public int size () {
}
public void remove (E objectToRemove) {
- currentSize--;
+ List myList = new ArrayList (Arrays.asList(this.internalArray));
+ if(myList.remove(objectToRemove)) currentSize--;
+ this.internalArray = (E[]) myList.toArray();
}
@SuppressWarnings("unchecked")
public E get (int index) {
- return (E)internalArray[index];
+ return internalArray[index];
+ }
+
+ public static void main (String[] args) {
+ ContainerArray myContainer = new ContainerArray<>();
+ myContainer.add("test");
+ myContainer.remove("test");
}
}
diff --git a/src/debug/ContainerArrayTest.java b/src/debug/ContainerArrayTest.java
index c566d50..a8f14df 100755
--- a/src/debug/ContainerArrayTest.java
+++ b/src/debug/ContainerArrayTest.java
@@ -7,10 +7,21 @@
public class ContainerArrayTest {
private ContainerArray myContainer = null;
-
+
@Before
public void setUp () {
myContainer = new ContainerArray<>();
+
+ }
+
+ @Test
+ public void testRemove() {
+ String alligator = "Alligator";
+ String bear = "Bear";
+ myContainer.add(alligator);
+ myContainer.add(bear);
+ myContainer.remove(alligator);
+ assertEquals("Remove should be different reference", bear, myContainer.get(0));
}
@Test
diff --git a/src/tdd/Sheet.java b/src/tdd/Sheet.java
new file mode 100644
index 0000000..47690ed
--- /dev/null
+++ b/src/tdd/Sheet.java
@@ -0,0 +1,23 @@
+package tdd;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Sheet {
+ public Map myMap = new HashMap<>();
+
+ public String get(String string) {
+ return myMap.get(string) == null? "" : myMap.get(string);
+ }
+
+ public void put(String key, String value) {
+ try {
+ Integer.parseInt(value);
+ value = value.trim();
+ }
+ catch (Exception e) {
+ }
+ myMap.put(key, value);
+ }
+}
diff --git a/src/tdd/TestSheet.java b/src/tdd/TestSheet.java
new file mode 100644
index 0000000..53cfc7a
--- /dev/null
+++ b/src/tdd/TestSheet.java
@@ -0,0 +1,84 @@
+package tdd;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestSheet {
+
+ // TDD says you write the test first for what you want to accomplish
+
+ // First test written is simply to get your code to compile (create the class, write some methods, etc.)
+
+ private Sheet mySheet;
+
+ // Initial setup with @Before
+ @Before
+ public void setUp() {
+ mySheet = new Sheet();
+ }
+
+ @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));
+ }
+
+
+
+}