1
0
Fork 0

//JUNIT Tests & some Error corrections

main
Emelie Schneider 2024-01-11 02:01:26 +01:00
parent 32470a9b10
commit 4419f6e872
3 changed files with 170 additions and 8 deletions

View File

@ -34,6 +34,8 @@ public class Axel {
spr.put("B2", "5"); spr.put("B2", "5");
spr.put("B3", "8"); spr.put("B3", "8");
spr.put("C1", "8");
spr.put("C2", "2");
// //
@ -64,8 +66,20 @@ public class Axel {
System.out.println("cell name:"); System.out.println("cell name:");
readInput= sc.nextLine(); readInput= sc.nextLine();
currentCell=readInput; currentCell=readInput;
readInput= readInput.toUpperCase();
if(readInput.charAt(0)>(char)('A'+spr.cells[0].length-1)){
System.out.println("This cell doesn't exist :(");
continue;
}
if(Integer.parseInt(readInput.substring(1))>spr.cells.length) {
System.out.println("This cell doesn't exist :(");
continue;
}
System.out.println("Set formula or value:"); System.out.println("Set formula or value:");
readInput= sc.nextLine(); readInput= sc.nextLine();
@ -81,7 +95,7 @@ public class Axel {
System.out.println("Do you want to save the sheet?(y/n)"); System.out.println("Do you want to save the sheet?(y/n)");
readInput=sc.nextLine(); readInput=sc.nextLine();
if(readInput.equals("y")||readInput.equals("Y")) { if(readInput.equals("y")||readInput.equals("Y")) {
spr.saveCsv("test"); spr.saveCsv("/home/emelie/Dokumente/Files/leer.csv");
} }

View File

@ -0,0 +1,134 @@
package de.hs_mannheim.informatik.spreadsheet;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class AxelTesting {
@Test
void testSum() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=4");
testSheet.put("A2", "=3");
testSheet.put("B1", "=5");
testSheet.put("B2", "=2");
testSheet.put("B3", "=1");
testSheet.put("C1", "=SUMME(A1:B3)");
assertEquals("15", testSheet.get("C1"));
}
@Test
void testProd() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=4");
testSheet.put("A2", "=3");
testSheet.put("B1", "=5");
testSheet.put("B2", "=2");
testSheet.put("B3", "=1");
testSheet.put("C1", "=PRODUKT(A1:B3)");
assertEquals("120", testSheet.get("C1"));
}
@Test
void testAvg() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=4");
testSheet.put("A2", "=3");
testSheet.put("B1", "=5");
testSheet.put("B2", "=2");
testSheet.put("B3", "=1");
testSheet.put("C1", "=10");
testSheet.put("C3", "=15");
testSheet.put("C4", "=MITTELWERT(A1:C3)");
assertEquals("5", testSheet.get("C4"));
}
@Test
void testMin() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=123");
testSheet.put("A2", "=12");
testSheet.put("B1", "=5");
testSheet.put("B2", "=23");
testSheet.put("B3", "=4");
testSheet.put("C1", "=10");
testSheet.put("C3", "=15");
testSheet.put("D5", "=3");
testSheet.put("D6", "=MIN(A1:D5)");
assertEquals(3, Integer.parseInt(testSheet.get("D6")));
}
@Test
void testMax() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=23");
testSheet.put("A2", "=12");
testSheet.put("B1", "=5");
testSheet.put("B2", "=123");
testSheet.put("B3", "=4");
testSheet.put("C1", "=10");
testSheet.put("C3", "=15");
testSheet.put("D5", "=3");
testSheet.put("D6", "=MAX(A1:D5)");
assertEquals("123", testSheet.get("D6"));
}
@Test
void testStDev() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=23");
testSheet.put("A2", "=12");
testSheet.put("B1", "=5");
testSheet.put("B2", "=123");
testSheet.put("B3", "=4");
testSheet.put("C1", "=10");
testSheet.put("C3", "=15");
testSheet.put("D5", "=3");
testSheet.put("D6", "=STABW(A1:D5)");
assertEquals("37", testSheet.get("D6"));
}
@Test
void testCalc() {
Spreadsheet testSheet= new Spreadsheet(99,26);
testSheet.put("A1", "=23");
testSheet.put("A2", "=12");
testSheet.put("B1", "=5");
testSheet.put("B2", "=123");
testSheet.put("B3", "=4");
testSheet.put("C1", "=10");
testSheet.put("C3", "=15");
testSheet.put("D5", "=3");
testSheet.put("D6", "=10+3+C3-B1");
testSheet.put("D7", "=666/B3");
testSheet.put("D8", "=30*5/2+20");
assertEquals("23", testSheet.get("D6"));
assertEquals("166", testSheet.get("D7"));
assertEquals("95", testSheet.get("D8"));
}
}

View File

@ -77,9 +77,12 @@ public class Spreadsheet {
} }
private int getRow(String cellName) { private int getRow(String cellName) {
return cellName.charAt(1) - '1'; String row = "";
for (int i = 1; i < cellName.length(); i++){
row += cellName.charAt(i);
}
return Integer.parseInt(row) - 1;
} }
// ----- // -----
// business logic // business logic
@ -221,9 +224,12 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(cells[i][j].getValue().equals("")){
temp=0;
}else {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
sum=sum+temp; sum=sum+temp;
}
} }
} }
@ -255,11 +261,14 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(cells[i][j].getValue().equals("")){
temp=1;
}else {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
prod=prod*temp; prod=prod*temp;
} }
} }
}
return prod; return prod;
} }
@ -292,11 +301,13 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(!cells[i][j].getValue().equals("")) {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
sum=sum+temp; sum=sum+temp;
part++; part++;
} }
} }
}
avg=sum/part; avg=sum/part;
return avg; return avg;
@ -328,12 +339,13 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(!cells[i][j].getValue().equals("")) {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
if(min>temp) { if(min>temp) {
min=temp; min=temp;
} }
} }
}
} }
@ -367,13 +379,14 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(!cells[i][j].getValue().equals("")) {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
if(max<temp) { if(max<temp) {
max=temp; max=temp;
} }
} }
} }
}
return max; return max;
} }
@ -410,12 +423,13 @@ public class Spreadsheet {
for(int i= startRow; i<=endRow; i++) { for(int i= startRow; i<=endRow; i++) {
for(int j=startCol; j<=endCol; j++) { for(int j=startCol; j<=endCol; j++) {
if(!cells[i][j].getValue().equals("")) {
temp= Integer.parseInt(cells[i][j].getValue()); temp= Integer.parseInt(cells[i][j].getValue());
temp=temp-avg; temp=temp-avg;
temp= temp*temp; temp= temp*temp;
elements.add(temp); elements.add(temp);
}
} }
} }