软件测试作业三—— 上机实验判断三角形的类型

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. 

 

1.按照要求导入junit和hamcrest.all包到java bulid path里;

2.在help -- install from site 输入http://update.eclemma.org即为安装eclemma插件;

3.创建目录如下:

4. triangle.java

 1 package cn.lxd.tju;
 2 
 3 public class triangle {
 4     private int a;
 5     private int b;
 6     private int c;
 7     public triangle(){
 8     
 9     }
10     
11     public int judge(int i , int j , int p){
12 
13         //如果是等边三角形,则返回1
14         if(i == j && j == p){
15             return 1 ;
16         }
17         //如果是等腰三角形,则返回2
18         else if(i == j || j == p || i == p){
19             return 2;
20         }
21         //如果是斜角三角形,则返回3
22         else{
23             return 3;
24         }
25     }
26 }

5. test.java

 1 package cn.lxd.tju;
 2 
 3 import static org.junit.Assert.*;
 4 import java.util.Arrays;
 5 import java.util.Collection;
 6 import org.junit.Before;
 7 import org.junit.Test;
 8 import org.junit.runner.RunWith;
 9 import org.junit.runners.Parameterized;
10 import org.junit.runners.Parameterized.Parameters;
11 
12 @RunWith(Parameterized.class)
13 public class test {
14     private triangle mytri;
15     
16     private int input1;
17     private int input2;
18     private int input3;
19     private int expected;
20     
21     public test(int a, int b, int c, int d){
22         this.input1 = a;
23         this.input2 = b;
24         this.input3 = c;
25         this.expected = d;
26     }
27     
28     @Before
29     public void setUp(){
30         mytri = new triangle();
31     }
32     
33     @Parameters
34     public static Collection<Object[]> getData(){
35         return Arrays.asList(new Object[][]{
36                 {3,4,5,3},
37                 {3,3,2,2},
38                 {9,9,9,1}
39         });
40     }
41     
42     @Test
43     public void JudgeTri(){
44         assertEquals(this.expected, mytri.judge(input1, input2, input3));
45     }
46 }

6.测试结果如下:

转载于:https://www.cnblogs.com/Elson8080/p/5291414.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值