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
25 changes: 23 additions & 2 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package debug;


import java.util.Arrays;

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

Expand All @@ -11,6 +13,8 @@ public ContainerArray () {
}

public ContainerArray (int initialCapacity) {

capacity = initialCapacity;
internalArray = new Object[initialCapacity];
}

Expand All @@ -23,9 +27,26 @@ public int size () {
}

public void remove (E objectToRemove) {
currentSize--;
for (int i = 0; i < currentSize; i++){
if (get(i).equals(objectToRemove)){
internalArray = concatArray(capacity, Arrays.copyOfRange(internalArray,0,i),Arrays.copyOfRange(internalArray,i+1,currentSize));
currentSize--;
i--;
}
}
}

private Object[] concatArray(int size, Object[] a1, Object[] a2){
Object[] arr = new Object[size];
int i;
for (i = 0; i < a1.length; i++){
arr[i] = a1[i];
}
for (int j = 0; j < a2.length; j++){
arr[i++] = a2[j];
}
return arr;
}
@SuppressWarnings("unchecked")
public E get (int index) {
return (E)internalArray[index];
Expand Down
24 changes: 24 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Test;



public class ContainerArrayTest {
private ContainerArray<String> myContainer = null;

Expand Down Expand Up @@ -44,4 +45,27 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

@Test
public void testIfRemoveTwiceFails(){
myContainer.add("Alligator");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Size should be 1", 1, myContainer.size());
}
@Test
public void testIfAllObjectsAreRemoved(){
myContainer.add("Alligator");
myContainer.add("Alligator");
myContainer.remove("Alligator");
assertEquals("Array should have no elements", 0, myContainer.size());
}
@Test
public void testIfObjectIsRemoved(){
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Remove element", "Bear", myContainer.get(0));
}
}
41 changes: 41 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tdd;

import java.util.HashMap;

/**
* Created by aamir on 4/7/2016.
*/
public class Sheet{
private HashMap<String,String> map;

public Sheet(){
map = new HashMap<>();
}
public void put(String key, String val){
map.put(key,val);
}

public String get(String key){
String value = map.get(key);
if (isNumeric(key.trim())){
return key.trim();
}
return key;
}

public String getLiteral(String key){
return map.get(key);
}
private boolean isNumeric(String str)
{
try
{
double d = Double.parseDouble(str);
}
catch(NumberFormatException nfe)
{
return false;
}
return true;
}
}
90 changes: 90 additions & 0 deletions src/tdd/Tests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package tdd;
import static org.junit.Assert.*;

/**
* Created by aamir on 4/7/2016.
*/
public class Tests {
public void testThatCellsAreEmptyByDefault() {
Sheet sheet = new Sheet();
assertEquals("", sheet.get("A1"));
assertEquals("", sheet.get("ZX347"));
}

// Implement each test before going to the next one.

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

// Implement each test before going to the next one; then refactor.

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


// Implement each test before going to the next one.
// You can split this test case if it helps.

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

// Refactor before going to each succeeding test.

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


// We'll talk about "get" and formulas next time.
}
7 changes: 7 additions & 0 deletions src/voogasalad/Tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Possible Tests for VoogaSalad

The tests that we wanted to implement, once our code is refactored and working, are as follows:

1. Test if, when a user adds a unit, it is represented correctly. And if you change the image of a unit, that image is properly stored in its object.

2. Test if a unit's default abilities can be changed several times, i.e. if I set the default offensive ability as convert, then attack, that the default abilities properly represent that even after changing it real time.