From d3984e702407193ccc73d22635e45c972642ca53 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Fri, 6 Apr 2018 12:06:34 +0200 Subject: [PATCH] Duda --- pom.xml | 12 -------- .../praktikum/praktikum2/CharCollection.java | 27 +++++++++++++++++ .../hs/java2/tests/GrosseZahlTest.java | 29 +++++++------------ .../hs/java2/tests/VorlesungsTest.java | 9 +++--- 4 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java diff --git a/pom.xml b/pom.xml index b67b0f9..71835cf 100644 --- a/pom.xml +++ b/pom.xml @@ -42,24 +42,12 @@ - - org.junit.jupiter - junit-jupiter-api - 5.1.0 - test - junit junit 4.12 test - - org.junit.jupiter - junit-jupiter-engine - 5.1.0 - test - org.junit.vintage junit-vintage-engine diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java new file mode 100644 index 0000000..f695d1b --- /dev/null +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum2/CharCollection.java @@ -0,0 +1,27 @@ +package de.joethei.hs.java2.praktikum.praktikum2; + +import java.util.*; + +public class CharCollection { + ArrayList 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; + } + +} \ No newline at end of file diff --git a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java index feca862..53b7a4f 100644 --- a/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/GrosseZahlTest.java @@ -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))); diff --git a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java index 2ead880..c3ee50d 100644 --- a/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java +++ b/src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java @@ -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 set = new TreeSet<>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19)); assertEquals(set, new Sieb(20).getPrimzahl()); }