Java_2/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java

91 lines
3.5 KiB
Java

package de.joethei.hs.java2.tests;
import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl;
import org.junit.Test;
import static org.junit.Assert.*;
public class GrosseZahlTest {
@Test
public void constructors() {
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
assertNotEquals(new GrosseZahl(14), 14);
}
@Test
public void length() {
assertEquals(4, new GrosseZahl("1234").length());
assertNotEquals(5, new GrosseZahl(1234).length());
}
@Test
public void numberAt() {
assertEquals(5, new GrosseZahl("125").numberAt(2));
assertNotEquals(5, new GrosseZahl(125).numberAt(1));
}
@Test
public void add() {
assertEquals(new GrosseZahl(42), new GrosseZahl("40").add(new GrosseZahl(2)));
assertEquals(new GrosseZahl("42"), new GrosseZahl(40).add(new GrosseZahl(2)));
assertNotEquals(new GrosseZahl(43), new GrosseZahl("40").add(new GrosseZahl(2)));
assertEquals(new GrosseZahl(200), new GrosseZahl(190).add(new GrosseZahl("10")));
assertEquals(new GrosseZahl(200), new GrosseZahl(10).add(new GrosseZahl(190)));
assertEquals(new GrosseZahl(400), new GrosseZahl(50).add(new GrosseZahl(350)));
assertEquals(new GrosseZahl(4000), new GrosseZahl(500).add(new GrosseZahl(3500)));
assertEquals(new GrosseZahl(200), new GrosseZahl("198").add(new GrosseZahl(2)));
}
@Test
public void sub() {
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50)));
assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl("10")));
assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl(15)));
}
@Test
public void mult() {
assertEquals(new GrosseZahl(15), new GrosseZahl("5").mult(new GrosseZahl(3)));
assertNotEquals(new GrosseZahl("15"), new GrosseZahl("4").mult(new GrosseZahl(3)));
assertEquals(new GrosseZahl(90000), new GrosseZahl(9).mult(new GrosseZahl(10000)));
}
@Test
public void less() {
assertTrue(new GrosseZahl("1234").less(new GrosseZahl("12345")));
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
public void toStringTest() {
assertEquals("45", new GrosseZahl(45).toString());
assertEquals("45", new GrosseZahl("45").toString());
}
@Test
public void ggT() {
assertEquals(new GrosseZahl(3), new GrosseZahl(45).ggT(new GrosseZahl(21)));
assertEquals(new GrosseZahl(70), new GrosseZahl(1400).ggT(new GrosseZahl(210)));
assertNotEquals(new GrosseZahl(2), new GrosseZahl("7").ggT(new GrosseZahl(13)));
}
@Test(expected = IllegalArgumentException.class)
public void wrongInput() {
new GrosseZahl("42B");
new GrosseZahl("42/");
}
@Test
public void hashCodeTest() {
assertEquals(new GrosseZahl(42).hashCode(), new GrosseZahl("42").hashCode());
}
}