一个水库水位报警的程序

[size=xx-small][/size][color=red]package csdn;

public class River {
[color=red][/color][color=red][/color]
private double curWaterLevel;
private double warnningLevel;

public River() {
}

public River(double curWaterLevel, double warnningLevel) {
this.curWaterLevel = curWaterLevel;
this.warnningLevel = warnningLevel;
}

public void flow() throws Exception {
System.out.println(doFlow());
}

//doFlow保证flow方法可测试!flow直接打印doFlow()方法返回值
public String doFlow() throws Exception {
if (curWaterLevel - warnningLevel >= 10) {
throw new Exception("决堤啦");
}

return "安静的流";
}

public double getCurWaterLevel() {
return curWaterLevel;
}

public void setCurWaterLevel(double curWaterLevel) {
this.curWaterLevel = curWaterLevel;
}

public void setWarnningLevel(double warnningLevel) {
this.warnningLevel = warnningLevel;
}

public double getWarnningLevel() {
return warnningLevel;
}

}


//测试用例
//Java code
package csdn.junit;

import junit.framework.TestCase;
import csdn.River;

public class RiverNormalTestor extends TestCase {

public void testNormal() {
// 测试没有异常
try {
River river = new River(19, 10);
assertEquals("安静的流", river.doFlow());
} catch (Exception e) {
assertTrue(false);
}
}

public void testException() {
// 测试存在异常 1
try {
new River(20, 10).doFlow();
assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}

// 测试存在异常 2
try {
new River(20, 10).doFlow();
assertTrue(false);
} catch (Exception e) {
assertTrue(true);
}

}
}[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值