软件测试学习(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类:
测试类:
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)); } }
相关文章推荐
- java中静态内部类和非静态内部类的使用
- 牌型种数
- 第37讲项目3——单位转换对照表
- 网易校招笔试题 小易的升级之路
- 利用可变模板参数实现log功能
- PHP,一个form表单使用多个按钮的实现方式
- tomcat启动指定jdk方法
- .net 插件式开发学习总结
- 练习——旋转链表问题
- R读取数据和导出数据
- 数据结构与算法-第12章二叉树和其他树-004求二叉树的最多结点数及对应的层数
- vs感受,由于我的电脑装了俩年了!我直接写感受吧
- 【字符串回顾】
- 网易校招笔试题 炮台攻击
- Contiki源码阅读之节点Rime地址
- Delphi编程实现是否开启“平滑屏幕字体边缘“
- HDU 2084
- 第一行代码_回顾Activity的生命周期
- NYOJ27水池数目,类似于FZU1008最大黑区域,简单搜索题~~~
- iOS显示3D模型,iOS和U3D混编(互相跳转)