Lab1 Report

Lab1 report

A) The brief description that you install junit, hamcrest and eclemma.

a)  install junit、hamcrest:
方式一:导入jar包。
1、鼠标右击项目名,点击‘Properties’一栏;
2、如下图点击‘Add External JARs’;

 


3、选中下载好的junit和hamcrest的jar包,打开即可。

 


方式二,添加junit库:
1、鼠标右击项目名,点击‘Properties’一栏;
2、如下图点击‘Add Library’;

 


3、选中Junit一栏,点击‘Next’;

 


4、选择Junit版本,之后点击‘Finish’。

 



b) install eclemma
1、下载jacoco,链接: http://www.eclemma.org/jacoco/ 根据系统选择适合的版本即可;
2、下载完成后,解压文件,将lib目录下的所有jar包放入eclipse安装目录的‘plugins’文件夹下;

 


3、在eclipse窗口依次点击HelpàEclipse Marktplaceà在‘Find’一栏输入:eclemmaà点击安装即可。

 

B) The test result and coverage report (print screen) of your tests on triangle problem.

test result:

 

 

coverage report:

 

source codes:

TriangleProblem.java:

 1 package cn.tju.triangleproblem;
 2 
 3 public class TriangleProblem {
 4 
 5     public TriangleProblem() {
 6         // TODO Auto-generated constructor stub
 7     }
 8 
 9     public String TriangleTypes(int a, int b, int c) {
10 
11         if (a + b > c && b + c > a && c + a > b) {
12             if (a == b && b == c)
13                 return "equilateral";
14             if (a == b || b == c || c == a)
15                 return "isosceles";
16 
17             return "scalene";
18         } else
19             return "Error, not a triangle!";
20 
21     }
22 
23 }

 

  TriangleProblemTest.java:

  

 1 package cn.tju.triangleproblem;
 2 
 3 import static org.junit.Assert.*;
 4 
 5 import java.util.Arrays;
 6 import java.util.Collection;
 7 
 8 import org.junit.Before;
 9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.junit.runners.Parameterized;
12 import org.junit.runners.Parameterized.Parameters;
13 
14 @RunWith(Parameterized.class)
15 public class TriangleProblemTest {
16     private String expectResult = "";
17     private int edgeA, edgeB, edgeC;
18     private TriangleProblem tp;
19 
20     public TriangleProblemTest(String expectResult, int edgeA, int edgeB,
21             int edgeC) {
22         super();
23         this.expectResult = expectResult;
24         this.edgeA = edgeA;
25         this.edgeB = edgeB;
26         this.edgeC = edgeC;
27     }
28 
29     @Before
30     public void setUp() {
31         tp = new TriangleProblem();
32     }
33 
34     @Test
35     public void testTriangleTypes() {
36         assertEquals(this.expectResult,
37                 tp.TriangleTypes(this.edgeA, this.edgeB, this.edgeC));
38     }
39 
40     @Parameters
41     public static Collection<Object[]> getData() {
42         return Arrays.asList(new Object[][] { { "equilateral", 6, 6, 6 },
43                 { "isosceles", 9, 9, 8 }, { "scalene", 4, 5, 6 },
44                 { "Error, not a triangle!", 3, 6, 9 }});
45     }
46 
47 }

 

posted @ 2018-03-22 12:02  豪客迈斯  阅读(183)  评论(0编辑  收藏  举报