Click here to Skip to main content
15,887,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok guys I neeed quick help with my assigment I think it is not something difficult
You see I have to write Bowling Code kata like this
?
1
http://programmingpraxis.com/2009/08/11/uncle-bobs-bowling-game-kata/


and I have writen the code for it

Here is my Bowling Class

public class BowlingGame {
private int roll = 0;
private int [] rolls = new int[21];
 
 
public void roll(int...rolls){
    for(int pinsDown:rolls){
        if(pinsDown>10){
            throw new IllegalArgumentException();
        }else{
        roll(pinsDown);
        }
 
    }
 
}
 
 
public void roll(int pinsDown){
    rolls[roll++] =pinsDown;
}
 
 
public int score(){
    int score = 0;
    int cursor = 0;
 
    for(int frame = 0;frame<10;frame++){
        if(rolls[cursor]==10){ // check if it is strike
            score+=10 + rolls[cursor+1] + rolls[cursor+2];
            cursor++;
        }else if(rolls[cursor] + rolls[cursor+1]==10){ // check if it is spare
            score+=10 + rolls[cursor+2];
            cursor+=2;
        }else{
            score+=rolls[cursor] + rolls[cursor+1];
            cursor+=2;
        }
    }
    return score;
 
}
}



and here is my Test Class


public class TestBowling {
private BowlingGame game;
 
@Before
public void setingUp(){
    game = new BowlingGame();
}
 
@Test
public void canScore60(){
    game.roll(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3);
    assertThat(game.score(), is(60));
 
}
 
 
 
@Test
public void canScorePerfect(){
    game.roll(10,10,10,10,10,10,10,10,10,10,10,10);
    assertThat(game.score(), is(300));
 
}
 
 
@Test
public void canScore67(){
    game.roll(3,3,3,3,3,3,3,3,4,6,3,3,3,3,3,3, 3,3, 3,3);
    assertThat(game.score(), is(67));
 
}
 
 
@Test
public void canScore75(){
    game.roll(3,3,3,3,3,3,3,3,4,6,4,6,3,3,3,3, 3,3, 3,3);
    assertThat(game.score(), is(75));
 
}
 
 
@Test
public void canScore70(){
    game.roll(3,3,3,3,3,3,3,3,10,3,3,3,3,3,3, 3,3, 3,3);
    assertThat(game.score(), is(70));
 
}
 
 
@Test
public void canScore87(){
    game.roll(3,3,3,3,3,3,3,3,10,10,3,3,3,3,3, 3,3, 3,3);
    assertThat(game.score(), is(87));
 
}
 
 
@Test
public void canScore70with10(){
    game.roll(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,10,3,3);
    assertThat(game.score(), is(70));
 
}
 
 
 
 
@Test
public void canScore84(){
    game.roll(3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,10,10,10);
    assertThat(game.score(), is(84));
 
}
 
 
@Test
public void canScoreWith3and7(){
    game.roll(3,7,3,7,3,7,3,7,3,7,3,7,3,7,3,7,3,7,3,7,3);
    assertThat(game.score(), is(130));
 
}
 
 
 
 
 
 
 
 
 
//this tests should fail
 
@Test (expected = IllegalArgumentException.class)
public void testing15() {
    int a = 15;
    game.roll(a);
 
}
 
 
 
@Test (expected = IllegalArgumentException.class)
public void testingLetter() {
    char c = 'c';
    game.roll(c);
 
}
}




My Question is how can I test this

Test wrong input with 15 for one throw
with two throws in the same frame bigger than 10
with a letter input
Posted
Updated 28-Jan-16 22:56pm
v2
Comments
Richard MacCutchan 29-Jan-16 4:57am    
Please do not use bold text; we are all capable of reading normal weight text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900