Skip to content
Snippets Groups Projects
Commit 5490e387 authored by Luca Romano's avatar Luca Romano
Browse files

Tests added

parent 1c98f361
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
File added
File deleted
...@@ -2,7 +2,7 @@ package io.fp.Primzahlen; ...@@ -2,7 +2,7 @@ package io.fp.Primzahlen;
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
Spiel spiel = new Spiel(); PrimGame spiel = new PrimGame();
spiel.play(); spiel.play();
} }
} }
package io.fp.Primzahlen; package io.fp.Primzahlen;
public enum Level { public enum Level {
EINFACH,MITTEL, SCHWER; BEGINNER, INTERMEDIATE, PRO;
public Level getNextLevel() { public Level getNextLevel() {
return values()[(ordinal() +1) % values().length]; return values()[(ordinal() +1) % values().length];
......
...@@ -3,12 +3,24 @@ package io.fp.Primzahlen; ...@@ -3,12 +3,24 @@ package io.fp.Primzahlen;
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class Spiel { public class PrimGame {
private Level level; private Level level;
private int zahl; private int number;
public Spiel() { public PrimGame() {
this.level = Level.EINFACH; this.level = Level.BEGINNER;
}
public int getNumber() {
return number;
}
public Level getLevel() {
return level;
}
public void levelUp(){
level = level.getNextLevel();
} }
public boolean checkIfPrim(int anwser) { public boolean checkIfPrim(int anwser) {
...@@ -24,17 +36,17 @@ public class Spiel { ...@@ -24,17 +36,17 @@ public class Spiel {
int i = 0; int i = 0;
Random rand = new Random(); Random rand = new Random();
switch (level) { switch (level) {
case EINFACH: case BEGINNER:
i = rand.nextInt(100 - 1 + 1) + 1; i = rand.nextInt(100 - 1 + 1) + 1;
break; break;
case MITTEL: case INTERMEDIATE:
i = rand.nextInt(800 - 100 + 1) + 100; i = rand.nextInt(800 - 100 + 1) + 100;
break; break;
case SCHWER: case PRO:
i = rand.nextInt(1000 - 800 + 1) + 800; i = rand.nextInt(1000 - 800 + 1) + 800;
break; break;
} }
zahl = i; number = i;
} }
public void play() { public void play() {
...@@ -42,14 +54,14 @@ public class Spiel { ...@@ -42,14 +54,14 @@ public class Spiel {
try (Scanner scanner = new Scanner(System.in)) { try (Scanner scanner = new Scanner(System.in)) {
for (int i = 0; i < 15; i++) { for (int i = 0; i < 15; i++) {
if (i == 5 || i == 10) { if (i == 5 || i == 10) {
level = level.getNextLevel(); levelUp();
System.out.println("You reached the Level: " + level.toString()); System.out.println("You reached the Level: " + level.toString());
} }
generateNumber(); generateNumber();
System.out.println("Is " + zahl + " a prime number? (true/false)"); System.out.println("Is " + number + " a prime number? (true/false)");
String answer = scanner.nextLine(); String answer = scanner.nextLine();
if (checkIfPrim(zahl) == Boolean.parseBoolean(answer)) { if (checkIfPrim(number) == Boolean.parseBoolean(answer)) {
System.out.println("You right!"); System.out.println("You right!");
count++; count++;
} }
......
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package io.fp.Primzahlen;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class AppTest {
PrimGame game;
@BeforeEach
void setUp(){
game = new PrimGame();
}
@Test void testifCorrect() {
assertEquals(true, game.checkIfPrim(11));
}
@Test void testifCorrectforBeginner() {
int[] prim = new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 , 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
for(int i : prim){
assertEquals(true, game.checkIfPrim(i));
}
}
@Test void testLevel() {
game.generateNumber();
assertTrue(game.getNumber()<100);
game.levelUp();
game.generateNumber();
assertTrue(game.getNumber()<800&& game.getNumber()>100);
game.levelUp();
game.generateNumber();
assertTrue(game.getNumber()<1000 && game.getNumber()>800);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment