您的位置:首页 > 其它

软件测试学习(3) 第一次上机实验

2016-03-19 17:11 274 查看
实验要求:

Install Junit(4.12), Hamcrest(1.3) with Eclipse

Install Eclemma with Eclipse

Write a java program for the triangle problem and test the program with Junit.

  a) Description of triangle problem:

  Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.

实验代码:

Triangle类:

package ST;

public class Triangle {
public String judge(double a, double  b, double  c)
{
if(a+b>c&&b+c>a&&a+c>b)
{
if(a==b||b==c||c==a)
{
if(a==b&&b==c)
return "equilateral";
else return "isosceles";
}
else return "scalene";
}
else return "it is not a triangle";
}
}


测试类:

package ST;

import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert .*;

public class TriangleTest {
private Triangle triangle;

@Before
public void setUp() throws Exception {
triangle = new Triangle();
}

@Test
public void test()
{
assertEquals("isosceles", triangle.judge(4,4,5));
assertEquals("it is not a triangle", triangle.judge(1,1,5));
assertEquals("equilateral", triangle.judge(4,4,4));
assertEquals("scalene", triangle.judge(3,4,5));
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: