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

import java.util.ArrayList;

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

internalArray[currentSize++] = element;
}

Expand All @@ -23,11 +26,28 @@ public int size () {
}

public void remove (E objectToRemove) {
currentSize--;
ArrayList<E> values = new ArrayList<E>();
for(int i = 0; i < internalArray.length; i++){
if(!this.get(i).equals(objectToRemove)){
values.add(this.get(i));
}
}
currentSize = values.size();
internalArray = (Object[]) values.toArray();
}


@SuppressWarnings("unchecked")
public E get (int index) {
return (E)internalArray[index];
}

public boolean contains(E objectToRemove){
for(int i = 0; i < internalArray.length;i++){
if(objectToRemove.equals(this.get(i))){
return true;
}
}
return false;
}
}
8 changes: 8 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

@Test
public void testObjectRemovedFromContainer () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Alligator should be removed", false, myContainer.contains("Alligator"));
}
}
44 changes: 44 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tdd;

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

public class Sheet {

Map<String, String> mySheet = new HashMap<String, String>();
Map<String, String> myLiteralSheet = new HashMap<String, String>();

public String get (String string) {
// TODO Auto-generated method stub
if(mySheet.containsKey(string)){
return mySheet.get(string);
}
else{
return "";
}
}

public void put (String theCell, String string) {
// TODO Auto-generated method stub
String myString = string;
myLiteralSheet.put(theCell, string);
try{
Double num = Double.parseDouble(string.trim());
myString = string.trim();
}
catch (NumberFormatException error){
//do nothing
}
mySheet.put(theCell, myString);
}

public Object getLiteral (String theCell) {
if(mySheet.containsKey(theCell)){
return myLiteralSheet.get(theCell);
}
else{
return "";
}
}

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

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

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

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

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


// Refactor before going to each succeeding test.
@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));
}

@Test
public void testFormulaSpec() {
Sheet sheet = new Sheet();
sheet.put("B1", " =7"); // note leading space
assertEquals("Not a formula", " =7", sheet.get("B1"));
assertEquals("Unchanged", " =7", sheet.getLiteral("B1"));
}

@Test
public void testConstantFormula() {
Sheet sheet = new Sheet();
sheet.put("A1", "=7");
assertEquals("Formula", "=7", sheet.getLiteral("A1"));
assertEquals("Value", "7", sheet.get("A1"));
}

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

import static org.junit.Assert.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import engine.ISprite;
import engine.Sprite;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
*
* @author Dhrumil and Jeremy
*
* jes85 and drp18
*
*/
public class TestCreation {

private CreationController<ISprite> myCreationController;
private ObservableList<ISprite> myCreationControllerItems;
private ISprite myCreationControllerCurrentItem;

@Before
public void setup () {
myCreationController = new CreationController<ISprite>();

try{
Field itemsField = CreationController.class.getDeclaredField("myItems");
itemsField.setAccessible(true);
myCreationControllerItems = (ObservableList<ISprite>) itemsField.get(myCreationController);


Field currentItemField = CreationController.class.getDeclaredField("myCurrentItem");
currentItemField.setAccessible(true);
myCreationControllerCurrentItem = (ISprite) itemsField.get(myCreationController);


}catch (Exception e) {
assert(false);
}

myCreationControllerCurrentItem = new Sprite();
myCreationControllerItems = FXCollections.observableArrayList();

/*
ISprite sprite1 = new Sprite();
ISprite sprite2 = new Sprite();
spriteList.add(sprite1);
spriteList.add(sprite2);

myCreationController.setItems(spriteList);
*/
}

@Test
public void testDeletion () {
myCreationControllerItems.add(myCreationControllerCurrentItem);

try {
Method deleteMethod = CreationController.class.getDeclaredMethod("deleteItem");
deleteMethod.setAccessible(true);

assertEquals(myCreationControllerItems.contains(myCreationControllerCurrentItem), true);
deleteMethod.invoke(myCreationController);
assertEquals(myCreationControllerItems.contains(myCreationControllerCurrentItem), false);

} catch (Exception e) {
assert(false);
}


}

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

import static org.junit.Assert.*;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import modules.IMovementModule;
import modules.UserControlledMover;
import util.ControlKeys;
import util.Coordinate;
import util.Key;
import util.TimeDuration;

/**
*
* @author Dhrumil and Jeremy
*
* jes85 and drp18
*
*/

public class TestSprite {

private ISprite sprite = new Sprite();


@Before
public void setUp () {

ControlKeys keys = new ControlKeys(new Key("Up"), new Key("Left"), new Key("Right"), new Key("Down"));
ObjectProperty<IMovementModule> mover = new SimpleObjectProperty<>(new UserControlledMover(10, keys, sprite));

try {
Method goRight = mover.get().getClass().getDeclaredMethod("goRight");
goRight.setAccessible(true);
goRight.invoke(mover.get());
}
catch (Exception e) {
assert(false);
return;
}

TimeDuration time = new TimeDuration(100.0);
sprite.getMovementStrategyProperty().set(mover.get());
mover.get().update(time);

}

@Test
public void test () {
Coordinate myCoordinate = new Coordinate(1000.0, 0.0);

assertEquals("XPos of Sprite", myCoordinate.getX(), sprite.getLocation().get().getX(), 0);
assertEquals("YPos of Sprite", myCoordinate.getY(), sprite.getLocation().get().getY(), 0);
}

}