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>
18 changes: 14 additions & 4 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@


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

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

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

public void add (E element) {
internalArray[currentSize++] = element;
if(currentSize < initialCapacity) {
internalArray[currentSize++] = element;
}
}

public int size () {
return currentSize;
}

public void remove (E objectToRemove) {
currentSize--;

for (int i=0; i<internalArray.length; i++) {
if (objectToRemove.equals(internalArray[i]))
{
internalArray[i] = null;
currentSize--;
}
}

}

@SuppressWarnings("unchecked")
Expand Down
20 changes: 20 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

@Test
public void testObjectIsRemovedCorrect() {
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Bear");
assertEquals("Remove should be same reference", null, myContainer.get(1));

}

@Test
public void testLimitsCorrect(){
for(int i = 0; i < 11; i++){
myContainer.add("test" + i);
}
assertEquals("List should have limits", 10, myContainer.size());
}


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

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

public class Sheet {

Map<String, String> myMap;
Map<String, String> myInput;

public Sheet() {
// TODO Auto-generated constructor stub
myMap = new HashMap<String, String>();
myInput = new HashMap<String, String>();
}

public String get(String string){
if(myMap.get(string) == null) return "";
else{

return myMap.get(string);
}
}

public void put(String cell, String value){
myInput.put(cell, value);
if (isNumeric(value.trim()))
myMap.put(cell, value.trim());
else
myMap.put(cell, value);
}


public String getLiteral(String key){
return myInput.get(key);
}
private boolean isNumeric(String value){

if (value.equals(""))
return false;

String numbers = "0123456789";

boolean numeric = true;

for(int i=0; i < value.length(); i++) {
if (!numbers.contains(value.substring(i, i+1))) {
numeric = false;
}
}

return numeric;

}



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

import static org.junit.Assert.*;

import org.junit.Test;

public class TestSheet {

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

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

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


import static org.junit.Assert.*;

import org.junit.Test;


import java.lang.reflect.InvocationTargetException;

import org.junit.Before;

import gameplayer.view.SplashScreen;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;


/*
* This class does not compile because we had issues with testing in the lab_testing package
* so we decided to create a package within our voogasalad project called lab_testing
* that implements JUnit tests and we worked on that side.
*/

public class Testing1 {

private SplashScreen mySplash = null;

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

@Before
public void setUP(){
mySplash = new SplashScreen(new Stage());
}

@Test
public void testElement(){
try {
mySplash.setButtonsUp(new HBox());
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertEquals("Adding buttons", mySplash.getRoot().getChildren().contains(new Button()));
}

@Test
public void testSwitch(){
mySplash.edit();
assertEquals("Screen switch", "GUIMain", mySplash.getClass());
}

}

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

import static org.junit.Assert.*;

import org.junit.Test;

import javafx.stage.Stage;
/*
* This class does not compile because we had issues with testing in the lab_testing package
* so we decided to create a package within our voogasalad project called lab_testing
* that implements JUnit tests and we worked on that side.
*/

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;

import gamedata.controller.CreatorController;
import gamedata.controller.ParserController;
import gameengine.controller.Game;
import gameengine.controller.GameInfo;
import gameengine.controller.Level;

public class Testing2 {

Game myGame;
CreatorController myCreatorController;
ParserController myParserController;


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

@Before
public void initialize() {
List<Level> levels = new ArrayList<>();
levels.add(new Level());
myGame = new Game(null, new GameInfo(), levels);
}

@Test
public void testCreationandParsingWorks() throws ParserConfigurationException, SAXException, IOException, TransformerException {
File f = new File("src/resources/test.xml");
myCreatorController.saveForPlaying(f);
Game g = myParserController.loadforPlaying(f);
assertEquals("Testing parser produces game from created XML", myGame, g);
}
}