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