博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LB1_3014218162
阅读量:5357 次
发布时间:2019-06-15

本文共 2011 字,大约阅读时间需要 6 分钟。

实验名称

Junit and Eclemma

实验目标

Install Junit and write a Java program with it.

实验内容

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.

实验步骤

1.下载安装Junit、hamcrest and eclemma

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

code:

1 package lab1; 2  3 public class Triangle {     4     public static String triangleshape(int a,int b, int c){         5         if(a == b && a == c && b == c){ 6             return "equilateral"; 7         } 8         else if(a == b || a == c || b == c){ 9             return "isosceles";10         }11         else{12             return "scalene";13         }      14     }    15 }
1 package lab1; 2  3 import static org.junit.Assert.*; 4 import java.util.Arrays; 5 import java.util.Collection; 6 import org.junit.Test; 7 import org.junit.runner.RunWith; 8 import org.junit.runners.Parameterized; 9 import org.junit.runners.Parameterized.Parameters;10 11 @RunWith(Parameterized.class)12 public class Testing {13 14     private int a;15     private int b;16     private int c;17     private String expected;18     private String result = null;19     20     public Testing(int a,int b, int c, String expected){21         this.a = a;22         this.b = b;23         this.c = c;24         this.expected= expected;       25     }26     27     @Parameters28     public static Collection
getData(){29 return Arrays.asList(new Object[][]{30 {1,1,1,"equilateral"},31 {2,3,4,"scalene"},32 {3,5,5,"isosceles"},33 {6,6,8,"isosceles"}34 });35 }36 37 @Test38 public void test() {39 assertEquals(this.expected,Triangle.triangleshape(a,b,c));40 }41

3、run

 

转载于:https://www.cnblogs.com/xiaolinhe/p/6590744.html

你可能感兴趣的文章
如何辨别一个程序员的水平高低?是靠发量吗?
查看>>
linux的子进程调用exec( )系列函数
查看>>
MySQLdb & pymsql
查看>>
zju 2744 回文字符 hdu 1544
查看>>
【luogu P2298 Mzc和男家丁的游戏】 题解
查看>>
前端笔记-bom
查看>>
上海淮海中路上苹果旗舰店门口欲砸一台IMAC电脑维权
查看>>
Google透露Android Market恶意程序扫描服务
查看>>
给mysql数据库字段值拼接前缀或后缀。 concat()函数
查看>>
迷宫问题
查看>>
【FZSZ2017暑假提高组Day9】猜数游戏(number)
查看>>
泛型子类_属性类型_重写方法类型
查看>>
对闭包的理解
查看>>
练习10-1 使用递归函数计算1到n之和(10 分
查看>>
Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞2
查看>>
Code Snippet
查看>>
zoj 1232 Adventure of Super Mario
查看>>
组合数学 UVa 11538 Chess Queen
查看>>
oracle job
查看>>
Redis常用命令
查看>>