开发者

test case generator using java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜