Praktikum 1: mehr Tests
This commit is contained in:
parent
bc6f5891a3
commit
fd059a6f88
2
pom.xml
2
pom.xml
@ -4,6 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<name>Java 2</name>
|
||||
|
||||
<groupId>de.joethei.hs</groupId>
|
||||
<artifactId>java2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
@ -39,14 +39,6 @@ public class GrosseZahl {
|
||||
this.ziffern = ziffern;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder rueckgabe = new StringBuilder();
|
||||
for (int ziffer : ziffern) {
|
||||
rueckgabe.append(Integer.toString(ziffer));
|
||||
}
|
||||
return rueckgabe.toString();
|
||||
}
|
||||
|
||||
public boolean less(GrosseZahl b) {
|
||||
if(this.equals(b)) return false;
|
||||
if (this.ziffern.length < b.ziffern.length) return true;
|
||||
@ -62,13 +54,7 @@ public class GrosseZahl {
|
||||
GrosseZahl big = this.less(b) ? b : this;
|
||||
GrosseZahl small = this.less(b) ? this : b;
|
||||
|
||||
int[] array;
|
||||
if(big.ziffern.length != small.ziffern.length) {
|
||||
int diff = big.ziffern.length - small.ziffern.length;
|
||||
array = new int[small.ziffern.length + diff];
|
||||
Arrays.fill(array, 0);
|
||||
|
||||
}else array = new int[small.ziffern.length];
|
||||
int[] array = fill(big, small);
|
||||
|
||||
for(int i = small.ziffern.length - 1; i >= 0; i--) {
|
||||
array[array.length - i - 1] = small.ziffern[small.ziffern.length - i - 1];
|
||||
@ -90,9 +76,32 @@ public class GrosseZahl {
|
||||
}
|
||||
|
||||
public GrosseZahl sub(GrosseZahl b) {
|
||||
GrosseZahl big = this.less(b) ? b : this;
|
||||
GrosseZahl small = this.less(b) ? this : b;
|
||||
|
||||
int[] array;
|
||||
array = fill(big, small);
|
||||
|
||||
for(int i = small.ziffern.length - 1; i >= 0; i--) {
|
||||
array[array.length - i - 1] = small.ziffern[small.ziffern.length - i - 1];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
|
||||
logger.info(Arrays.toString(array));
|
||||
|
||||
return new GrosseZahl(array);
|
||||
}
|
||||
|
||||
private int[] fill(GrosseZahl big, GrosseZahl small) {
|
||||
int[] array;
|
||||
if(big.ziffern.length != small.ziffern.length) {
|
||||
int diff = big.ziffern.length - small.ziffern.length;
|
||||
array = new int[small.ziffern.length + diff];
|
||||
Arrays.fill(array, 0);
|
||||
|
||||
}else array = new int[small.ziffern.length];
|
||||
return array;
|
||||
}
|
||||
|
||||
public GrosseZahl mult(GrosseZahl b) {
|
||||
@ -125,6 +134,15 @@ public class GrosseZahl {
|
||||
else return this.sub(b).ggT(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int ziffer : ziffern) {
|
||||
result.append(Integer.toString(ziffer));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o instanceof GrosseZahl) {
|
||||
|
@ -14,6 +14,7 @@ class GrosseZahlTest {
|
||||
assertThrows(NumberFormatException.class, exec);
|
||||
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
||||
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
||||
assertNotEquals(new GrosseZahl(14), 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -26,13 +27,13 @@ class GrosseZahlTest {
|
||||
assertEquals(new GrosseZahl(4000), new GrosseZahl(500).add(new GrosseZahl(3500)));
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
void sub() {
|
||||
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
void mult() {
|
||||
assertEquals(new GrosseZahl(15), new GrosseZahl("5").mult(new GrosseZahl(3)));
|
||||
@ -47,6 +48,13 @@ class GrosseZahlTest {
|
||||
assertFalse(new GrosseZahl("12345").less(new GrosseZahl("1234")));
|
||||
assertFalse(new GrosseZahl("1234").less(new GrosseZahl("1234")));
|
||||
assertFalse(new GrosseZahl("1234").less(new GrosseZahl("1233")));
|
||||
assertTrue(new GrosseZahl(1233).less(new GrosseZahl(1234)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toStringTest() {
|
||||
assertEquals("45", new GrosseZahl(45).toString());
|
||||
assertEquals("45", new GrosseZahl("45").toString());
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user