In: Computer Science
import java.util.Scanner;
public class CompareNums {
private static String comparison( int first, int second){
if (first < second)
return "less than";
else if (first == second)
return "equal to";
else
return "greater than";
}
// DO NOT MODIFY main!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter first integer: ");
int first = input.nextInt();
System.out.print("Enter second integer: ");
int second = input.nextInt();
System.out.println("The first integer is " +
comparison(first, second) +
" the second integer.");
}
}
NEED HELP WITH TEST CODE
public class CompareNumsTest {
// TODO - write your code below this comment.
// Write three tests, where each test corresponds to one
// of the three possible scenarios:
// - CompareNums.comparison returns "less than"
// - CompareNums.comparison returns "equal to"
// - CompareNums.comparison returns "greater than"
}
Here are the 3 test cases. Please note: The comparison method in the CompareNums.java class is marked as private, it should be public otherwise we cant access it from the CompareNumsTest.java class, so when you run the test please make it public instead of private
===================================================================
import static org.junit.Assert.assertEquals; import org.junit.Test; public class CompareNumsTest { // TODO - write your code below this comment. // Write three tests, where each test corresponds to one // of the three possible scenarios: // - CompareNums.comparison returns "less than" // - CompareNums.comparison returns "equal to" // - CompareNums.comparison returns "greater than" @Test public void testLessThan() { assertEquals(CompareNums.comparison(10, 11), "less than"); } @Test public void testEqualTo() { assertEquals(CompareNums.comparison(11, 11), "equal to"); } @Test public void testGreaterThan() { assertEquals(CompareNums.comparison(11, 10), "greater than"); } }
=====================================================================