Hi so I am currently working on a project for a java class and I am having trouble with a unit testing portion of the lab. This portion wants us to add three additional tests for three valid arguments and one test for an invalid argument. I tried coding it by myself but I am not well versed in unit testing so I am not sure if it is correct or if the invalid unit test will provide the desired outcome.
@Test
public void isValidPick() {
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SCISSORS));
Assert.assertFalse(RPSLSpock.isValidPick(null));
// TODO remove this comment and add tests for the other three valid arguments
// TODO remove this comment and verify the method returns false if passed and invalid argument like "banana"
}
Here is the portion of code I am specifically referencing. I will post the full code down below. All I want is to know if I coded the unit test correctly and if I did not what I need to change about it to make it correct. Thank you!
Main Class:
import java.util.*;
/**
* Main for Rock, Paper, Scissors, Lizard, Spock
*/
public class Main {
private static Scanner input = new Scanner(System.in);
/**
* Main method for running Rock, Paper, Scissors, Lizard, Spock
* @param args run-time arguments
*/
public static void main(String[] args) {
String h_pick;
String c_pick;
String answer;
boolean isValid;
do {
System.out.println("Let's play rock, paper, scissors, lizard, spock");
do {
System.out.print("Enter your choice: ");
h_pick = input.nextLine();
isValid = RPSLSpock.isValidPick(h_pick);
if (!isValid) {
System.out.println(h_pick + " is not a valid choice");
}
} while (!isValid);
c_pick = RPSLSpock.generatePick();
System.out.print("Computer picked " + c_pick + " ");
if (c_pick.equalsIgnoreCase(h_pick)) {
System.out.println("Tie!");
} else if (RPSLSpock.isComputerWin(c_pick, h_pick)) {
System.out.println("Computer wins!");
} else {
System.out.println("You win!");
}
System.out.print("Play again ('y' or 'n'): ");
answer = input.nextLine();
} while ("Y".equalsIgnoreCase(answer));
System.out.println("Live long and prosper!");
}
}
RPSLSpock Class:
import java.util.Random;
// TODO remove this comment and document this class. Be sure to include an @author tag
public class RPSLSpock {
static Random rand = new Random(System.currentTimeMillis());
public static final String ROCK = "rock";
public static final String PAPER = "paper";
public static final String SCISSORS = "scissors";
public static final String LIZARD = "lizard";
public static final String SPOCK = "spock";
// TODO remove this comment and document this method
public static boolean isValidPick(String pick) {
if (pick == null) {
return false;
}
pick = pick.trim();
return (ROCK.equalsIgnoreCase(pick) ||
PAPER.equalsIgnoreCase(pick) ||
SCISSORS.equalsIgnoreCase(pick) ||
LIZARD.equalsIgnoreCase(pick) ||
SPOCK.equalsIgnoreCase(pick));
}
// TODO remove this comment and document this method
public static String generatePick() {
String pick = null;
switch (rand.nextInt(5)) {
case 0:
pick = ROCK;
break;
case 1:
pick = PAPER;
break;
case 2:
pick = SCISSORS;
break;
case 3:
pick = LIZARD;
break;
case 4:
pick = SPOCK;
break;
}
return pick;
}
// TODO remove this comment and document this method
public static boolean isComputerWin(String c_pick,String h_pick) {
h_pick = h_pick.toLowerCase();
return ((ROCK.equals(c_pick) && (SCISSORS.equals(h_pick) || LIZARD.equals(h_pick))) ||
(PAPER.equals(c_pick) && (ROCK.equals(h_pick) || SPOCK.equals(h_pick))) ||
(SCISSORS.equals(c_pick) && (PAPER.equals(h_pick) || LIZARD.equals(h_pick))) ||
(LIZARD.equals(c_pick) && (PAPER.equals(h_pick) || SPOCK.equals(h_pick))) ||
(SPOCK.equals(c_pick) && (ROCK.equals(h_pick) || SCISSORS.equals(h_pick))));
}
}
RPSLSpockTest Class:
import org.junit.Assert;
import org.junit.Test;
/**
* Set of unit tests for RPSLSpock methods
*/
public class RPSLSpockTest {
/**
* Test isValidPick() method
* Test that it returns true if argument is {rock,paper,scissors,lizard, or spock}
* Test that it returns false if the argument is not a valid input String
*/
@Test
public void isValidPick() {
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SCISSORS));
Assert.assertFalse(RPSLSpock.isValidPick(null));
// TODO remove this comment and add tests for the other three valid arguments
// TODO remove this comment and verify the method returns false if passed and invalid argument like "banana"
}
/**
* Test generatePick() method
* Test that it returns a non-null String
* Test that the String it returns is valid
* Since the method is based on a RANDOM number - test it ONE MILLION times
*/
@Test
public void generatePick() {
for (int i=0; i<1000000; ++i) {
String pick = RPSLSpock.generatePick();
Assert.assertNotNull(pick);
Assert.assertTrue(RPSLSpock.isValidPick(pick));
}
}
/**
* Test the isComputerWin method
* Test it with all ten possible computer win scenarios (it should return true)
* Test it with at least one computer loses scenario to make sure it returns false
*/
@Test
public void isComputerWin() {
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.ROCK,RPSLSpock.SCISSORS));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.ROCK,RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.PAPER,RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.PAPER,RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.LIZARD,RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.LIZARD,RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SPOCK,RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SPOCK,RPSLSpock.SCISSORS));
Assert.assertFalse(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.SPOCK));
}
}
Program Files
Main.java
import java.util.*;
/**
* Main for Rock, Paper, Scissors, Lizard, Spock
*/
public class Main {
private static Scanner input = new Scanner(System.in);
/**
* Main method for running Rock, Paper,2 Scissors, Lizard,
Spock
* @param args run-time arguments
*/
public static void main(String[] args) {
String h_pick;
String c_pick;
String answer;
boolean isValid;
do {
System.out.println("Let's play rock, paper, scissors, lizard,
spock");
do {
System.out.print("Enter your choice: ");
h_pick = input.nextLine();
isValid = RPSLSpock.isValidPick(h_pick);
if (!isValid) {
System.out.println(h_pick + " is not a valid choice");
}
} while (!isValid);
c_pick = RPSLSpock.generatePick();
System.out.print("Computer picked " + c_pick + " ");
if (c_pick.equalsIgnoreCase(h_pick)) {
System.out.println("Tie!");
} else if (RPSLSpock.isComputerWin(c_pick, h_pick)) {
System.out.println("Computer wins!");
} else {
System.out.println("You win!");
}
System.out.print("Play again ('y' or 'n'): ");
answer = input.nextLine();
} while ("Y".equalsIgnoreCase(answer));
System.out.println("Live long and prosper!");
}
}

RPSLSpock.java
import java.util.Random;
/**
* RPSLSpock Class
* @author yourname_here
*/
public class RPSLSpock {
public static String WATER;
static Random rand = new Random(System.currentTimeMillis());
public static final String ROCK = "rock";
public static final String PAPER = "paper";
public static final String SCISSORS = "scissors";
public static final String LIZARD = "lizard";
public static final String SPOCK = "spock";
/**
*
* @param pick users choice
* @return false when pick is null
* when user picks valid option, uses ignoreCase to return
pick
*/
public static boolean isValidPick(String pick) {
if (pick == null) {
return false;
}
pick = pick.trim();
return (ROCK.equalsIgnoreCase(pick) ||
PAPER.equalsIgnoreCase(pick) ||
SCISSORS.equalsIgnoreCase(pick) ||
LIZARD.equalsIgnoreCase(pick) ||
SPOCK.equalsIgnoreCase(pick));
}
/**
* randomly generated pick from 5 options (array), breaks once a
pick has been matched
* @return computer generated pick
*/
public static String generatePick() {
String pick = null;
switch (rand.nextInt(5)) {
case 0:
pick = ROCK;
break;
case 1:
pick = PAPER;
break;
case 2:
pick = SCISSORS;
break;
case 3:
pick = LIZARD;
break;
case 4:
pick = SPOCK;
break;
}
return pick;
}
/**
*
* @param c_pick computer generated pick versus
* @param h_pick human chosen pick
* @return resultant is a computer win
*/
public static boolean isComputerWin(String c_pick,String h_pick)
{
h_pick = h_pick.toLowerCase();
return ((ROCK.equals(c_pick) && (SCISSORS.equals(h_pick) ||
LIZARD.equals(h_pick))) ||
(PAPER.equals(c_pick) && (ROCK.equals(h_pick) ||
SPOCK.equals(h_pick))) ||
(SCISSORS.equals(c_pick) && (PAPER.equals(h_pick) ||
LIZARD.equals(h_pick))) ||
(LIZARD.equals(c_pick) && (PAPER.equals(h_pick) ||
SPOCK.equals(h_pick))) ||
(SPOCK.equals(c_pick) && (ROCK.equals(h_pick) ||
SCISSORS.equals(h_pick))));
}
}


RPSLSpockTest.java
import org.junit.Assert;
import org.junit.Test;
/**
* Set of unit tests for RPSLSpock methods
*/
public class RPSLSpockTest {
/**
* Test isValidPick() method
* Test that it returns true if argument is
{rock,paper,scissors,lizard, or spock}
* Test that it returns false if the argument is not a valid input
String
*/
@Test
public void isValidPick() {
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.SCISSORS));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isValidPick(RPSLSpock.ROCK));
Assert.assertFalse(RPSLSpock.isValidPick(RPSLSpock.WATER));
}
/**
* Test generatePick() method
* Test that it returns a non-null String
* Test that the String it returns is valid
* Since the method is based on a RANDOM number - test it ONE
MILLION times
*/
@Test
public void generatePick() {
for (int i=0; i<1000000; ++i) {
String pick = RPSLSpock.generatePick();
Assert.assertNotNull(pick);
Assert.assertTrue(RPSLSpock.isValidPick(pick));
}
}
/**
* Test the isComputerWin method
* Test it with all ten possible computer win scenarios (it should
return true)
* Test it with at least one computer loses scenario to make sure it
returns false
*/
@Test
public void isComputerWin() {
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.ROCK,RPSLSpock.SCISSORS));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.ROCK,RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.PAPER,RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.PAPER,RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.LIZARD));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.LIZARD,RPSLSpock.PAPER));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.LIZARD,RPSLSpock.SPOCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SPOCK,RPSLSpock.ROCK));
Assert.assertTrue(RPSLSpock.isComputerWin(RPSLSpock.SPOCK,RPSLSpock.SCISSORS));
Assert.assertFalse(RPSLSpock.isComputerWin(RPSLSpock.SCISSORS,RPSLSpock.SPOCK));
}
}


output
Let's play rock, paper, scissors, lizard, spock
Enter your choice: rock
Computer picked rock Tie!
Play again ('y' or 'n'): y
Let's play rock, paper, scissors, lizard, spock
Enter your choice: paper
Computer picked scissors Computer wins!
Play again ('y' or 'n'): n
Live long and prosper!

Hope this helps!
Please let me know if any changes needed.
Thank you!
Hi so I am currently working on a project for a java class and I am...
java pls
Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
easy question but i am confused. someone help
Consider the following Java classes: class OuterClass { static class InnerClass { public void inner Method({ System.out.println("This is my inner class"); public static void outer Method{ System.out.println("This is my outer class"); public class OuterClass Test{ public static void main(String args[]) { Complete the class OuterClass Test to produce as output the two strings in class OuterClass. What are the outputs of your test class?
Modify your Rock Paper Scissor (Lizard/Spock) game from Week 5 to generate a random number for Player 2 and assign that as Player 2's choice. The rest of your program should stay the same. You can use your program with the nested if statements or the switch statement. The implementation should use the Random class to get your random number. The assignment is worth 10 points. Upload your submission to the assignment. code: import java.util.Scanner; public class RPSLSYourLastName { ...
IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....
(Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...
I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) { int choice; Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result; Scanner scanner = new Scanner(System.in); System.out.print("Enter 1\t UsDollars to Yen:...
Starting codes:MathQuiz.javaimport java.util.Scanner;public class MathQuiz { private final int NUMBER_OF_QUESTIONS = 10; private final MathQuestion[] questions = new MathQuestion[NUMBER_OF_QUESTIONS]; private final int[] userAnswers = new int[NUMBER_OF_QUESTIONS]; public static void main(String[] args) { MathQuiz app = new MathQuiz(); System.out.println(app.welcomeAndInstructions()); app.createQuiz(); app.administerQuiz(); app.gradeQuiz(); } private String welcomeAndInstructions() { return "Welcome to Math Quiz!\n" + ...
How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...
“Oh I know, let’s play Rock, Paper, Scissors, Lizard, Spock. It’s very simple.” What better way to expand the classic Rock, Paper, Scissors game than to add Lizard and Spock! Sheldon and Raj brought Sam Kass’s game to life on The Big Bang Theory in “The Lizard-Spock Expansion” episode. Assignment & Discussion Your task in Programming Assignment 8 is to create a C# console app-version of Rock, Paper, Scissors, Lizard, Spock (RPSLS). Use any of the programming tools and techniques...