一个可以生成边界值,有效等价类无效等价类的小小程序。
package testcaseBuilderPackage2;
class getRandom {
double getRandom1(double hmin, double hmax) {
double random1 = (double)(Math.random() * (hmax - hmin) + hmin);
return random1;
}
double getRandom2(double wmin, double wmax) {
double random2 =Math.random() * (wmax - wmin) + wmin;
return random2;
}
}
package testcaseBuilderPackage2;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.DecimalFormat;
class TestDouble extends Test {
File file=new File("e:/testcase1.txt");
double hmin = 1.0;
double hmax = 250.0;
double wmin = 0.1;
double wmax = 500.0;
getRandom gr1 = new getRandom();
getRandom gr2 = new getRandom();
DecimalFormat df = new DecimalFormat("0.00");
public void height() throws IOException {
Writer w=new FileWriter(file,true);
String s1="身高的有效等价类为:" +'\r'+'\n'+ df.format(gr1.getRandom1(hmin, hmax))
+ " ; " + df.format(gr2.getRandom2(wmin, wmax))+'\r'+'\n';
String s2="无效等价类为:\r\n" + df.format(hmin - 1) + " ; "
+ df.format(gr2.getRandom2(wmin, wmax)) + '\r'+'\n'
+ df.format(hmin) + " ; "
+ df.format(gr2.getRandom2(wmin, wmax)) + '\r'+'\n'
+ df.format(hmax) + " ; "
+ df.format(gr2.getRandom2(wmin, wmax)) + '\r'+'\n'
+ df.format(hmax + 1) + " ; "
+ df.format(gr2.getRandom2(wmin, wmax))+'\r'+'\n';
w.write(s1);
w.write(s2);
w.close();
}
public void weight() throws IOException {
Writer w=new FileWriter(file,true);
String s3='\r'+'\n'+"体重的有效等价类为:\r\n" + df.format(gr1.getRandom1(hmin, hmax))
+ " ; " + df.format(gr2.getRandom2(wmin, wmax))+'\r'+'\n';
String s4='\n' + "无效等价类为:\r\n"
+ df.format(gr1.getRandom1(hmin, hmax)) + " ; "
+ df.format(wmin - 0.1) + '\r'+'\n'
+ df.format(gr1.getRandom1(hmin, hmax)) + " ; "
+ df.format(wmin) + '\r'+'\n'
+ df.format(gr1.getRandom1(hmin, hmax)) + " ; "
+ df.format(wmax) + '\r'+'\n'
+ df.format(gr1.getRandom1(hmin, hmax)) + " ; "
+ df.format((wmax + 0.1))+'\r'+'\n';
w.write(s3);
w.write(s4);
w.close();
}
}
package testcaseBuilderPackage2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws IOException {
TestDouble td = new TestDouble();
System.out.print("请输入:");
while (true) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
if (s.equals("身高")) {
td.height();
} else if (s.equals("体重")) {
td.weight();
} else {
System.out.print("输入有误,重新输入:");
}
}
}
}
这个只是单一模块,过几天发一下集成的