package cz.jcu.prf.uai.javamugs.logic;

import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * Game logic test.
 * @author Daniel Hryzbil
 */
public class GameTest extends TestCase {
	
	private static final double TIME_OFFSET = 80.0;
	private static final byte DIFFICULTY = 3;
	
	public void testGameLogic() {
		ArrayList<Press> presses = new ArrayList<Press>();
		presses.add(new Press(Chord.RED,      100.0));
		presses.add(new Press(Chord.YELLOW,   200.0));
		presses.add(new Press(Chord.MAGENTA,  300.0));
		presses.add(new Press(Chord.MAGENTA,  400.0));
		presses.add(new Press(Chord.MAGENTA,  500.0));
		presses.add(new Press(Chord.MAGENTA,  600.0));
		presses.add(new Press(Chord.MAGENTA,  700.0));
		presses.add(new Press(Chord.MAGENTA,  800.0));
		presses.add(new Press(Chord.MAGENTA,  900.0));
        presses.add(new Press(Chord.BLUE,    1000.0));
        presses.add(new Press(Chord.YELLOW,  1100.0));
        presses.add(new Press(Chord.MAGENTA, 1200.0));
        presses.add(new Press(Chord.BLUE,    1300.0));
        presses.add(new Press(Chord.BLUE,    1400.0));
        presses.add(new Press(Chord.RED,     1500.0));
		
        PressChart pressChart = new PressChart(presses);
		Game game = new Game(TIME_OFFSET, DIFFICULTY, pressChart);
		assertNotNull(game);
		
		Chord userInput = new Chord(false, false, false, false, true);  // MAGENTA
		GameReport report;
		double currentTime = 0;
		long expectedScore = 0;
		
		for (int i = 0; i < 5; i++) {
			report = game.tick(currentTime, userInput);
			assertEquals(expectedScore, report.getScore());
			assertEquals(1.0, report.getMultiplier());
			currentTime += 100;
		}
		
		for (int i = 0; i < 4; i++) {
			expectedScore += Game.SCORE_BASE;
			report = game.tick(currentTime, userInput);
			assertEquals(expectedScore, report.getScore());
			assertEquals(1.0, report.getMultiplier());
			currentTime += 100;
		}
		
		for (int i = 0; i < 3; i++) {
			expectedScore += Game.SCORE_BASE * (1.0+Game.MULTIPLIER_BASE);
			report = game.tick(currentTime, userInput);
			assertEquals(expectedScore, report.getScore());
			assertEquals(1.0 + Game.MULTIPLIER_BASE, report.getMultiplier());
			currentTime += 100;
		}
		
		report = game.tick(currentTime, userInput);
		assertEquals(expectedScore, report.getScore());
		assertEquals(1.0, report.getMultiplier());
		currentTime += 100;
		
		report = game.tick(currentTime, userInput);
		assertEquals(expectedScore, report.getScore());
		assertEquals(1.0, report.getMultiplier());
		expectedScore += Game.SCORE_BASE;
		currentTime += 100;
		
		report = game.tick(currentTime, userInput);
		assertEquals(expectedScore, report.getScore());
		assertEquals(1.0, report.getMultiplier());
		currentTime += 100;
		
		report = game.tick(currentTime, userInput);
		assertEquals(expectedScore, report.getScore());
		assertEquals(1.0, report.getMultiplier());
	}
}

@@ -930,24 +930,24 @@
 s(Chord.
-YELLOW, 
+MAGENTA,
  1100.0)
@@ -986,24 +986,24 @@
 s(Chord.
-MAGENTA,
+BLUE,   
  1200.0)
@@ -1066,64 +1066,8 @@
 );%0D%0A
-        presses.add(new Press(Chord.BLUE,    1400.0));%0D%0A
     
@@ -1108,17 +1108,17 @@
 D,     1
-5
+4
 00.0));%0D
@@ -1348,16 +1348,84 @@
 AGENTA%0D%0A
+%09%09Chord emptyInput = new Chord(false, false, false, false, false);%0D%0A
 %09%09GameRe
@@ -1492,24 +1492,195 @@
 e = 0;%0D%0A%09%09%0D%0A
+%09%09report = game.tick(currentTime, emptyInput);%0D%0A%09%09assertEquals(expectedScore, report.getScore());%0D%0A%09%09assertEquals(1.0, report.getMultiplier());%0D%0A%09%09currentTime += 50;%0D%0A%09%09%0D%0A
 %09%09for (int i
@@ -1689,17 +1689,17 @@
  0; i %3C 
-5
+8
 ; i++) %7B
@@ -1857,34 +1857,33 @@
 %09currentTime += 
-10
+5
 0;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09f
@@ -2459,36 +2459,37 @@
 ck(currentTime, 
-user
+empty
 Input);%0D%0A%09%09asser

fix Game logic test