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
2 changes: 2 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Spreadsheet.class
/SpreadsheetTest.class
Binary file modified bin/Spreadsheet.class
Binary file not shown.
Binary file modified bin/SpreadsheetTest.class
Binary file not shown.
47 changes: 41 additions & 6 deletions src/Spreadsheet.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
import java.util.HashMap;
import java.util.Map;

public class Spreadsheet {

private Map<String, String> spriteSheet = new HashMap<String, String>();

public String get(String cell) {
// to be implemented
return null;
String cellValue = spriteSheet.get(cell);

return cellValue;
}

public void set(String cell, String value) {
// to be implemented
spriteSheet.put(cell, value);
}

public String evaluate(String cell) {
// to be implemented
return null;

String cellValue = get(cell);
String returnValue;
char first = cellValue.charAt(0);
char last = cellValue.charAt(cellValue.length() -1);

if(isNumeric(cellValue) == true){
returnValue = cellValue;
}else if(isString(first, last) == true){
returnValue = cellValue.substring(1, cellValue.length()-1);
}else{
returnValue = "#Error";
}

return returnValue;
}

public boolean isNumeric(String s){

if(s.matches("-?\\d+(\\.\\d+)?")){
return true;
}else{
return false;
}
}

}
public boolean isString(char a, char b){

if(a == '�' && b == '�'){
return true;
}else{
return false;
}
}
}
40 changes: 36 additions & 4 deletions tests/SpreadsheetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,41 @@
public class SpreadsheetTest {

@Test
public void test() {
fail("Not yet implemented");

public void testCreate() {
Spreadsheet sp = new Spreadsheet();
assertNotNull(sp);
}


@Test
public void testGet() {
Spreadsheet sp = new Spreadsheet();
sp.set("A1", "5");
String cv = sp.get("A1");
assertEquals("5", cv);
}

@Test
public void testEvaluate_integer() {
Spreadsheet sp = new Spreadsheet();
sp.set("A1", "1");
String cv = sp.evaluate("A1");
assertEquals("1", cv);
}

@Test
public void testEvaluate_quoted_string() {
Spreadsheet sp = new Spreadsheet();
sp.set("A1", "�abc�");
String cv = sp.evaluate("A1");
assertEquals("abc", cv);
}

@Test
public void testEvaluate_incorrect_value() {
Spreadsheet sp = new Spreadsheet();
sp.set("A1", "�abc1");
String cv = sp.evaluate("A1");
assertEquals("#Error", cv);
}

}