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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<name>Java 2</name>
|
||||||
|
|
||||||
<groupId>de.joethei.hs</groupId>
|
<groupId>de.joethei.hs</groupId>
|
||||||
<artifactId>java2</artifactId>
|
<artifactId>java2</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
|
@ -39,14 +39,6 @@ public class GrosseZahl {
|
||||||
this.ziffern = ziffern;
|
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) {
|
public boolean less(GrosseZahl b) {
|
||||||
if(this.equals(b)) return false;
|
if(this.equals(b)) return false;
|
||||||
if (this.ziffern.length < b.ziffern.length) return true;
|
if (this.ziffern.length < b.ziffern.length) return true;
|
||||||
|
@ -62,13 +54,7 @@ public class GrosseZahl {
|
||||||
GrosseZahl big = this.less(b) ? b : this;
|
GrosseZahl big = this.less(b) ? b : this;
|
||||||
GrosseZahl small = this.less(b) ? this : b;
|
GrosseZahl small = this.less(b) ? this : b;
|
||||||
|
|
||||||
int[] array;
|
int[] array = fill(big, small);
|
||||||
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];
|
|
||||||
|
|
||||||
for(int i = small.ziffern.length - 1; i >= 0; i--) {
|
for(int i = small.ziffern.length - 1; i >= 0; i--) {
|
||||||
array[array.length - i - 1] = small.ziffern[small.ziffern.length - i - 1];
|
array[array.length - i - 1] = small.ziffern[small.ziffern.length - i - 1];
|
||||||
|
@ -90,9 +76,32 @@ public class GrosseZahl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrosseZahl sub(GrosseZahl b) {
|
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) {
|
public GrosseZahl mult(GrosseZahl b) {
|
||||||
|
@ -125,6 +134,15 @@ public class GrosseZahl {
|
||||||
else return this.sub(b).ggT(b);
|
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
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if(o instanceof GrosseZahl) {
|
if(o instanceof GrosseZahl) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ class GrosseZahlTest {
|
||||||
assertThrows(NumberFormatException.class, exec);
|
assertThrows(NumberFormatException.class, exec);
|
||||||
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
||||||
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
||||||
|
assertNotEquals(new GrosseZahl(14), 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -26,13 +27,13 @@ class GrosseZahlTest {
|
||||||
assertEquals(new GrosseZahl(4000), new GrosseZahl(500).add(new GrosseZahl(3500)));
|
assertEquals(new GrosseZahl(4000), new GrosseZahl(500).add(new GrosseZahl(3500)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
void sub() {
|
void sub() {
|
||||||
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||||
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Test
|
@Test
|
||||||
void mult() {
|
void mult() {
|
||||||
assertEquals(new GrosseZahl(15), new GrosseZahl("5").mult(new GrosseZahl(3)));
|
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("12345").less(new GrosseZahl("1234")));
|
||||||
assertFalse(new GrosseZahl("1234").less(new GrosseZahl("1234")));
|
assertFalse(new GrosseZahl("1234").less(new GrosseZahl("1234")));
|
||||||
assertFalse(new GrosseZahl("1234").less(new GrosseZahl("1233")));
|
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