Lab 1:write A Java program for the Triangle problem and test, with Junit.

Source: Internet
Author: User

Tasks:

1. Install Junit (4.12), Hamcrest (1.3) with Eclipse

Add two jar packages to the project

2. Install Eclemma with Eclipse

3. Write a Java program for the Triangle problem and test, 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.

Run as follows:

The code is as follows:

 PackageTesttriangle; Public classTriangles { Public StaticString Triangleshape (intAintBintc) {                if(A = = b && a = = c && b = =c) {            return"Equilateral"; }        Else if(A = = b | | a = = c | | b = =c) {            return"Isosceles"; }        Else{            return"Scalene"; }                        }    }
 PackageTesttriangle;Import Staticorg.junit.assert.*;Importjava.util.Arrays;Importjava.util.Collection;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.junit.runners.Parameterized;Importorg.junit.runners.Parameterized.Parameters; the @RunWith (parameterized.class) Public classTesttriangles {Private intA; Private intb; Private intC; PrivateString expected; PrivateString result =NULL;  PublicTesttriangles (intAintBintC, String expected) {         This. A =A;  This. B =b;  This. C =C;  This. expected=expected; } @Parameters Public StaticCollection<object[]>GetData () {returnArrays.aslist (Newobject[][]{{1,1,1, "equilateral"},    {2,3,4, "Scalene"},    {3,5,5, "Isosceles"},    {6,6,8, "Isosceles"}    }); } @Test Public voidTest () {assertequals ( This. Expected,triangles.triangleshape (a,b,c)); }    }

Lab 1:write A Java program for the Triangle problem and test, with Junit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.