Write a code to judge the type of triangle and test it.
To judge the Triangle code:
PackageTest 1; Public classSJX { PublicString F (intAintBintc) {if(a<=0| | b<=0| | c<=0| | a+b<=c| | a+c<=b| | B+C<=A)return"Not a triangle."; if(A = = B&&b = = c)returnEquilateral triangle; Else if(A = = b| | b = = c)returnIsosceles Triangle; Else return"General Triangle"; }}
Test code:
PackageTest 1;Importorg.junit.*; Public classSjxtest {SJX s; @Before Public voidSetUp () {s=NewSJX (); } @Test Public voidTests () {assert.assertequals ("Cannot judge whether it is a triangle", "not a triangle", S.F (1,1,2)); Assert.assertequals ("Cannot judge whether it is equilateral triangle", "equilateral triangle", S.F (1,1,1)); Assert.assertequals ("Cannot judge whether it is isosceles triangle", "isosceles triangle", S.F (2,2,3)); Assert.assertequals ("Cannot judge whether it is a general triangle", "General Triangle", S.F (3,4,6)); }}
Operation Result:
Software Test job three attempts to use JUnit