Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
10073d9
besouro automatic message
Oct 12, 2016
edd4487
besouro automatic message
Oct 12, 2016
1ad845e
besouro automatic message
Oct 12, 2016
3762821
besouro automatic message
Oct 12, 2016
f1247fb
besouro automatic message
Oct 12, 2016
d277dcc
besouro automatic message
Oct 12, 2016
9da1889
besouro automatic message
Oct 12, 2016
e6e1380
besouro automatic message
Oct 12, 2016
3f425b4
besouro automatic message
Oct 12, 2016
31b6449
besouro automatic message
Oct 12, 2016
40f961e
besouro automatic message
Oct 12, 2016
da1a4c7
besouro automatic message
Oct 12, 2016
c82a615
besouro automatic message
Oct 12, 2016
e3508bf
besouro automatic message
Oct 12, 2016
d2c430a
besouro automatic message
Oct 12, 2016
b99200d
besouro automatic message
Oct 12, 2016
fa9a68d
besouro automatic message
Oct 12, 2016
45ca01b
besouro automatic message
Oct 12, 2016
b9b0bc3
besouro automatic message
Oct 12, 2016
6579351
besouro automatic message
Oct 12, 2016
7e72482
besouro automatic message
Oct 12, 2016
5ecc24a
besouro automatic message
Oct 12, 2016
341e4a0
besouro automatic message
Oct 12, 2016
c7030f9
besouro automatic message
Oct 12, 2016
dfad407
besouro automatic message
Oct 12, 2016
232b97f
besouro automatic message
Oct 12, 2016
6fd0dd2
besouro automatic message
Oct 12, 2016
bab7f22
besouro automatic message
Oct 12, 2016
bf47de7
besouro automatic message
Oct 12, 2016
c80ebd5
besouro automatic message
Oct 12, 2016
b5d82e1
besouro automatic message
Oct 12, 2016
6527718
besouro automatic message
Oct 12, 2016
80bf9b0
besouro automatic message
Oct 12, 2016
f874fdf
besouro automatic message
Oct 12, 2016
714e7fc
besouro automatic message
Oct 12, 2016
dc4c2ed
besouro automatic message
Oct 12, 2016
f7d8669
besouro automatic message
Oct 12, 2016
ec3d789
besouro automatic message
Oct 12, 2016
bec801b
besouro automatic message
Oct 12, 2016
54af3ca
besouro automatic message
Oct 12, 2016
f0ccb30
besouro automatic message
Oct 12, 2016
d807583
besouro automatic message
Oct 12, 2016
200aa07
besouro automatic message
Oct 12, 2016
336c006
besouro automatic message
Oct 12, 2016
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
347 changes: 347 additions & 0 deletions .besouro/20161012142150776/actions.txt

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions .besouro/20161012142150776/besouroEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
1476271678563 test-addition 2 367 true
1476271678564 test-addition 1 367 true
1476271950606 test-addition 1 233 true
1476271950607 test-addition 1 233 true
1476271950608 test-addition 1 233 true
1476272034216 refactoring 1A 24 true
1476272034217 refactoring 3 24 true
1476272034218 refactoring 3 24 true
1476272669239 test-first 3 612 true
1476272669240 test-first 3 612 true
1476272669241 test-first 3 612 true
1476272669242 test-first 3 612 true
1476272669243 test-first 3 612 true
1476272669244 test-first 3 612 true
1476272669245 test-first 3 612 true
1476272669246 test-first 3 612 true
1476272669247 test-first 3 612 true
1476272722602 test-addition 1 41 true
1476272722603 test-addition 1 41 true
1476273007371 test-first 3 280 true
1476273007372 test-first 3 280 true
1476273007373 test-first 3 280 true
1476273047923 production 2 14 false
1476273209685 test-first 3 112 true
1476273209686 test-first 3 112 true
1476273209687 test-first 3 112 true
1476273209688 test-first 3 112 true
1476273233713 refactoring 2A 8 true
1476273261060 production 2 7 false
1476273310613 refactoring 2A 7 true
1476273685750 test-first 3 209 true
1476273685751 test-first 3 209 true
1476273881112 test-addition 1 173 true
1476273881113 test-addition 1 173 true
1476273977582 test-addition 1 48 true
1476273977583 test-addition 1 48 true
1476274107669 test-addition 1 119 true
1476274409528 test-addition 2 287 true
1476274409529 test-addition 1 287 true
1476274409530 test-addition 2 287 true
1476274409531 test-addition 1 287 true
1476274462301 regression 1 0 true
1476274766504 refactoring 2B 240 true
1476274766505 refactoring 2B 240 true
1476274766506 refactoring 2B 240 true
1476274766507 regression 1 240 true
1476274853107 test-addition 1 51 true
1476274853108 test-addition 1 51 true
1476274919063 test-addition 1 59 true
1476274919064 test-addition 1 59 true
1476275247005 test-addition 2 264 true
1476275247006 test-addition 1 264 true
1476275247007 test-addition 2 264 true
1476275247008 test-addition 1 264 true
1476276690110 test-addition 2 1298 true
1476276690111 test-addition 2 1298 true
1476276690112 test-addition 1 1298 true
1476276690113 test-addition 2 1298 true
1476276690114 test-addition 2 1298 true
1476276690115 test-addition 2 1298 true
1476276690116 test-addition 2 1298 true
1476276690117 test-addition 2 1298 true
1476276690118 test-addition 2 1298 true
1476276690119 test-addition 2 1298 true
1476276690120 test-addition 2 1298 true
1476276690121 test-addition 2 1298 true
1476276690122 test-addition 2 1298 true
1476276690123 test-addition 2 1298 true
1476276690124 test-addition 2 1298 true
1476276690125 test-addition 2 1298 true
1476276690126 test-addition 1 1298 true
1476276690127 test-addition 2 1298 true
1476276717635 refactoring 2B 14 true
1476276717636 refactoring 2B 14 true
1476276717637 regression 1 14 true
1476278967934 test-addition 2 2241 true
1476278967935 test-addition 2 2241 true
1476278967936 test-addition 2 2241 true
1476278967937 test-addition 2 2241 true
1476278967938 test-addition 2 2241 true
1476278967939 test-addition 2 2241 true
1476278967940 test-addition 2 2241 true
1476278967941 test-addition 2 2241 true
1476278967942 test-addition 2 2241 true
1476278967943 test-addition 2 2241 true
1476278967944 test-addition 2 2241 true
1476278967945 test-addition 1 2241 true
1476278967946 test-addition 2 2241 true
1476278967947 test-addition 2 2241 true
1476278967948 test-addition 1 2241 true
1476278967949 test-addition 2 2241 true
1476278967950 test-addition 2 2241 true
1476278967951 test-addition 2 2241 true
1476278967952 test-addition 2 2241 true
1476278967953 test-addition 2 2241 true
1476279027989 test-addition 2 51 true
1476279027990 test-addition 1 51 true
1476279027991 test-addition 2 51 true
1476279027992 test-addition 1 51 true
1476279075080 test-addition 2 39 true
1476279075081 test-addition 1 39 true
1476279075082 test-addition 2 39 true
1476279075083 test-addition 1 39 true
1476279135285 test-addition 2 48 true
1476279135286 test-addition 1 48 true
1476279135287 test-addition 2 48 true
1476279135288 test-addition 1 48 true
Empty file.
27 changes: 27 additions & 0 deletions .besouro/20161012142150776/randomHeuristicEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1476271678563 test-addition 2 367 false
1476271950606 test-addition 1 233 false
1476272034216 refactoring 1A 24 true
1476272669239 test-first 3 612 true
1476272722602 test-addition 1 41 true
1476273007371 test-first 3 280 true
1476273047923 production 2 14 true
1476273209685 test-first 3 112 true
1476273233713 refactoring 2A 8 false
1476273261060 production 2 7 true
1476273310613 refactoring 2A 7 true
1476273685750 test-first 3 209 true
1476273881112 test-addition 1 173 false
1476273977582 test-addition 1 48 true
1476274107669 test-addition 1 119 true
1476274409528 test-addition 2 287 false
1476274462301 regression 1 0 false
1476274766504 refactoring 2B 240 true
1476274853107 test-addition 1 51 true
1476274919063 test-addition 1 59 true
1476275247005 test-addition 2 264 true
1476276690110 test-addition 2 1298 true
1476276717635 refactoring 2B 14 true
1476278967934 test-addition 2 2241 false
1476279027989 test-addition 2 51 false
1476279075080 test-addition 2 39 true
1476279135285 test-addition 2 48 true
Empty file.
27 changes: 27 additions & 0 deletions .besouro/20161012142150776/zorroEpisodes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
1476271678563 test-addition 2 367 true
1476271950606 test-addition 1 272 true
1476272034216 refactoring 1A 83 true
1476272669239 test-first 3 635 true
1476272722602 test-addition 1 53 true
1476273007371 test-first 3 284 true
1476273047923 production 2 40 true
1476273209685 test-first 3 161 true
1476273233713 refactoring 2A 24 true
1476273261060 production 2 27 true
1476273310613 refactoring 2A 49 true
1476273685750 test-first 3 375 true
1476273881112 test-addition 1 195 true
1476273977582 test-addition 1 96 true
1476274107669 test-addition 1 130 true
1476274409528 test-addition 2 301 true
1476274462301 regression 1 52 true
1476274766504 refactoring 2B 304 true
1476274853107 test-addition 1 86 true
1476274919063 test-addition 1 65 true
1476275247005 test-addition 2 327 true
1476276690110 test-addition 2 1443 true
1476276717635 refactoring 2B 27 true
1476278967934 test-addition 2 2250 true
1476279027989 test-addition 2 60 true
1476279075080 test-addition 2 47 true
1476279135285 test-addition 2 60 true
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.
114 changes: 107 additions & 7 deletions src/Spreadsheet.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,118 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Spreadsheet {

private static final String STRING_CLASSIFIER = "'";
private static final String EQUALS = "=";
private static final String ERROR = "#ERROR";
Map<String, String> sheet = new HashMap<>();

public String get(String cell) {
// to be implemented
return null;
return sheet.get(cell);
}

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

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

if (cellValue.startsWith(EQUALS)) {
cellValue = cellValue.substring(1); // remove equal sign
if (sheet.containsKey(cellValue)) {
if (sheet.get(cellValue).substring(1).equals(cell)) {
return "#CIRCULAR";
}
return evaluate(cellValue);
}
}

if (cellValue.startsWith(STRING_CLASSIFIER)) {
return evaluateString(cellValue);
} else {
return evaluateInt(cellValue);
}
}

private String evaluateString(String cellStored) {
if (cellStored.endsWith(STRING_CLASSIFIER)) {
return cellStored.substring(1, cellStored.length() - 1);
} else {
return ERROR;
}
}

private String evaluateInt(String cellStored) {
try {
// cellStored = new StringBuilder(cellStored).reverse().toString();
char[] characters = cellStored.toCharArray();
if(characters[0] == '-'){
return cellStored;
}
return evaluateIntFormula(characters);

} catch (NumberFormatException ex) {

return ERROR;
}
}

private String evaluateIntFormula(char[] characters) {
char operand = 0;
String number="";
int calculation = 0;
int i = 0;
for (char c : characters) {
if (c >= '0' && c <= '9') {
operand = c;
} else if (c == '+') {
int x = (int)operand -48;
int y = Integer.parseInt(evaluateIntFormula(Arrays.copyOfRange(characters, i+1, characters.length)));
calculation = x + y;
return String.valueOf(calculation);
} else if (c == '-') {
int x = (int)operand -48;
int y = Integer.parseInt(evaluateIntFormula(Arrays.copyOfRange(characters, i+1, characters.length)));
calculation = x - y;
return String.valueOf(calculation);
}else if (c == '*') {
int x = (int)operand -48;
int y = Integer.parseInt(evaluateIntFormula(Arrays.copyOfRange(characters, i+1, characters.length)));
calculation = x * y;
return String.valueOf(calculation);
} else if (c == '/') {
int x = (int)operand -48;
int y = Integer.parseInt(evaluateIntFormula(Arrays.copyOfRange(characters, i+1, characters.length)));
calculation = x / y;
return String.valueOf(calculation);
} else if (c == '%') {
int x = (int)operand -48;
int y = Integer.parseInt(evaluateIntFormula(Arrays.copyOfRange(characters, i+1, characters.length)));
calculation = x % y;
return String.valueOf(calculation);
} else {
return ERROR;
}
number = number + String.valueOf(operand);
i++;
}
return number;
}

private int getNextNumber(char[] characters){
String number="";
for (char c : characters) {
if (c >= '0' && c <= '9') {
number = number + String.valueOf(c);
}else{
return Integer.parseInt(number);
}
}
return 0;
}

}
Loading