diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/debug/ContainerArray.java b/src/debug/ContainerArray.java index 124ece6..810dd7b 100755 --- a/src/debug/ContainerArray.java +++ b/src/debug/ContainerArray.java @@ -1,21 +1,33 @@ package debug; - public class ContainerArray { - 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 () { @@ -23,11 +35,25 @@ public int size () { } 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]; } } diff --git a/src/debug/ContainerArrayTest.java b/src/debug/ContainerArrayTest.java index c566d50..d55f66d 100755 --- a/src/debug/ContainerArrayTest.java +++ b/src/debug/ContainerArrayTest.java @@ -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()); + } } diff --git a/src/tdd/Sheet.java b/src/tdd/Sheet.java new file mode 100644 index 0000000..8ab85c5 --- /dev/null +++ b/src/tdd/Sheet.java @@ -0,0 +1,33 @@ +package tdd; + +import java.util.HashMap; + +public class Sheet { + HashMap myMap = new HashMap(); + + 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+)?"); + } +} diff --git a/src/voogasalad/Tests b/src/voogasalad/Tests new file mode 100644 index 0000000..ecd48d2 --- /dev/null +++ b/src/voogasalad/Tests @@ -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.