zoukankan      html  css  js  c++  java
  • 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));
        }
        
    }
  • 相关阅读:
    08--Docker安装Mysql
    第三天
    html---Keymaker-EMBRACE
    解析selenium http://blog.csdn.net/java2000_net/article/details/3721706
    selenium
    day4复习
    函数
    列表
    int整数和bool值
    字符串方法整理
  • 原文地址:https://www.cnblogs.com/eric7/p/5296513.html
Copyright © 2011-2022 走看看