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.