zoukankan      html  css  js  c++  java
  • 软件测试学习(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));
        }
        
    }
  • 相关阅读:
    access denied for user 'root'@'localhost'(using password:YES) FOR WINDOWS
    PKU 1001解题代码
    PKU 1002解题总结
    为什么vue组件data必须是函数
    call 和 apply 区别
    CSS|Stacking context 堆叠上下文
    Vue3.0 tsx 函数组件
    js中的变量提升
    JavaEE|架构
    MVC,MVP 和 MVVM
  • 原文地址:https://www.cnblogs.com/tjuwx/p/5295676.html
Copyright © 2011-2022 走看看