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.

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.java:

 package cn.st.lab1;

 public class Triangle {
public static boolean isTriangle(int a, int b, int c) {
if(a+b>c && a+c>b && b+c>a && Math.abs(a-b)<c &&
Math.abs(a-c)<b && Math.abs(b-c)<a && a>0 && b>0 && c>0) {
return true;
}
else {
return false;
}
}
public static boolean isEquilateral(int a, int b, int c) {
if(isTriangle(a,b,c)) {
if(a == b && a == c) {
return true;
}
}
return false;
}
public static boolean isIsosceles(int a, int b, int c) {
if(isTriangle(a,b,c)) {
if(a == b || a == c || b == c) {
return true;
}
}
return false;
} public static void Triangle (int a, int b, int c) {
if(isTriangle(a,b,c)) { //输出以下内容,则为三角形
if(isEquilateral(a,b,c)) {
System.out.println("Equilateral");
} //如果是等边,只输出等边,不输出等腰
else if(isIsosceles(a,b,c)) {
System.out.println("Isosceles");
}
else {
System.out.println("Scalene");
}
}
else {
System.out.println("NotATriangle");
}
}

testTriangle.java:

 package cn.st.lab1;

 import static org.junit.Assert.*;

 import org.junit.*;

 public class testTriangle {

     Triangle t;
@Before
public void setUp(){
t = new Triangle();
} @Test
public void testIsEquilateral() {
assertEquals("testIsEquilateral", true, t.isEquilateral(6,6,6));
}
@Test
public void testIsIsosceles() {
assertEquals("testIsIsosceles", true, t.isIsosceles(5,6,6));
}
@Test
public void testIsTriangle() {
assertEquals("testIsTriangle", true, t.isTriangle(5,6,7));
}
@Test
public void testTriangle() {
t.Triangle(3, 4, 5);
t.Triangle(3, 4, 4);
t.Triangle(4, 4, 4);
t.Triangle(1, 1, 5);
}
}

实验结果:

代码请见github:https://github.com/fogmisty/SoftwareTest

Software Testing, Lab 1的更多相关文章

  1. Software Testing Techniques LAB 02: Selenium

    1. Installing 1. Install firefox 38.5.1 2. Install SeleniumIDE    After installing, I set the view o ...

  2. 101+ Manual and Automation Software Testing Interview Questions and Answers

    101+ Manual and Automation Software Testing Interview Questions and Answers http://www.softwaretesti ...

  3. Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...

  4. 软件测试software testing summarize

    软件测试(英语:software testing),描述一种用来促进鉴定软件的正确性.完整性.安全性和质量的过程.软件测试的经典定义是:在规定的条件下对程序进行操作,以发现程序错误,衡量软件质量,并对 ...

  5. 读书笔记-Software Testing(By Ron Patton)

    Software Testing Part I:The Big Picture 1.Software Testing Background Bug's formal definition 1.The ...

  6. software testing

    Software Testing Software testing is the process of evaluation a software item to detect differences ...

  7. 探索式软件测试—Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...

  8. FW:Software Testing

    Software Testing Testing with a Purpose Software testing is performed to verify that the completed s ...

  9. 《The art of software testing》的一个例子

    这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...

随机推荐

  1. Android 反编译apk

    工具介绍:    apktool 作用:资源文件获取,可以提取出图片文件和布局文件进行使用查看 下载地址:https://bitbucket.org/iBotPeaches/apktool/downl ...

  2. 字符集之在UTF-8中,一个汉字为什么需要三个字节?

    (一)在UTF-8中,一个汉字为什么需要三个字节? UNICODE是万能编码,包含了所有符号的编码,它规定了所有符号在计算机底层的二进制的表示顺序.有关Unicode为什么会出现就不叙述了,Unico ...

  3. jenkins 登录远程机器并执行脚本,脚本中有后台执行的程序无法执行解决方法。

    jenkins构建shell执行配置 在远程shell脚本中,需要后台执行的命令需要以$( )括起来

  4. js插件解读

    1.calendar.js:日期插件:2.html5shiv.js:用于解决IE9以下版本浏览器对HTML5新增标签不识别,并导致CSS不起作用的问题的js文件:3.jquery.js里的代码是没有进 ...

  5. Centos6.8 下 从零开始 部署 Java Web 应用

    一.硬件信息 CPU: [root@localhost ~]# grep 'physical id' /proc/cpuinfo | sort -u | wc -l 2 [root@localhost ...

  6. Centos7 Crontab

    Centos7 Crontab # 查看crontab -l # 编辑 crontab -e # 重启 service crond restart ccrontab 编写规则 # 分 时 日 月 周 ...

  7. classmethod作用

    >>> class A(object): bar = 1 def func1(self): print 'foo' >>> class A(object): bar ...

  8. IDEA-各模块间引用出现问题的解决方法

    1 点击项目右上角的Project Structure 2 选择Modules->父项目->点击右上角的加号->添加需要依赖的模块

  9. Mac Eclipse安装lombok

    Lombok是一个可以通过注解的形式可以帮助消除一些必须但是显得很臃肿的Java代码的工具,通过使用对应的注解,可以在进行编译源码的时候生成对应的方法,比如类属性的get/set/toString() ...

  10. python nose测试框架全面介绍十一---用例的发现

    nose是怎么发现用例的??网上一大把说函数以test开头的都会自动发现,真的是这样吗???还是自己来试验下吧 首先,我们还是来看看官方文档怎么说的吧: If it looks like a test ...