Vorführungen für Coverage aus der Vorlesung
parent
95297fd480
commit
8d06c2faee
|
@ -13,8 +13,13 @@ public class Würfel {
|
|||
}
|
||||
|
||||
public int würfle() {
|
||||
var a = 1;
|
||||
augen = 1 + (int)(Math.random() * SEITEN);
|
||||
|
||||
// try this with Coverage as
|
||||
if (augen == 6 && a >= 1);
|
||||
System.out.println("Los für MÄDN!");
|
||||
|
||||
return augen;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,54 @@
|
|||
package de.hs_mannheim.informatik.games.kniffel.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class WürfelTest {
|
||||
private Würfel w;
|
||||
|
||||
@BeforeAll
|
||||
static void initialisiere() {
|
||||
|
||||
System.out.println("Einmal vor allem!");
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void vorJedem() {
|
||||
w = new Würfel();
|
||||
System.out.println("Vor jedem!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWürfel() {
|
||||
Würfel w = new Würfel();
|
||||
|
||||
void testWürfelEinsBisSechs() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
int augen = w.würfle();
|
||||
assertTrue(augen >= 1 && augen <= 6);
|
||||
assertEquals(augen, w.getAugen());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVerteilung() {
|
||||
Set<Integer> zahlen = new HashSet<>();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
zahlen.add(w.würfle());
|
||||
}
|
||||
|
||||
assertEquals(6, zahlen.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void test8erWürfel() {
|
||||
Würfel w = new Würfel(8);
|
||||
|
||||
|
|
Loading…
Reference in New Issue