Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab3;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertTrue;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertThrows;
- public class Triangle {
- private int a, b, c;
- public Triangle() {
- this.a = 0;
- this.b = 0;
- this.c = 0;
- }
- public Triangle(int a,int b,int c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- public int getA() {
- return this.a;
- }
- public int getB() {
- return this.b;
- }
- public int getC() {
- return this.c;
- }
- void setA(int a) {
- this.a = a;
- }
- void setB(int b) {
- this.b = b;
- }
- void setC(int c) {
- this.c = c;
- }
- public boolean isIsoscelesButNotEqulateralTriangle(){
- return ((a==b)&&!(a==c))||((b==c)&&!(a==b))||((a==c)&&(a==b));
- }
- }
- class TriangleTest {
- /*
- This test set achieves CACC on the predicate in the isIsoscelesButNotEqulateralTriangle()
- method inside the Triangle class.
- Comments show the test number and the values of a,b and c variables. Test numbers are from
- the logic coverage tool on the book webiste, one can determine that there are various ways to
- achieve CACC with exactly 3 tests. The tests in this JUnit implemet one of these possibilities,
- namely tests 4, 6 and 7, hence they are named Test4, Test6, and Test7.
- However, it should be noted that other possible test set options genetarated via CACC criteria may be infeasible.
- */
- public Triangle triangle;
- @BeforeEach
- public void init(){
- triangle = new Triangle();
- // System.out.println("NOV TEST");
- }
- /*
- Test 4: T F F
- s1==s2 is True; s1==s3 is False; s2==s3 is False;
- */
- @Test
- public void Test4() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 4");
- System.out.println("**********");
- triangle.setA(5);
- triangle.setB(5);
- triangle.setC(7);
- System.out.println(triangle.getA());
- System.out.println(triangle.getB());
- System.out.println(triangle.getC());
- System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
- assertTrue(triangle.isIsoscelesButNotEqulateralTriangle());
- }
- /*
- Test 6: F T F
- s1==s2 is False; s1==s3 is True; s2==s3 is False;
- */
- @Test
- public void Test6() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 6");
- System.out.println("**********");
- triangle.setA(10);
- triangle.setB(14);
- triangle.setC(10);
- System.out.println(triangle.getA());
- System.out.println(triangle.getB());
- System.out.println(triangle.getC());
- System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
- assertFalse(triangle.isIsoscelesButNotEqulateralTriangle());
- }
- /*
- Test 7: F F T
- s1==s2 is False; s1==s3 is False; s2==s3 is True;
- */
- @Test
- public void Test7() throws Throwable {
- System.out.println("**********");
- System.out.println("TEST 7");
- System.out.println("**********");
- triangle.setA(6);
- triangle.setB(9);
- triangle.setC(9);
- System.out.println(triangle.getA());
- System.out.println(triangle.getB());
- System.out.println(triangle.getC());
- System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
- assertTrue(triangle.isIsoscelesButNotEqulateralTriangle());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement