test case generator using java [closed]
I'm developing an 'Automatic test case generator' using java. The inputs for the java program will be fed by prolog program. If the input is for example an integer 2 then the java program should square the number and display it as output. In the same way if there are 3 integers the java program should accept one number at a time and display all r开发者_如何学Cesults (i mean it should test each case).
As I said in a comment, all inputs are Strings
The program has to convert the strings into different object types to "test each case", such as in the following program.
import java.util.*;
public class CaseTester {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in).useDelimiter(" "); //separate entries with a space
String input;
while (sc.hasNext()) {
input = sc.next();
try {
double num = Double.parseDouble(input);
System.out.println("" + Math.pow(num, 2));
} catch (NumberFormatException e) {
//input was not a number so move to the next "test"
}
try {
URL test = new URL(input);
System.out.println("Valid URL");
} catch (MalformedURLException e) {
//input was not a valid URL so move to the next "test"
}
//put more tests here if you want
}
sc.close();
}
}
Just in case you're confused, you don't always have to conduct tests with a try
block. You can use if
and switch
blocks as well (i.e. if (input.equalsIgnoreCase("dog")) //do something
)
精彩评论