Software test on-machine experiment

Source: Internet
Author: User

Requirements: Write a program to determine the 3 integers of the edge around the shape is a triangle, and determine the equilateral triangle, isosceles triangle, not equilateral triangle. The Java code is written as follows:

public class Triangle {

Public String f (int A, int b, int c) {
if (a==0| | b==0| | c==0| | a+b<=c| | a+c<=b| | B+c<=a) return "is not a triangle";
else if (a==b&&a==c) return "equilateral triangle";
else if (a==b| | a==c| | B==C) return "isosceles triangle";
Else
Return "not equilateral triangle";
}

}

In the JUnit auto-generated test class, the test code is written as follows

public class Triangletest {
Triangle Tri;
@Before
public void Setup () {
Tri = new triangle ();
}

@Test
public void Testequilateral () {
String rel = TRI.F (2, 2, 2);
Assert.assertequals ("The judgment of the equilateral is problematic", rel, "equilateral triangle");
}

@Test
public void Testisosceles () {
String rel = TRI.F (3, 2, 2);
Assert.assertequals ("isosceles judgment has a problem", rel, "isosceles triangle");
}

@Test
public void Testscalene () {
String rel = TRI.F (3, 4, 5);
Assert.assertequals ("No equilateral triangle judgment problem", rel, "not equilateral triangle");
}

@Test
public void Testtri () {
String rel = TRI.F (3, 4, 8);
Assert.assertequals ("Whether there is a problem with the triangle", rel, "not a triangle");
}
}

Running the test class with the plug-in Eclemma, you can see that the test was successful and all the test cases passed:

For the problem of installing junit and Eclemma, it is simple to introduce the necessary junit packages to build path on the line, Hamcrest-all-1.3.jar,junit-4.12.jar. Installing plug-in Eclemma is even easier, with the ability to download and install directly from Eclipse.

Software test on-machine experiment

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.