swing - java testing junit help wrong input -


ok guys neeed quick assigment think not difficult

you see have write bowling code kata this

http://programmingpraxis.com/2009/08/11/uncle-bobs-bowling-game-kata/

and have writen code

here 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 strike                 score+=10 + rolls[cursor+1] + rolls[cursor+2];                 cursor++;             }else if(rolls[cursor] + rolls[cursor+1]==10){ // check if spare                 score+=10 + rolls[cursor+2];                 cursor+=2;             }else{                 score+=rolls[cursor] + rolls[cursor+1];                 cursor+=2;             }         }         return score;      }  } 

and here testing 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 = 15;         game.roll(a);      }        @test (expected = illegalargumentexception.class)     public void testingletter() {         char c = 'c';         game.roll(c);      }   } 

**my question how can test

test wrong input 15 1 throw

with 2 throws in same frame bigger 10

with letter input

**

just use expected annotation parameter.

@test(expected = illegalargumentexception.class) public void cantscoremorethan10points() {     game.roll(15,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3); } 

Comments