public class TestPlayEngine { public static void main(String[] args) { RefPlayEngine refEngine = new RefPlayEngine(); PlayEngine myEngine = new PlayEngine(); boolean hasFailed = false; int[] dice = new int[5]; for (int i = 1; i <= 6; i++) { dice[0] = i; for (int j = 1; j <= 6; j++) { dice[1] = j; for (int k = 1; k <= 6; k++) { dice[2] = k; for (int l = 1; l <= 6; l++) { dice[3] = l; for (int m = 1; m <= 6; m++) { dice[4] = m; // evaluate() may alter the input. Pass a clone. int[] diceClone = dice.clone(); int[] refScores = refEngine.evaluate(diceClone); diceClone = dice.clone(); int[] scores = myEngine.evaluate(diceClone); if(checkScores(dice, refScores, scores)) { hasFailed = true; } } } } } } if(!hasFailed) { System.out.println("Poängberäkningen funkar OK!"); } } public static boolean checkScores(int[] dice, int[] refScore, int[] myScore) { String[] scoreNames = { "ettor", "tvåor", "treor", "fyror", "femmor", "sexor", "par", "två par", "triss", "fyrtal", "liten stege", "stor stege", "kåk", "chans", "yatzy" }; boolean hasFailed = false; for (int i = 0; i < 15; i++) { if (refScore[i] != myScore[i]) { System.out.println("Fel poäng för " + dice[0] + " " + dice[1] + " " + dice[2] + " " + dice[3] + " " + dice[4] + ", " + scoreNames[i] + ". Borde varit " + refScore[i] + " men var " + myScore[i]); hasFailed = true; } } return hasFailed; } }