This commit is contained in:
Johannes Theiner 2018-04-06 12:06:34 +02:00
parent a76271a99f
commit d3984e7024
4 changed files with 42 additions and 35 deletions

12
pom.xml
View File

@ -42,24 +42,12 @@
</build> </build>
<dependencies> <dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.junit.vintage</groupId> <groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId> <artifactId>junit-vintage-engine</artifactId>

View File

@ -0,0 +1,27 @@
package de.joethei.hs.java2.praktikum.praktikum2;
import java.util.*;
public class CharCollection {
ArrayList<Character> list = new ArrayList<>();
CharCollection(char... cc) {
for(char c:cc) this.list.add(c);
}
CharCollection(String s) {
new CharCollection(s.toCharArray());
}
int size() {
return this.list.size();
}
int count(char c) {
int rueckgabe = 0;
for(char b:list) {
if(b == c)rueckgabe ++;
}
return rueckgabe;
}
}

View File

@ -1,17 +1,14 @@
package de.joethei.hs.java2.tests; package de.joethei.hs.java2.tests;
import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl; import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl;
import org.junit.jupiter.api.DisplayName; import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.Assert.*;
@DisplayName("Eigene GrosseZahl") public class GrosseZahlTest {
class GrosseZahlTest {
@Test @Test
@DisplayName("Konstruktoren") public void constructors() {
void constructors() {
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), 14); assertNotEquals(new GrosseZahl(14), 14);
@ -19,8 +16,7 @@ class GrosseZahlTest {
@Test @Test
@DisplayName("Addition") public void add() {
void add() {
assertEquals(new GrosseZahl(42), new GrosseZahl("40").add(new GrosseZahl(2))); assertEquals(new GrosseZahl(42), new GrosseZahl("40").add(new GrosseZahl(2)));
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))); assertNotEquals(new GrosseZahl(43), new GrosseZahl("40").add(new GrosseZahl(2)));
@ -32,8 +28,7 @@ class GrosseZahlTest {
} }
@Test @Test
@DisplayName("Substraktion") public 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)));
assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50))); assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50)));
@ -41,16 +36,14 @@ class GrosseZahlTest {
} }
@Test @Test
@DisplayName("Multiplikation") public 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)));
assertNotEquals(new GrosseZahl("15"), new GrosseZahl("4").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))); assertEquals(new GrosseZahl(90000), new GrosseZahl(9).mult(new GrosseZahl(10000)));
} }
@Test @Test
@DisplayName("less") public void less() {
void less() {
assertTrue(new GrosseZahl("1234").less(new GrosseZahl("12345"))); assertTrue(new GrosseZahl("1234").less(new GrosseZahl("12345")));
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")));
@ -59,15 +52,13 @@ class GrosseZahlTest {
} }
@Test @Test
@DisplayName("toString()") public void toStringTest() {
void toStringTest() {
assertEquals("45", new GrosseZahl(45).toString()); assertEquals("45", new GrosseZahl(45).toString());
assertEquals("45", new GrosseZahl("45").toString()); assertEquals("45", new GrosseZahl("45").toString());
} }
@Test @Test
@DisplayName("größter gemeinsamer Teiler") public void ggT() {
void ggT() {
assertEquals(new GrosseZahl(3), new GrosseZahl(45).ggT(new GrosseZahl(21))); assertEquals(new GrosseZahl(3), new GrosseZahl(45).ggT(new GrosseZahl(21)));
assertEquals(new GrosseZahl(70), new GrosseZahl(1400).ggT(new GrosseZahl(210))); assertEquals(new GrosseZahl(70), new GrosseZahl(1400).ggT(new GrosseZahl(210)));
assertNotEquals(new GrosseZahl(2), new GrosseZahl("7").ggT(new GrosseZahl(13))); assertNotEquals(new GrosseZahl(2), new GrosseZahl("7").ggT(new GrosseZahl(13)));

View File

@ -1,18 +1,19 @@
package de.joethei.hs.java2.tests; package de.joethei.hs.java2.tests;
import de.joethei.hs.java2.vorlesungen.Sieb; import de.joethei.hs.java2.vorlesungen.Sieb;
import org.junit.jupiter.api.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.Assert.assertEquals;
class VorlesungsTest {
public class VorlesungsTest {
@Test @Test
void sieb() { public void sieb() {
Set<Integer> set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19)); Set<Integer> set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19));
assertEquals(set, new Sieb(20).getPrimzahl()); assertEquals(set, new Sieb(20).getPrimzahl());
} }