Lab 1: Write a java program for the triangle problem and test the program with Junit.
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lab 1: Write a java program for the triangle problem and test the program with Junit.相关的知识,希望对你有一定的参考价值。
Tasks:
1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
将两个jar包添加到工程中
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.
运行截图如下:
代码如下:
package TestTriangle; public class triangles { public static String triangleshape(int a,int b, int c){ if(a == b && a == c && b == c){ return "equilateral"; } else if(a == b || a == c || b == c){ return "isosceles"; } else{ return "scalene"; } } }
package TestTriangle; import static org.junit.Assert.*; import java.util.Arrays; import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class testTriangles { private int a; private int b; private int c; private String expected; private String result = null; public testTriangles(int a,int b, int c, String expected){ this.a = a; this.b = b; this.c = c; this.expected= expected; } @Parameters public static Collection<Object[]> getData(){ return Arrays.asList(new Object[][]{ {1,1,1,"equilateral"}, {2,3,4,"scalene"}, {3,5,5,"isosceles"}, {6,6,8,"isosceles"} }); } @Test public void test() { assertEquals(this.expected,triangles.triangleshape(a,b,c)); } }
以上是关于Lab 1: Write a java program for the triangle problem and test the program with Junit.的主要内容,如果未能解决你的问题,请参考以下文章
6.S081-2021-lab5 Copy-on-Write Fork
java 进度对话框。字体:https://stackoverflow.com/questions/12841803/best-way-to-show-a-loading-progress-indic