aufgeräumt & Sieb

This commit is contained in:
Johannes Theiner 2018-04-05 17:10:11 +02:00
parent 93b4abc1b3
commit 602c601eb7
7 changed files with 69 additions and 29 deletions

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

10
pom.xml
View File

@ -55,11 +55,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</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>

View File

@ -1,4 +1,4 @@
package de.joethei.hs.java2.praktikum1;
package de.joethei.hs.java2.praktikum.praktikum1;
public class GrosseZahl {

View File

@ -0,0 +1,38 @@
package de.joethei.hs.java2.vorlesungen;
import java.util.Set;
import java.util.TreeSet;
public class Sieb {
private int n;
public Sieb(int n) {
this.n = n;
}
public Set<Integer> getPrimzahl() {
Set<Integer> set = new TreeSet<>();
for(int i = 2; i <= n; i++) {
set.add(i);
}
Set<Integer> not = new TreeSet<>();
int mult;
int number = 2;
do{
mult = 2*number;
while (mult <= n) {
not.add(mult);
mult += number;
}
do {
number++;
}
while (not.contains(number));
}while (number * number <= n);
set.removeAll(not);
return set;
}
}

View File

@ -1,11 +1,12 @@
package de.joethei.hs.java2.tests;
import de.joethei.hs.java2.praktikum1.GrosseZahl;
import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Eigene GrosseZahl")
class GrosseZahlTest {
@Test

View File

@ -1,11 +1,12 @@
package de.joethei.hs.java2.tests;
import static org.junit.Assert.*;
import de.joethei.hs.java2.praktikum1.GrosseZahl;
import de.joethei.hs.java2.praktikum.praktikum1.GrosseZahl;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class GrosseZahlTest2 {
GrosseZahl i0;

View File

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