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>
20 changes: 17 additions & 3 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@


public class ContainerArray<E> {
private int initialCapacity = 10;
private int limit = 10;
private int currentSize = 0;
private Object[] internalArray;

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;
}

Expand All @@ -23,8 +27,18 @@ public int size () {
}

public void remove (E objectToRemove) {
for(int i=0;i<internalArray.length;i++){
if(internalArray[i]==objectToRemove){
removeIndex(i);
}
}
currentSize--;
}
public void removeIndex(int i){
for(int j=i;j<internalArray.length-1;j++){
internalArray[j]=internalArray[j+1];
}
}

@SuppressWarnings("unchecked")
public E get (int index) {
Expand Down
18 changes: 17 additions & 1 deletion src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ public class ContainerArrayTest {

@Before
public void setUp () {
myContainer = new ContainerArray<>();
myContainer = new ContainerArray<String>();
}

@Test
public void testSizeLimit() {
for(int i = 0; i < 11; i++) {
myContainer.add(i + "TapDancers");
}
}

@Test
Expand Down Expand Up @@ -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));
}
}
33 changes: 33 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tdd;

import java.util.HashMap;

public class Sheet {
private HashMap<String, String> myMap;
public Sheet() {
// TODO Auto-generated constructor stub
myMap=new HashMap<String, String>();
}
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);
}

}
85 changes: 85 additions & 0 deletions src/tdd/TestSheet.java
Original file line number Diff line number Diff line change
@@ -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));
}

}