package dojo.java;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @author Norbert Wigbels (norbert@wigbels.de)
 */
public class BowlingGameTest {
    BowlingGame bg;

    @Before
    public void setup() {
        bg = new BowlingGame();
    }

    @Test
    public void testAllZeros() {
        rollForward(20, 0);
        assertEquals(0, bg.calcScore());
    }

    @Test
    public void testAllOnes() {
        rollForward(20, 1);
        assertEquals(20, bg.calcScore());
    }

    @Test
    public void testAllStrikes() {
        rollForward(12, 10);
        assertEquals(300, bg.calcScore());
    }

    @Test
    public void testOneSpare() {
        rollForward(4, 0);
        bg.roll(5);       // roll, that is
        bg.roll(5);       //
        bg.roll(3);       /* bonus */
        rollForward(13, 0);
        assertEquals(16, bg.calcScore());
    }

    @Test
    public void testOneStrike() {
        rollForward(4, 0);
        bg.roll(10);    /* strike, that is */
        bg.roll(3);     // bonus
        bg.roll(4);     //
        rollForward(12, 0);
        assertEquals(24, bg.calcScore());
    }

    @Test
    public void testSampleGame() {
        bg.roll(1);
        bg.roll(4);
        bg.roll(4);
        bg.roll(5);
        bg.roll(6);
        bg.roll(4);
        bg.roll(5);
        bg.roll(5);
        bg.roll(10);
        bg.roll(0);
        bg.roll(1);
        bg.roll(7);
        bg.roll(3);
        bg.roll(6);
        bg.roll(4);
        bg.roll(10);
        bg.roll(2);
        bg.roll(8);
        bg.roll(6);
        assertEquals(133, bg.calcScore());
    }

    private void rollForward(int rounds, int pins) {
        for (int i = 0; i < rounds; i++) {
            bg.roll(pins);
        }
    }

}
