1
0
Fork 0

Dateien nach "Axel/src/de/hs_mannheim/informatik/spreadsheet" hochladen

main
Jan Bachmann 2024-01-07 23:32:59 +01:00
parent 1aa39e7344
commit f09c112e2c
1 changed files with 139 additions and 139 deletions

View File

@ -1,139 +1,139 @@
package de.hs_mannheim.informatik.spreadsheet; package de.hs_mannheim.informatik.spreadsheet;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class nr5 { public class nr5 {
private Spreadsheet spr; private Spreadsheet spr;
private String[] spreadsheetData = { private String[] spreadsheetData = {
"40", "12", "87", "54", "32", "66", "78", "21", "90", "89", "40", "12", "87", "54", "32", "66", "78", "21", "90", "89",
"25", "74", "88", "91", "33", "98", "67", "45", "19", "11", "25", "74", "88", "91", "33", "98", "67", "45", "19", "11",
"65", "69", "50", "84", "74", "61", "53", "99", "29", "46", "65", "69", "50", "84", "74", "61", "53", "99", "29", "46",
"16", "89", "79", "62", "45", "31", "73", "23", "13", "81", "16", "89", "79", "62", "45", "31", "73", "23", "13", "81",
"60", "88", "45", "51", "36", "16", "46", "3", "18", "85", "60", "88", "45", "51", "36", "16", "46", "3", "18", "85",
"4", "27", "87", "91", "29", "84", "95", "65", "71", "94", "4", "27", "87", "91", "29", "84", "95", "65", "71", "94",
"84", "49", "3", "79", "67", "89", "10", "74", "77", "51", "84", "49", "3", "79", "67", "89", "10", "74", "77", "51",
"48", "38", "41", "59", "2", "15", "62", "18", "40", "29", "48", "38", "41", "59", "2", "15", "62", "18", "40", "29",
"93", "13", "5", "58", "30", "64", "58", "6", "67", "96", "93", "13", "5", "58", "30", "64", "58", "6", "67", "96",
"67", "77", "25", "81", "87", "27", "53", "31", "85", "98"}; "67", "77", "25", "81", "87", "27", "53", "31", "85", "98"};
public void setup() { public void setup() {
spr = new Spreadsheet(10,10); spr = new Spreadsheet(10,10);
for(int i=0;i<10;i++) { for(int i=0;i<10;i++) {
for(int j=0;j<10;j++) { for(int j=0;j<10;j++) {
spr.put(i,j, spreadsheetData[i+j*10]); spr.put(i,j, spreadsheetData[i+j*10]);
} }
} }
} }
@Test @Test
public void testSum() { public void testSum() {
setup(); setup();
System.out.println(spr); System.out.println(spr);
long expectedSum = 40 + 12 + 87 + 54 + 32 + 66 + 78 + 21 + 90 + 89 + long expectedSum = 40 + 12 + 87 + 54 + 32 + 66 + 78 + 21 + 90 + 89 +
25 + 74 + 88 + 91 + 33 + 98 + 67 + 45 + 19 + 11 + 25 + 74 + 88 + 91 + 33 + 98 + 67 + 45 + 19 + 11 +
65 + 69 + 50 + 84 + 74 + 61 + 53 + 99 + 29 + 46 + 65 + 69 + 50 + 84 + 74 + 61 + 53 + 99 + 29 + 46 +
16 + 89 + 79 + 62 + 45 + 31 + 73 + 23 + 13 + 81 + 16 + 89 + 79 + 62 + 45 + 31 + 73 + 23 + 13 + 81 +
60 + 88 + 45 + 51 + 36 + 16 + 46 + 3 + 18 + 85 + 60 + 88 + 45 + 51 + 36 + 16 + 46 + 3 + 18 + 85 +
4 + 27 + 87 + 91 + 29 + 84 + 95 + 65 + 71 + 94 + 4 + 27 + 87 + 91 + 29 + 84 + 95 + 65 + 71 + 94 +
84 + 49 + 3 + 79 + 67 + 89 + 10 + 74 + 77 + 51 + 84 + 49 + 3 + 79 + 67 + 89 + 10 + 74 + 77 + 51 +
48 + 38 + 41 + 59 + 2 + 15 + 62 + 18 + 40 + 29 + 48 + 38 + 41 + 59 + 2 + 15 + 62 + 18 + 40 + 29 +
93 + 13 + 5 + 58 + 30 + 64 + 58 + 6 + 67 + 96 + 93 + 13 + 5 + 58 + 30 + 64 + 58 + 6 + 67 + 96 +
67 + 77 + 25 + 81 + 87 + 27 + 53 + 31 + 85 + 98; 67 + 77 + 25 + 81 + 87 + 27 + 53 + 31 + 85 + 98;
assertEquals(expectedSum, spr.sum("A1", "J10")); assertEquals(expectedSum, spr.sum("A1", "J10"));
} }
@Test
@Test public void testProd() {
public void testProd() { setup();
setup(); long expectedProduct = 1;
long expectedProduct = 1; for (String value : spreadsheetData) {
for (String value : spreadsheetData) { expectedProduct *= Integer.parseInt(value);
expectedProduct *= Integer.parseInt(value); }
} assertEquals(expectedProduct, spr.prod("A1", "J10"));
assertEquals(expectedProduct, spr.prod("A1", "J10")); }
} @Test
@Test public void testMid() {
public void testMid() { setup();
setup(); int mid = 0;
int mid = 0; for (String value : spreadsheetData) {
for (String value : spreadsheetData) { mid += Integer.parseInt(value);
mid += Integer.parseInt(value); }
} mid /= 100;
mid /= 100;
assertEquals((long) mid, spr.mid("A1", "J10"));
assertEquals((long) mid, spr.mid("A1", "J10")); }
} @Test
@Test public void testStabw() {
public void testStabw() { setup();
setup(); double Stabw = stabw();
double Stabw = stabw(); assertEquals((long) Stabw, spr.stabw("A1", "J10"));
assertEquals((long) Stabw, spr.stabw("A1", "J10")); }
} @Test
@Test public void testMin() {
public void testMin() { setup();
setup(); long Min = calMin();
long Min = calMin(); assertEquals(Min, spr.min("A1", "J10"));
assertEquals(Min, spr.min("A1", "J10")); }
} @Test
@Test public void testMax() {
public void testMax() { setup();
setup(); long Max = calMax();
long Max = calMax(); assertEquals(Max, spr.max("A1", "J10"));
assertEquals(Max, spr.max("A1", "J10")); }
}
private double stabw() {
private double stabw() { double midVal = cMV();
double midVal = cMV(); double sum = 0.0;
double sum = 0.0; int numbers = 0;
int numbers = 0; for (String value : spreadsheetData) {
for (String value : spreadsheetData) { if (!value.isBlank()) {
if (!value.isBlank()) { long longValue = Long.parseLong(value);
long longValue = Long.parseLong(value); sum += Math.pow(longValue - midVal, 2);
sum += Math.pow(longValue - midVal, 2); numbers++;
numbers++; }
} }
} return Math.sqrt(sum / numbers);
return Math.sqrt(sum / numbers); }
} private double cMV() {
private double cMV() { double midSum = 0.0;
double midSum = 0.0; int numbers = 0;
int numbers = 0; for (String value : spreadsheetData) {
for (String value : spreadsheetData) { if (!value.isBlank()) {
if (!value.isBlank()) { midSum += Long.parseLong(value);
midSum += Long.parseLong(value); numbers++;
numbers++; }
} }
} return midSum / numbers;
return midSum / numbers; }
} private long calMin() {
private long calMin() { long min = Long.MAX_VALUE;
long min = Long.MAX_VALUE; for (String value : spreadsheetData) {
for (String value : spreadsheetData) { if (!value.isBlank()) {
if (!value.isBlank()) { long longValue = Long.parseLong(value);
long longValue = Long.parseLong(value); min = Math.min(min, longValue);
min = Math.min(min, longValue); }
} }
} return min;
return min; }
} private long calMax() {
private long calMax() { long max = Long.MIN_VALUE;
long max = Long.MIN_VALUE;
for (String value : spreadsheetData) {
for (String value : spreadsheetData) { if (!value.isBlank()) {
if (!value.isBlank()) { long longValue = Long.parseLong(value);
long longValue = Long.parseLong(value); max = Math.max(max, longValue);
max = Math.max(max, longValue); }
} }
}
return max;
return max; }
} }
}