上机1(Sjx)

项目属性中找到Build java path ,add Library中添加junit4,然后就可以使用了,效果如图一,

install new software中安装Eclemma ,安装完毕后在测试代码选择coverage as即可,效果如图二。

 

代码:

package shiyan;

 

public class Sjx {

private double a;

private double b;

private double c;

private String temp;

public Sjx(double a, double b, double c) {

super();

this.a = a;

this.b = b;

this.c = c;

}
public boolean isSjx(){//判断三角形

if(a+b<=c || a+c<=b || b+c<=a){

return false;

}

else{

return true;

}

}

public String cal(){
if(isSjx()){

if(a==b&&a==c){
temp="等边三角形";
}
else if(a==b||a==c||b==c){
temp="等腰三角形";
}
else{
temp="其他三角形";
}
}
else{
return "构不成三角形";
}
return temp;
}

}

 

测试:

public class SjxTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Test
public void test1(){
Sjx test1=new Sjx(1,1,1);
String rs=test1.cal();
System.out.println(rs);
}
@Test
public void test2() {
Sjx test2=new Sjx(1,2,1);
String rs=test2.cal();
System.out.println(rs);
}
@Test
public void test3() {
Sjx test3=new Sjx(5,5,4);
String rs=test3.cal();
System.out.println(rs);
}
@Test
public void test4() {
Sjx test4=new Sjx(2,3,4);
String rs=test4.cal();
System.out.println(rs);
}
}

 

posted on 2018-03-22 11:21  mxwmwx  阅读(125)  评论(0编辑  收藏  举报