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. Netty WebSocket 开发

    代码: Server package netty.protocol.websocket.server; import io.netty.bootstrap.ServerBootstrap; impor ...

  2. git报错You are not allowed to force push code to a protected branch on this project

    当我们有时候回滚了代码,想强制push到远程仓库的时候, git push origin --force 会报如下错误: You are not allowed to force push code ...

  3. 11.12git部分和redis

    2018-11-12 09:54:58 这星期把luffycity看完,然后周末回学校 越努力,越幸运!永远不要高估自己! 具体可以参考  戳我啊!! 一些git常用命令: 目前已使用Git的四个命令 ...

  4. layui实现左侧菜单点击右侧内容区显示

    https://segmentfault.com/a/1190000014617129

  5. 关于JAVA项目中的常用的异常处理

    一.简介(摘自百度百科) 异常处理,是编程语言或计算机硬件里的一种机制,用于处理软件或信息系统中出现的异常状况(即超出程序正常执行流程的某些特殊条件). 异常有以下的一些特点: (1)偶然性.程序运行 ...

  6. 13.vue组件

    vue组件(一) 组件嵌套: 1.全局嵌套: <!doctype html> <html> <head> <meta charset="utf-8& ...

  7. 12.vue属性.监听.组件

    1.计算属性 https://cn.vuejs.org/v2/guide/computed.html new Vue({ computed:{//定义 show(){ } } }) ++计算属性1.h ...

  8. c++ __declspec

    dllimport 和dllexport 用__declspec(dllexport),__declspec(dllimport)显式的定义dll接口给调用它的exe或dll文件,用 dllexpor ...

  9. NFC中国-中国第一NFC论坛,NFC中文论坛+NFC技术社区+NFC_电子发烧友网【申明:来源于网络】

    NFC中国-中国第一NFC论坛,NFC中文论坛+NFC技术社区[申明:来源于网络] NFC中国-中国第一NFC论坛,NFC中文论坛:http://nfcchina.org/forum.php NFC技 ...

  10. pytorch--nn.Sequential学习

    nn.SequentialA sequential container. Modules will be added to it in the order they are passed in the ...