我正在使用以前的考试问题为本周即将到来的考试进行修改,但我无法获得 100% 的覆盖率,我的程序是:
public int computeInsurance(boolean SportsEquipment, boolean MusicEquipment)
{
int insurance;
if(SportsEquipment == true && MusicEquipment==true)
insurance = 20;
else if((SportsEquipment == true && MusicEquipment == false)||(SportsEquipment == false && MusicEquipment == true))
insurance = 10;
else
insurance= 5;
return insurance;
}
}
我正在使用以下测试用例:
public class Lab5CarTest {
@Test
public void testComputeInsurance() {
Lab5Car t = new Lab5Car();
int result = t.computeInsurance(true, true);
assertEquals(20,result);
int i = t.computeInsurance(true,false);
assertEquals(10,i);
int u = t.computeInsurance(false,false);
assertEquals(5,u);
}
}
但是我在代码的 else if 行中缺少 8 个分支中的 3 个!