Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
22 changes: 17 additions & 5 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package debug;

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class ContainerArray<E> {
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) {
Expand All @@ -23,11 +27,19 @@ public int size () {
}

public void remove (E objectToRemove) {
currentSize--;
List<E> myList = new ArrayList<E> (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<String> myContainer = new ContainerArray<>();
myContainer.add("test");
myContainer.remove("test");
}
}
13 changes: 12 additions & 1 deletion src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@

public class ContainerArrayTest {
private ContainerArray<String> 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
Expand Down
23 changes: 23 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tdd;

import java.util.HashMap;
import java.util.Map;


public class Sheet {
public Map<String, String> 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);
}
}
84 changes: 84 additions & 0 deletions src/tdd/TestSheet.java
Original file line number Diff line number Diff line change
@@ -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));
}



}