Duda
This commit is contained in:
parent
a76271a99f
commit
d3984e7024
12
pom.xml
12
pom.xml
@ -42,24 +42,12 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +1,14 @@
|
||||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@DisplayName("Eigene GrosseZahl")
|
||||
class GrosseZahlTest {
|
||||
public class GrosseZahlTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Konstruktoren")
|
||||
void constructors() {
|
||||
public void constructors() {
|
||||
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
||||
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
||||
assertNotEquals(new GrosseZahl(14), 14);
|
||||
@ -19,8 +16,7 @@ class GrosseZahlTest {
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("Addition")
|
||||
void add() {
|
||||
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)));
|
||||
@ -32,8 +28,7 @@ class GrosseZahlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Substraktion")
|
||||
void sub() {
|
||||
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)));
|
||||
@ -41,16 +36,14 @@ class GrosseZahlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Multiplikation")
|
||||
void mult() {
|
||||
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
|
||||
@DisplayName("less")
|
||||
void less() {
|
||||
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")));
|
||||
@ -59,15 +52,13 @@ class GrosseZahlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("toString()")
|
||||
void toStringTest() {
|
||||
public void toStringTest() {
|
||||
assertEquals("45", new GrosseZahl(45).toString());
|
||||
assertEquals("45", new GrosseZahl("45").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("größter gemeinsamer Teiler")
|
||||
void ggT() {
|
||||
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)));
|
||||
|
@ -1,18 +1,19 @@
|
||||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.vorlesungen.Sieb;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
class VorlesungsTest {
|
||||
|
||||
public class VorlesungsTest {
|
||||
|
||||
@Test
|
||||
void sieb() {
|
||||
public void sieb() {
|
||||
Set<Integer> set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19));
|
||||
assertEquals(set, new Sieb(20).getPrimzahl());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user