码迷,mamicode.com
首页 > 编程语言 > 详细

Lab 1: Write a java program for the triangle problem and test the program with Junit.

时间:2016-03-19 23:06:04      阅读:695      评论:0      收藏:0      [点我收藏+]

标签:

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.

标签:

原文地址:http://www.cnblogs.com/eric7/p/5296513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!