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. go: writing stat cache:, permission denied

    sudo chown -R $(whoami):admin /Users/zhushuyan/go/pkg && sudo chmod -R g+rwx /Users/zhushuya ...

  2. OE1、OE2、ON1、ON2路由有什么区别?

    OSPF的路由类型: 1 .O    域内路由 2 .O/A  域间路由 3 .OE1  域外路由,会累加METRIC值(默认20) 4 .OE2  域外路由,不累加METRIC值(默认20),由外部 ...

  3. CreateWindowEx failed (当前程序已使用了 Window 管理器对象的系统允许的所有句柄。)

    我在QT图形场景视图中通过QGraphicsProxyWidget添加代理Widget(实现添加基本的QT Widget,如按钮.复选框.日期时间控件等),当数量超过3500左右的时候,QT应用程序直 ...

  4. CSS设置浏览器滚动条样式

    /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ ::-webkit-scrollbar { width: 5px; height: 110px; background-color: #F5 ...

  5. POJ 3414 pots (未解决)

    http://poj.org/problem?id=3414 #include <iostream> #include <cstdio> #include <queue& ...

  6. 创建dblink

    创建dblinkcreate database link user1_Link_app--dblink名称----connect to ehl_app ----远程数据库名称----identifie ...

  7. 关于 Java 中关于 数组的声明

    第一种方式:直接声明(只能在定义处使用!) int[] arr = {2, 3, 4, 5} 第二种方式:显式声明(用于各种情况) 比如方法返回值: public static int[] getAr ...

  8. asp.net session锁导致ajax请求阻塞

    问:为了可以顺序访问Session的状态值,Session是否提供了锁定机制?答:Session实现了Reader/Writer的锁机制:当页面对Session具有可写功能(即页面有<%@Pag ...

  9. ubuntu安装sublime-text

    按照网上的教程, wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - sudo apt ...

  10. javascript的数组之from()

    Array.from()方法从一个类似数组或可迭代对象中创建一个新的数组实例. const arr = [1, 2, 3]; Array.from(arr); //[1, 2, 3] Array.fr ...