1
0
Fork 0

JUnit-tests implementiert!!!

master
devra 2024-01-09 01:24:19 +01:00
parent e5ada63b88
commit 2ba010b6cb
4 changed files with 95 additions and 19 deletions

View File

@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -206,16 +206,6 @@ public class Axel {
if(spr1.checkIfCellExists(parts[0])) {
spr1.put(parts[0], "=" + parts[1]);
}
// else {
// System.err.println("Zelle '"+ parts[0]+ "' existiert nicht!");
// }
// if((spr1.getRow(parts[0])+1)<=spr1.cells.length&&(spr1.getCol(parts[0])+1)<=spr1.cells[0].length) {
// spr1.put(parts[0], "=" + parts[1]);
// }
// else {
// System.err.println("Zelle '"+ parts[0]+ "' existiert nicht!");
// }
System.out.println(spr1);
} else if (userInput.toLowerCase().contains("exit")) {

View File

@ -167,7 +167,7 @@ public class Spreadsheet {
result = "" + mit(onlyCells[0], onlyCells[1]);
}
}
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> minimal-wert
else if (formula.startsWith("STABW(")) { // e.g. STABW(C6:D8) -> standardabweichung
String[] onlyCells = formula.substring(6, formula.length() - 1).split(":");
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
@ -175,7 +175,7 @@ public class Spreadsheet {
}
}
else if (formula.startsWith("MIN(")) {
else if (formula.startsWith("MIN(")) { // e.g. min(C6:D8) -> minimal-wert
String[] onlyCells = formula.substring(4, formula.length() - 1).split(":");
if(checkIfCellExists(onlyCells[0])&&checkIfCellExists(onlyCells[1])) {
result = "" + min(onlyCells[0], onlyCells[1]);
@ -212,7 +212,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The sum calculated.
*/
private long sum(String startCellName, String endCellName) {
public long sum(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
int summe=0;
@ -228,7 +228,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The product calculated.
*/
private long pro(String startCellName, String endCellName) {
public long pro(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
int produkt=1;
@ -244,7 +244,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The average calculated.
*/
private long mit(String startCellName, String endCellName) {
public long mit(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
int summe=0;
@ -260,7 +260,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The standard deviation calculated.
*/
private double statbw(String startCellName, String endCellName) {
public double statbw(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
if (werte.length < 2) {
@ -292,7 +292,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The minimum-value calculated.
*/
private long min(String startCellName, String endCellName) {
public long min(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
if (werte.length == 0) {
@ -316,7 +316,7 @@ public class Spreadsheet {
* @param endCellName The name of the cell in the lower right corner of the rectangle.
* @return The maximum-value calculated.
*/
private long max(String startCellName, String endCellName) {
public long max(String startCellName, String endCellName) {
int werte[]=getValues(startCellName,endCellName);
if (werte.length == 0) {
@ -377,7 +377,7 @@ public class Spreadsheet {
* @param formula The expression to be evaluated.
* @return The result calculated.
*/
private long calculate(String formula) throws ArithmeticException {
public long calculate(String formula) throws ArithmeticException {
//System.out.println(formula);
Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula);

View File

@ -0,0 +1,85 @@
package de.hs_mannheim.informatik.spreadsheet;
import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
class Tests {
Spreadsheet spr2=new Spreadsheet(10,10);
//Grundrechenarten
@Test
void testAddition() {
assertEquals(spr2.calculate("=1+1"),2);
}
@Test
void testSubtraction() {
assertEquals(spr2.calculate("=5-3"), 2);
}
@Test
void testMultiplication() {
assertEquals(spr2.calculate("=2*3"), 6);
}
@Test
void testDivision() {
assertEquals(spr2.calculate("=10/2"), 5);
}
//Komplexere Methoden
@Test
void testSum() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.sum("A1","A3"), 6);
}
@Test
void testProduct() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.pro("A1","A3"), 6);
}
@Test
void testMedian() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.mit("A1","A3"), 2);
}
@Test
void testStandardDeviation() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.statbw("A1","A3"),0.8, 0.1);
}
@Test
void testMin() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.min("A1","A3"),1);
}
@Test
void testMax() {
spr2.put("A1", "1");
spr2.put("A2", "2");
spr2.put("A3", "3");
assertEquals(spr2.max("A1","A3"),3);
}
}