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


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

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

public ContainerArray (int initialCapacity) {
internalArray = new Object[initialCapacity];
for(int i = 0; i < internalArray.length; i++)
internalArray[i] = "empty";
}

public void add (E element) {
public String add (E element) {
if(currentSize >= LIMIT) return "is full";
internalArray[currentSize++] = element;
return "added";
}

public int size () {
return currentSize;
}

public void remove (E objectToRemove) {
int idx =0;
for(Object e: internalArray) {
if(e.equals(objectToRemove)){
internalArray[idx] = "empty";
}
idx++;
}
currentSize--;
}

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

@Test
public void testObjectInBounds(){
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
assertEquals("Array out of bounds ", "out of bounds", myContainer.get(11));
}

@Test
public void testObjectWithinBounds(){
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
assertEquals("Array in of bounds ", "empty", myContainer.get(2));
}

@Test
public void testObjectRemoved(){
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.remove(alligator);
assertEquals("Is the object removed ", "empty", myContainer.get(0));
}

@Test
public void testContainerFull(){
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
assertEquals("Is container full", "is full", myContainer.add("To many"));
}

@Test
public void testSizeGreaterThanLimit(){
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Deer");
myContainer.add("Alligator");
assertEquals("is the size increasing if full", 10, myContainer.size());
}


}
27 changes: 27 additions & 0 deletions src/tdd/Algorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tdd;

public class Algorithm {

public Algorithm() {
// TODO Auto-generated constructor stub
}

public String checkValue(String value){
String temp = value.trim();
if(temp.matches("-?\\d+(\\.\\d+)?")){
return temp;
} else {
return value;
}
}

public static void main(String[] args){
Algorithm a = new Algorithm();
String input = " 1345 ";
String input2 = " 99 X";
String input3 = " ";
String input4 = "1234";
System.out.println(a.checkValue(input4));
}

}
28 changes: 28 additions & 0 deletions src/tdd/Cell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tdd;

public class Cell {

private String name;
private String value;
private String literal;
Algorithm alg = new Algorithm();

public Cell(String name, String value) {
this.name = name;
this.literal = value;
this.value = alg.checkValue(value);
}

public String getName(){
return name;
}

public String getLiteral(){
return literal;
}

public String getValue(){
return value;
}

}
38 changes: 38 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tdd;

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

public class Sheet {

private Map<String, Cell> map;

public Sheet() {
map = new HashMap<String, Cell>();
}

public String get(String input) {
Cell val = map.get(input);
if(val == null) return "";
return val.getValue();
}

public void put(String name, String value) {
Cell n = new Cell(name, value);
map.put(name, n);
}

public String getLiteral(String theCell) {
return map.get(theCell).getLiteral();
}

public static void main(String[] args){
Sheet s = new Sheet();
String theCell = "A21";

s.put(theCell, "Some string");
String v = s.getLiteral(theCell);
System.out.println(v);
}

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

public class TestSheet {

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

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

}
66 changes: 66 additions & 0 deletions src/voogasalad/GAETest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package voogasalad;

import static org.junit.Assert.*;

import org.junit.Test;

import backend.FrontEndGameAuthoringEnvironment;

public class GAETest {

/**
*//////////////////////////////////////////////////////////////////////////////
*///////////////////GameAuthoringEnvirornment Tester//////////////////////////////////////////
*//////////////////////////////////////////////////////////////////////////////
*/

@Test
public void testCreateGameObject() {
GameAuthoringEnvironment gae = new GameAuthoringEnvironment();
GameObject trump = new GameObject();
assertEquals("is game object created", trump, gae.createGameObject());
}

@Test
public void testSetGameObjectWithMockData(){
FrontEndGameAuthoringEnvironment mockData = FrontEndGameAuthoringEnvironment();
mockData.createModes( new {
levels = 5,
levels = 4,
levels = 2,
});
GameAuthoringEnvironment gae = new GameAuthoringEnvironment();
GameObject trump = new GameObject(mockData);
assertEquals("is game object created", trump, gae.createGameObject(mockData));
}

/**
*//////////////////////////////////////////////////////////////////////////////
*///////////////////GameObject Tester//////////////////////////////////////////
*//////////////////////////////////////////////////////////////////////////////
*/

@Test
public void testInitGameObject() {
GameObject trump = new GameObject();
int numModes = 1;
int numLevels = 3;
trump.initializeGameObject(numModes, numLevels)
assertEquals("is game object created with right num of modes", numModes, trump.getModes());
assertEquals("is game object created with right num of levels", numLevels, trump.getLevelsForMode(trump.getModes().get(0)));
}

@Test
public void testNewLevelToCurrentMode() {
GameObject trump = new GameObject();
int numModes = 1;
int numLevels = 3;
trump.initializeGameObject(numModes, numLevels);
trump.addNewLevelToCurrentMode(trump.getModes().get(0));

assertEquals("did the game object add another level to current mode", numLevels + 1, trump.getLevelsForMode(trump.getModes().get(0)));


}

}