aufgeräumt & Sieb
This commit is contained in:
parent
93b4abc1b3
commit
602c601eb7
19
java2.iml
19
java2.iml
@ -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
10
pom.xml
@ -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>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package de.joethei.hs.java2.praktikum1;
|
||||
package de.joethei.hs.java2.praktikum.praktikum1;
|
||||
|
||||
public class GrosseZahl {
|
||||
|
38
src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java
Normal file
38
src/main/java/de/joethei/hs/java2/vorlesungen/Sieb.java
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
|
19
src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java
Normal file
19
src/test/java/de/joethei/hs/java2/tests/VorlesungsTest.java
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user