package sizeys;
import java.text.DecimalFormat;
import java.util.Scanner;
public class H {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
System.out.print("请输入第一个数:");
double x = scanner.nextDouble();
System.out.print("请输入第二个数:");
double y = scanner.nextDouble();
System.out.print("请输入运算符:");
String s = scanner.next();
char z = s.charAt(0);
js.yunsuan(x, y, z);
} catch (Exception e) {
System.out.println("请输入正确的数据!");
}
}
}
package sizeys;
import java.text.DecimalFormat;
public class js {
public static void yunsuan(double x, double y, Character z) {
DecimalFormat r = new DecimalFormat();
r.applyPattern("#0.00");
if (z.equals(‘+‘)) {
jia.yunsuan1(x, y);
// System.out.println(x + "+" + y + "=" + r.format((x + y)));
} else if (z.equals(‘-‘)) {
jia.yunsuan2(x, y);
// System.out.println(x + "-" + y + "=" + r.format((x - y)));
} else if (z.equals(‘*‘)) {
jia.yunsuan3(x, y);
// System.out.println(x + "*" + y + "=" + r.format((x * y)));
} else if (z.equals(‘/‘)) {
if (y == 0) {
System.out.println("被除数不能为0");
} else {
jia.yunsuan4(x, y);
// System.out.println(x + "/" + y + "=" + r.format((x / y)));
}
} else {
System.out.println("无法识别改运算符");
}
}
}
package sizeys;
import java.text.DecimalFormat;
public class jia {
public static double yunsuan1(double x, double y) {
DecimalFormat r = new DecimalFormat();
r.applyPattern("#0.00");
System.out.println(x + "+" + y + "=" + r.format((x + y)));
return x + y;
}
public static double yunsuan2(double x, double y) {
DecimalFormat r = new DecimalFormat();
r.applyPattern("#0.00");
System.out.println(x + "-" + y + "=" + r.format((x - y)));
return x - y;
}
public static double yunsuan3(double x, double y) {
DecimalFormat r = new DecimalFormat();
r.applyPattern("#0.00");
System.out.println(x + "*" + y + "=" + r.format((x * y)));
return x * y;
}
public static double yunsuan4(double x, double y) {
DecimalFormat r = new DecimalFormat();
r.applyPattern("#0.00");
System.out.println(x + "/" + y + "=" + r.format((x / y)));
return x / y;
}
}
package sizeys;
import static org.junit.Assert.*;
import org.junit.Test;
public class jiaTest {
@SuppressWarnings("static-access")
@Test
public void testYunsuan1() {
jia core1 = new jia();
double a = core1.yunsuan1(9, -3);
// 测一下:9和-3传入我的add方法里面,结果会不会是6?
// assertEquals(6, a);
}
@Test
public void testYunsuan2() {
jia core2 = new jia();
double b = core2.yunsuan2(9, 4);
}
@Test
public void testYunsuan3() {
jia core3 = new jia();
double c = core3.yunsuan3(9, -1);
}
@Test
public void testYunsuan4() {
jia core4 = new jia();
double d = core4.yunsuan4(9, 5);
}
}


以下为黑盒法与白盒法测试技术:
1.黑盒法测试。这个测试主要就是以用户角度测试代码的功能与用途:
|
测试用例 |
输入条件 |
有效等价类 |
无效等价类 |
|
题目有效性判断 |
只允许数字 |
8 |
OP |
|
输入字符的有效性判断 |
(8,2,OP) |
8,2 |
OP |
|
测试对象 |
测试说明 |
测试数据 |
测试结果 |
|
题目数量 |
输入非法数据 |
t |
请输入正确的数据! |
|
加减乘除计算 |
输入符号有误 |
5 6 o |
无法识别该运算符 |
|
计算范围 |
精确度 |
11.0和11和11.00 |
正确 |
2.白盒法测试。对软件的过程性细节做细致的检查。
|
测试用例 |
用例说明 |
实际结果 |
|
加法处理 |
1.2+2.3 |
3.50 |
|
减法处理 |
9-4.2 |
4.80 |
|
乘法处理 |
11*3.0 |
33.00 |
|
除法处理 |
8.0/2 |
4.0 |
|
除零处理 |
5.0/0 |
抛出异常 |
|
代码覆盖率 |
100% |
100% |
同伴:201306114208,陈秋亮。
微博:http://www.cnblogs.com/chenqiuliang/
原文:http://www.cnblogs.com/diaoyi/p/4486514.html