軟體測試第一次上機

來源:互聯網
上載者:User

標籤:

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%

 

軟體測試第一次上機

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.