TJUSCSST第一次上机实验

一、上机时间及地点

2016年3月18日10:25到12:00,上机55A210

二、上机实验内容

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

2、Install Eclemma with Eclipse

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

三、实验过程

1、导入Junit和Hamcrest的JAR包

新建Java Project

右键Project并Build Path

2、为Eclipse安装Eclemma

在help菜单中点击eclipse marketplace 并查找eclemma安装

3、编写算法

 1 package moody;
 2 public class Calculator {
 3     private static int result = 0;
 4     public void triangle(int a,int b,int c)
 5     {
 6         if((a+b)>c && (a+c)>b && (b+c)>a && a>0 && b>0 && c>0)//判断是否构成三角形
 7         {
 8             if((a==b)||(a==c)||(b==c))
 9             {
10                 if((a == b)&&(a == c))
11                 {
12                     result = 3;//等边
13                 }
14                 else
15                 {
16                     result = 2;//等腰
17                 }
18                 
19             }
20             else
21             {
22                 result = 1;//普通
23             }
24         }
25         
26         else
27         {
28             result = 0;//不是三角形
29         }
30         
31     }
32     public int getReuslt(){
33         return result;
34     }
35     
36         public void clear(){
37         result = 0;
38     }
39 }

4、编写测试程序

 1 package moody;
 2 import static org.junit.Assert.*;
 3 import org.junit.Test;
 4 public class TestCalculator {
 5     private static Calculator cal = new Calculator();
 6     @Test
 7     public void testTriangle(){
 8         
 9     cal.triangle(2, 2, 2);
10     assertEquals(3, cal.getReuslt());//等边三角形
11     cal.triangle(3, 3, 5);
12     assertEquals(2, cal.getReuslt());//等腰三角形
13     cal.triangle(2, 3, 4);
14     assertEquals(1, cal.getReuslt());//普通三角形
15     cal.triangle(1, 2, 3);
16     assertEquals(0, cal.getReuslt());//不能构成三角形
17     cal.triangle(-1, 5, 3);
18     assertEquals(0, cal.getReuslt());//不能构成三角形
19     }
20 
21 }

5、进行测试

转载于:https://www.cnblogs.com/moody/p/5293006.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值