• 软件测试学习(3) 第一次上机实验


    实验要求:

    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.

      a) 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类:

    package ST;
    
    public class Triangle {    
        public String judge(double a, double  b, double  c)
        {
            if(a+b>c&&b+c>a&&a+c>b)
            {
                if(a==b||b==c||c==a)
                {    
                    if(a==b&&b==c)
                        return "equilateral";
                    else return "isosceles";
                }
                else return "scalene";
            }
            else return "it is not a triangle";        
        }
    }

    测试类:

    package ST;
    
    import org.junit.Test;
    import org.junit.Before;
    import static org.junit.Assert .*;
    
    public class TriangleTest {
        private Triangle triangle;
        
        @Before
        public void setUp() throws Exception {
            triangle = new Triangle();
        }
        
        @Test
        public void test()
        {
            assertEquals("isosceles", triangle.judge(4,4,5));
            assertEquals("it is not a triangle", triangle.judge(1,1,5));
            assertEquals("equilateral", triangle.judge(4,4,4));
            assertEquals("scalene", triangle.judge(3,4,5));
        }
        
    }
  • 相关阅读:
    Action获取表单数据的三种方式
    Action三种编写方式
    hibernate 查询方式
    hibernate 多对多操作(级联操作)
    对拍
    树的数据生成器
    SPOJ1825 Free tour II 树分治
    Codeforces 474(#271 Div 2) 解题报告
    HNCPC2012 总结
    Sort 对下标进行排序
  • 原文地址:https://www.cnblogs.com/tjuwx/p/5295676.html
Copyright © 2020-2023  润新知