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: 23 additions & 5 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@


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

public ContainerArray () {
this(10);
}

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

public void add (E element) {
internalArray[currentSize++] = element;
int currentIndex = -1;
for(int i = 0; i < limit; i++) {
if(internalArray[i] == null) {
currentIndex = i;
break;
}
}
try {
internalArray[currentIndex] = element;
currentSize++;
} catch(Exception e) {
throw new ArrayIndexOutOfBoundsException();
}
}

public int size () {
return currentSize;
}

public void remove (E objectToRemove) {
currentSize--;
for(int i = 0; i < currentSize; i++) {
if(internalArray[i] == objectToRemove) {
internalArray[i] = null;
currentSize--;
}
}
}

@SuppressWarnings("unchecked")
Expand Down
45 changes: 45 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ public void testSizeChangeWithRemove () {
myContainer.remove("Alligator");
assertEquals("Remove size", 1, myContainer.size());
}

@Test
public void testObjectGoneWithRemove () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Object should be removed", null, myContainer.get(0));
}

@Test
public void testObjectToRemoveExists () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Cat");
assertEquals("Size should not decrease if object does not exist", 2, myContainer.size());
}


@Test
public void testObjectIsRemoved () {
String alligator = "Alligator";
Expand All @@ -44,4 +61,32 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

@Test
public void testRemoveThenAdd () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Cat");
myContainer.add("Duck");
myContainer.remove("Bear");
myContainer.add("Banana");
assertEquals("Adding shouldn't overwrite", "Duck", myContainer.get(3));
}

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testOverflowCapacity () {
for(int i = 0; i < 11; i++) {
myContainer.add("Alligator");
}
assertEquals("Adding shouldn't overwrite", "Alligator", myContainer.get(0));
}

@Test
public void testLimit () {
myContainer = new ContainerArray<>(20);
for(int i = 0; i < 15; i++) {
myContainer.add("Alligator");
}
assertEquals("Custom constructor should update limit", "Alligator", myContainer.get(0));
}
}
35 changes: 35 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tdd;

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

public class Sheet {

private Map<String, String> sheetMap;

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

public String get(String theCell) {
if(this.sheetMap.containsKey(theCell)) {
String testIfNumber = this.sheetMap.get(theCell).replace(" ", "");
try {
Integer.parseInt(testIfNumber);
return testIfNumber;
} catch(NumberFormatException e) {
return this.sheetMap.get(theCell);
}
}
return "";
}

public void put(String theCell, String string) {
this.sheetMap.put(theCell, string);
}

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

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

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

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

}
69 changes: 69 additions & 0 deletions src/voogasalad/ResourceDecipherer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package voogasalad;
import java.util.ResourceBundle;

/**
* A decrypter of file paths, in order to determine what kind of file a user
* is trying to import.
* @author DoovalSalad
*
*/
public class ResourceDecipherer {

private static ResourceBundle fileExtensions;
private static final String IMAGE = "IMAGE";
private static final String AUDIO = "AUDIO";

/**
* Returns a VoogaFileType enum depending on the path and extension of the file
* @param path: path of the image
* @return a VoogaFileType (IMAGE or AUDIO)
*/
public static VoogaFileType decipherName(String path) {
fileExtensions = VoogaBundles.extensionProperties;
if(fileExtensions.containsKey(getExtension(path, '.'))) {
return VoogaFileType.valueOf(fileExtensions.getString(getExtension(path, '.')));
}
return null;

}

/**
* Determines if a file being imported is an image
* @param path: the path of the item
* @return: true if it is valid
*/
public static boolean isImage(String path) {
if(decipherName(path) == null) return false;
return decipherName(path).name().equals(IMAGE);
}

/**
* Determines if a file being imported is an audio file
* @param path: the path of the item
* @return: true if it is valid
*/
public static boolean isAudio(String path) {
if(decipherName(path) == null) return false;
return decipherName(path).name().equals(AUDIO);
}

/**
* Returns the extension given the path and delimiter to use. For example,
* would return "png" if a PNG file was passed as a parameter, along with the
* '.' delimiter to separate extension from the name.
* @param path: path of the item
* @param delimiter: character with which to separate
* @return
*/
public static String getExtension(String path, char delimiter) {
String extension = path;

int i = path.lastIndexOf(delimiter);
if (i > 0) {
extension = path.substring(i+1).toLowerCase();
}

return extension;
}

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

import static org.junit.Assert.*;

import org.junit.Test;

public class ResourceDeciphererTest {

@Test
public void testIsImage() {
assertEquals("Should be an image", true, ResourceDecipherer.isImage("hello.png"));
assertEquals("Should be an image", true, ResourceDecipherer.isImage("C:\\User\\Programs\\hello.gif"));
assertEquals("Should be an image", true, ResourceDecipherer.isImage("file:/../hello.bmp"));
assertEquals("Should be an image", false, ResourceDecipherer.isImage("hello.wav"));
assertEquals("Should be an image", false, ResourceDecipherer.isImage("hello.jpgg"));
}

@Test
public void testIsAudio() {
assertEquals("Should be an audio", true, ResourceDecipherer.isAudio("hello.wav"));
assertEquals("Should be an audio", true, ResourceDecipherer.isAudio("C:\\User\\Programs\\hello.mp3"));
assertEquals("Should be an audio", true, ResourceDecipherer.isAudio("file:/../hello.wav"));
assertEquals("Should be an audio", false, ResourceDecipherer.isAudio("hello.flv"));
assertEquals("Should be an audio", false, ResourceDecipherer.isAudio("hello..png"));
}

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

import java.util.ResourceBundle;

/**
* A class to contain public static references to resource bundles,
* so that multiple classes requiring access to these properties do
* not need to independently and repeatedly instantiate them.
*
*/
public class VoogaBundles {

public final static ResourceBundle extensionProperties = ResourceBundle.getBundle("resources/extensions");
public final static ResourceBundle toolbarProperties = ResourceBundle.getBundle("resources/toolbarbuttons");

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

/**
* The enum specifying what kind of item a particular VoogaFile is,
* currently supporting folders, images, and audio files.
* @author DoovalSalad
*
*/
public enum VoogaFileType {
FOLDER, IMAGE, AUDIO;

}