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
8 changes: 8 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="resource/" kind="src" path="src"/>
<classpathentry kind="src" path="src/resource"/>
<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>
43 changes: 33 additions & 10 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
package debug;

import java.util.List;

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];
public ContainerArray (int limit) {
internalArray = new Object[limit];
}

public void add (E element) {
internalArray[currentSize++] = element;
public void add (E element) { //1: handling array out of bounds; don't allow addition when full
if(currentSize < internalArray.length){
internalArray[currentSize++] = element;
}
}

public void addAll(List<E> toAdd){
for(E e: toAdd){
add(e);
}
}

public int size () {
return currentSize;
}

public void remove (E objectToRemove) {
currentSize--;
public void remove (E objectToRemove) { //2: Remove object (first instance) and shift rightmost elements to left
int index = -1;
for(int i = 0; i < internalArray.length; i++){
if(objectToRemove.equals(internalArray[i])){
index = i;
break;
}
}
if(index != -1){
for(;index < internalArray.length-1; index++){
internalArray[index] = internalArray[index+1];
internalArray[index+1] = null;
}
currentSize--; //3: only decrement currentSize if something is removed
}
}

@SuppressWarnings("unchecked")
public E get (int index) {
return (E)internalArray[index];
public E get (int index) { //4: handle index out of bounds
if(index>=0 && index < LIMIT) return (E)internalArray[index];
return null;
}
}
39 changes: 37 additions & 2 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package debug;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.junit.Before;
import org.junit.Test;

Expand All @@ -20,28 +23,60 @@ public void testSizeChangeWithAdd () {
myContainer.add("Camel");
assertEquals("Add size", 3, myContainer.size());
}

@Test //
public void testStoreLimit () {
myContainer.addAll(Arrays.asList("aaaaaaaaaaaaaaaaaaaaaa".split("")));
assertEquals("Add size", 10, myContainer.size());
}

@Test
public void testObjectIsStored () {
String alligator = "Alligator";
myContainer.add(alligator);
myContainer.add("Alligator");
assertEquals("Add should be same reference", alligator, myContainer.get(0));
}

@Test
@Test
public void testSizeChangeWithRemove () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Remove size", 1, myContainer.size());
}

@Test //
public void testRemoveNonExistentObject () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Falafel");
assertEquals("Remove size", 2, myContainer.size());
}

@Test //
public void testRemoveModifiesAndShiftsArray () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Bear", myContainer.get(0));
}

@Test //
public void testGetOutOfBounds () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Loofah");
assertEquals(null, myContainer.get(-1));
assertEquals(null, myContainer.get(2568));
}
@Test
public void testObjectIsRemoved () {
public void testObjectIsRemoved () {
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Bear");
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}
}
1 change: 1 addition & 0 deletions src/resource/invalidbasegiven.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test=test
1 change: 1 addition & 0 deletions src/resource/validbasegiven.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test=test
34 changes: 34 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package tdd;

import java.util.HashMap;

public class Sheet {
HashMap<String, String> sheetMap;
HashMap<String,String> literalMap;
public Sheet() {
this.sheetMap = new HashMap<>();
this.literalMap = new HashMap<>();
}

public String get(String key) {
String toReturn = sheetMap.get(key);
if(toReturn!=null) return toReturn;
return "";
}

public void put(String theCell, String string) {
try{
int testInt = Integer.parseInt(string.trim());
sheetMap.put(theCell, string.trim());
}
catch(Exception e){
sheetMap.put(theCell, string);
}
literalMap.put(theCell, string);
}

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

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

//static allows to import all static methods from this class, Assert
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));
}

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

import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
* Abstract Tab for setting attributes to go in the Inspector Pane in either the Level or Actor Editing Environment GUI.
* @author AnnieTang
*
*/
public class TabAttributes {
private static final String DEFAULT_BASE = "invalidbasegiven";
private static final int PADDING = 10;
private static final double TEXTFIELD_WIDTH = 150;
private static final String EDITOR_ELEMENTS = "EditorElements";
private static final String PROMPT = "Select";
private static final String DELIMITER = ",";
private static final String LABEL = "Label";
private static final String OPTIONS = "Options";
private static final String TEXTFIELD = "Textfields";
private static final String COMBOBOXES = "Comboboxes";
private static final String TEST = "TEST";
private static final String GO = "GO";
private ResourceBundle myAttributesResources;
private String levelOptionsResource;

public TabAttributes(String tabText, String levelOptionsResource) {
this.levelOptionsResource = levelOptionsResource;
setResources();
}

private void setResources(){
try{
this.myAttributesResources = ResourceBundle.getBundle(levelOptionsResource);
}catch(Exception e){
this.myAttributesResources = ResourceBundle.getBundle(DEFAULT_BASE);
}
}

public String getResourcesBundleBaseName(){
return myAttributesResources.getBaseBundleName();
}

Node getContent() {
VBox vbox = new VBox(PADDING);
vbox.setPadding(new Insets(PADDING, PADDING, PADDING, PADDING));


String[] elements = myAttributesResources.getString(EDITOR_ELEMENTS).split(DELIMITER);
for (int i = 0; i < elements.length; i++) {
HBox hbox = new HBox(PADDING);
hbox.setAlignment(Pos.CENTER_LEFT);
Label label = new Label(myAttributesResources.getString(elements[i] + LABEL));
label.setWrapText(true);
// IGUIElement elementToCreate = null;
// elementToCreate = createNewGUIObject(elements[i]);
// hbox.getChildren().addAll(label, elementToCreate.createNode());
vbox.getChildren().add(hbox);
}
return vbox;
}

// private IGUIElement createNewGUIObject(String nodeType) {
// if (isTextField(nodeType)) {
// return createTextField(nodeType);
// } else if (isComboBox(nodeType)) {
// return createComboBox(nodeType);
// }
// return null;
// }

private boolean isTextField(String nodeType) {
return Arrays.asList(myAttributesResources.getString(TEXTFIELD).split(",")).contains(nodeType);
}

private boolean isComboBox(String nodeType) {
return Arrays.asList(myAttributesResources.getString(COMBOBOXES).split(",")).contains(nodeType);
}

// private IGUIElement createTextField(String nodeType) {
// IGUIElement textField = new TextFieldWithButton("", TEST, TEXTFIELD_WIDTH, GO, null);
// return textField;
// }

// private IGUIElement createComboBox(String nodeType) {
// String options = myAttributesResources.getString(nodeType + OPTIONS);
// List<String> optionsList = Arrays.asList(options.split(DELIMITER));
// return (IGUIElement) new ComboBoxOptions(myAttributesResources,PROMPT,optionsList);
// }
}
22 changes: 22 additions & 0 deletions src/voogasalad/TabAttributesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package voogasalad;

import static org.junit.Assert.*;

import org.junit.Test;


public class TabAttributesTest {
private TabAttributes ta = null;
private String rbValidBaseBundle;

@Test
public void testHandleInvalidBaseBundle() {
rbValidBaseBundle = "validbasegiven";
ta = new TabAttributes("tabTest", rbValidBaseBundle);
assertEquals("validbasegiven", ta.getResourcesBundleBaseName());
ta = new TabAttributes("tabTest", "randomword");
assertEquals("invalidbasegiven", ta.getResourcesBundleBaseName());

}

}
Loading