lundi 15 mai 2017

Need help in passing test for rock paper scissor game

`char getInput(String prompt, char[] options, Scanner sc) {
   // getInput method
   // prompts user for an input that matches one of the given characters
   // if its not one of those, repeat. (use contains (above))
   char ch;
   boolean con = false;
   String printStr = prompt + " (";
   for (int i = 0; i < options.length; i++) {
       printStr += " " + options[i] + ",";
   }
   printStr = printStr.substring(0, printStr.length() - 1) + " ):";

   do {
       ch = sc.next().charAt(0);
       System.out.println(printStr);
       if (contains(ch, options)) {
           con = true;
       }
   }
   while (!con);
   return ch;

}

I have made the above code...but it is showing this error... i have to pass the test without changing the test code

Exception in thread "main"` `java.lang.Asse`rtionError: 26 13

Doug ( v ): Doug ( v ): Doug ( v ):

at RPSTester.assertOutput(RPSTester.java:227)
at RPSTester.testGetInput(RPSTester.java:88)
at RPSTester.main(RPSTester.java:16)

test code void testGetInput() { OutputStream out;

  out = resetSystemOut();
  assert 'y' == RPS.getInput("Choose", new char[] {'y','n','q'}, new Scanner("y\n"));
  assertOutput("Choose ( y, n, q ):\n", out);
  out = resetSystemOut();
  assert 'n' == RPS.getInput("Alice", new char[] {'y','n','q'}, new Scanner("n\n"));
  assertOutput("Alice ( y, n, q ):\n", out);
  out = resetSystemOut();
  assert 'q' == RPS.getInput("Bob", new char[] {'y','n','q'}, new Scanner("q\n"));
  assertOutput("Bob ( y, n, q ):\n", out);
  out = resetSystemOut();
  assert 'q' == RPS.getInput("Cloe", new char[] {'y','n','q'}, new Scanner("x\nw\nq\n"));
  assertOutput("Cloe ( y, n, q ):\n" +
     "Cloe ( y, n, q ):\n" +
     "Cloe ( y, n, q ):\n", out);
  out = resetSystemOut();
  assert 'v' == RPS.getInput("Doug", new char[] {'v'}, new Scanner("vvvv\nv\n"));
  assertOutput("Doug ( v ):\n" +
     "Doug ( v ):\n", out);

}

Aucun commentaire:

Enregistrer un commentaire