Advertisement
dzocesrce

[SKIT] Triangle Testing

May 15th, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.75 KB | None | 0 0
  1. package Lab3;
  2.  
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5.  
  6. import static org.junit.Assert.assertFalse;
  7. import static org.junit.Assert.assertTrue;
  8. import static org.junit.jupiter.api.Assertions.assertEquals;
  9. import static org.junit.jupiter.api.Assertions.assertThrows;
  10.  
  11. public class Triangle {
  12.     private int a, b, c;
  13.  
  14.     public Triangle() {
  15.         this.a = 0;
  16.         this.b = 0;
  17.         this.c = 0;
  18.     }
  19.     public Triangle(int a,int b,int c) {
  20.         this.a = a;
  21.         this.b = b;
  22.         this.c = c;
  23.     }
  24.  
  25.     public int getA() {
  26.         return this.a;
  27.     }
  28.     public int getB() {
  29.         return this.b;
  30.     }
  31.     public int getC() {
  32.         return this.c;
  33.     }
  34.     void setA(int a) {
  35.         this.a = a;
  36.     }
  37.     void setB(int b) {
  38.         this.b = b;
  39.     }
  40.     void setC(int c) {
  41.         this.c = c;
  42.     }
  43.     public boolean isIsoscelesButNotEqulateralTriangle(){
  44.         return ((a==b)&&!(a==c))||((b==c)&&!(a==b))||((a==c)&&(a==b));
  45.     }
  46.  
  47. }
  48.  
  49. class TriangleTest {
  50.  
  51.     /*
  52.     This test set achieves CACC on the predicate in the isIsoscelesButNotEqulateralTriangle()
  53.     method inside the Triangle class.
  54.  
  55.     Comments show the test number and the values of a,b and c variables. Test numbers are from
  56.     the logic coverage tool on the book webiste, one can determine that there are various ways to
  57.     achieve CACC with exactly 3 tests. The tests in this JUnit implemet one of these possibilities,
  58.     namely tests 4, 6 and 7, hence they are named Test4, Test6, and Test7.
  59.  
  60.     However, it should be noted that other possible test set options genetarated via CACC criteria may be infeasible.
  61.      */
  62.     public Triangle triangle;
  63.  
  64.     @BeforeEach
  65.     public void init(){
  66.     triangle = new Triangle();
  67. //        System.out.println("NOV TEST");
  68.     }
  69.  
  70.     /*
  71.     Test 4: T F F
  72.     s1==s2 is True; s1==s3 is False; s2==s3 is False;
  73.      */
  74.  
  75.     @Test
  76.     public void Test4() throws Throwable {
  77.  
  78.         System.out.println("**********");
  79.         System.out.println("TEST 4");
  80.         System.out.println("**********");
  81.  
  82.         triangle.setA(5);
  83.         triangle.setB(5);
  84.         triangle.setC(7);
  85.  
  86.         System.out.println(triangle.getA());
  87.         System.out.println(triangle.getB());
  88.         System.out.println(triangle.getC());
  89.         System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
  90.         assertTrue(triangle.isIsoscelesButNotEqulateralTriangle());
  91.     }
  92.  
  93.     /*
  94.     Test 6: F T F
  95.     s1==s2 is False; s1==s3 is True; s2==s3 is False;
  96.      */
  97.  
  98.     @Test
  99.     public void Test6() throws Throwable {
  100.  
  101.         System.out.println("**********");
  102.         System.out.println("TEST 6");
  103.         System.out.println("**********");
  104.  
  105.         triangle.setA(10);
  106.         triangle.setB(14);
  107.         triangle.setC(10);
  108.  
  109.         System.out.println(triangle.getA());
  110.         System.out.println(triangle.getB());
  111.         System.out.println(triangle.getC());
  112.         System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
  113.         assertFalse(triangle.isIsoscelesButNotEqulateralTriangle());
  114.     }
  115.  
  116.     /*
  117.     Test 7: F F T
  118.     s1==s2 is False; s1==s3 is False; s2==s3 is True;
  119.      */
  120.  
  121.     @Test
  122.     public void Test7() throws Throwable {
  123.  
  124.         System.out.println("**********");
  125.         System.out.println("TEST 7");
  126.         System.out.println("**********");
  127.  
  128.         triangle.setA(6);
  129.         triangle.setB(9);
  130.         triangle.setC(9);
  131.  
  132.         System.out.println(triangle.getA());
  133.         System.out.println(triangle.getB());
  134.         System.out.println(triangle.getC());
  135.         System.out.println(triangle.isIsoscelesButNotEqulateralTriangle());
  136.         assertTrue(triangle.isIsoscelesButNotEqulateralTriangle());
  137.     }
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement