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
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?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="output" path="bin"/>
</classpath>
38 changes: 32 additions & 6 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,59 @@
package debug;


public class ContainerArray<E> {
private int initialCapacity = 10;
private int currentSize = 0;
private static final int INITIAL_CAPACITY = 10;
private int capacity;
private Object[] internalArray;

public ContainerArray () {
this(10);
this(INITIAL_CAPACITY);
}

public ContainerArray (int initialCapacity) {
internalArray = new Object[initialCapacity];
capacity = initialCapacity;
}

public void add (E element) {
internalArray[currentSize++] = element;
Object[] newInternalArray = new Object[capacity * 2];
if ((currentSize + 1) > capacity) {
for (int i = 0; i < capacity; i++) {
newInternalArray[i] = internalArray[i];
}
capacity = capacity * 2;
newInternalArray[currentSize++] = element;
internalArray = newInternalArray;
}
else {
internalArray[currentSize++] = element;
}
}

public int size () {
return currentSize;
}

public void remove (E objectToRemove) {
currentSize--;
for (int i = 0; i < currentSize; i++) {
if (internalArray[i].equals(objectToRemove)) {
for (int j = i; j < currentSize - 1; j++) {
internalArray[j] = internalArray[j + 1];
}
i--;
currentSize--;
}
}
//Does not remove object from internalArray
//currentSize needs to be decremented as many times as there are objectToRemove's
}

@SuppressWarnings("unchecked")
public E get (int index) {
return (E)internalArray[index];
//Does not check if index is out of bounds
if (index > currentSize) {
return null;
}
return (E) internalArray[index];
}
}
24 changes: 24 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,28 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

@Test
public void testSizeLimit () {
myContainer = new ContainerArray<>(1);
myContainer.add("Alligator");
myContainer.add("Bear");
}

@Test
public void testMultipleRemoves () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
myContainer.remove("Alligator");
assertEquals("Remove size", 1, myContainer.size());
}

@Test
public void testRemovesAll () {
myContainer.add("Alligator");
myContainer.add("Alligator");
myContainer.remove("Alligator");
assertEquals("Removes all", 0, myContainer.size());
}
}
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 {
HashMap<String, String> myMap = new HashMap<String, String>();

public void put (String key, String val) {
myMap.put(key, val);
}

public String get (String key) {
String val = myMap.get(key);
String[] valueArray = val.split(" ");
if (valueArray.length != 1) {
return val;
}
else if (isNumeric(valueArray[0])) {
return val.trim();
}
else {
return val;
}
}

public String getLiteral (String key) {
return myMap.get(key);
}

public boolean isNumeric(String s) {
return s.matches("-?\\d+(\\.\\d+)?");
}
}
6 changes: 6 additions & 0 deletions src/voogasalad/Tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Tests for VOOGASalad
====================

1. Test that user input to authoring environment text fields is transferred over to data files accurately.

2. Test that whenever the user clicks on a unit it is set as the selected unit.