zoukankan      html  css  js  c++  java
  • 软件测试第一次上机

    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的内容:

    判断三角形的形状的代码如下:

    public String type(Triangle tri){
            if(isTriangle(tri)){
                
                if(isIsosceles(tri)){
                    return "isoscele";
                }
                if(isScalene(tri)){
                    return "equilateral";
                }
                return "scalene";
            }
            return "not a triangle";
        }

    TriangleTest的内容如下:

    package cn.tjuscs.st;
    
    import org.junit.Before;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    
    import java.util.Arrays;
    import java.util.Collection;
    
    import static org.junit.Assert.assertEquals;
    
    
    @RunWith(Parameterized.class)
    public class TriangleTest {
        
        private Triangle tri;
        private int input1;
        private int input2;
        private int input3;
        private String expected;
        
        public TriangleTest(int input1, int input2, int input3, String expected){
            this.input1 = input1;
            this.input2 = input2;
            this.input3 = input3;
            this.expected = expected;
        }
        
        @Before
        public void setUp(){
            tri = new Triangle(input1, input2, input3);
        }
        
        @Parameterized.Parameters
        public static Collection<Object[]> getData(){
            return Arrays.asList(new Object[][]{
                    {2,2,2,"equilateral"},
                    {2,4,3,"scalene"},
                    {2,3,3,"isoscele"},
                    {2,9,2,"not a triangle"}
            });
        }
        
        @Test
        public void testTriangle() throws Exception{
            assertEquals(this.expected, tri.type(tri));
        }
        
    }

    覆盖率97.6%

     //原来的程序打不开了。。所以截图等我弄好了再放上来。。

  • 相关阅读:
    八个方便C#开发的省时的国外工具
    从babel-polyfill的一个坑而起
    Universal Link
    微信机器人
    微信手记
    Elasticsearch手记
    小游戏引擎手记
    【数学基础】3D数学基础-左右手坐标系
    【linux基础】linux误改sudoers权限之后的恢复及配置sudoers
    【c/c++基础】struct/typedef struct的用法详解总结
  • 原文地址:https://www.cnblogs.com/czyhhxx/p/5296785.html
Copyright © 2011-2022 走看看