Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are two files ( Triangle.java and TriangleTest.java ). The Triangle code is based on an example in the OpenDSA book. You should add more

There are two files (Triangle.javaandTriangleTest.java). The Triangle code is based on an example in the OpenDSA book. You should add more comments to the code and try to write test cases that will execute all lines in your Triangle.java file. The lines of code will show colored in pink if they are not executed by your test cases. Try to cover all lines. Do the following:

  1. Add comments to the code so that you gain full points for Style/Coding.
  2. Write more test cases to exercise all lines of code in theclassifyTriangle()method. You have been given a few test cases already. Add new test cases that callclassifyTriangle()with values ofs1,s2, ands3so that they meet each different condition in the series of if statements in the only method you are testing,classifyTriangle().
  3. As you add more test cases, you will recharge your submission energy.

Triangle.java public class Triangle { /** * Calculates the type of triangle returning: * 0 = not a triangle * 1 = equilateral * 2 = isoceles * 3 = scalene */ public static int classifyTriangle(int s1, int s2, int s3) { // coverage if (s1 < 0 || s2 < 0 || s3 < 0) { return 0; } else if (s1 == 0) { return 0; } else if (s2 == 0) { return 0; } else if (s3 == 0) { return 0; } else if (s1 - s2 == s3) { return 0; } else if (s2 - s1 == s3) { return 0; } else if (s3 - s2 == s1) { return 0; } else if (s1 - s2 > s3) { return 0; } else if (s2 - s1 > s3) { return 0; } else if (s3 - s2 > s1) { return 0; } else if (s1 == s2 && s1 == s3 && s2 == s3) { return 1; } else if (s1 != s2 && s1 != s3 && s2 != s3) { return 3; } else { return 2; } } }

TriangleTest.java

import static org.junit.Assert.*; import org.junit.Test; public class TriangleTest { @Test public void testNotATriangle() { int r = Triangle.classifyTriangle(3, 4, 55); assertEquals("This should not be a triangle", 0, r); } @Test public void testScalene() { int r = Triangle.classifyTriangle(3, 4, 5); assertEquals("This should be an scalene triangle", 3, r); } @Test public void testIsoceles() { int r = Triangle.classifyTriangle(10, 10, 6); assertEquals("This should be an isoceles triangle", 2, r); } @Test public void testEquilateral() { int r = Triangle.classifyTriangle(10, 10, 10); assertEquals("This should be an equilateral triangle", 1, r); r = Triangle.classifyTriangle(-1, -2, -3); assertEquals("Problems with negative values", 0, r); } @Test public void testAllZeroes() { int r = Triangle.classifyTriangle(0, 0, 0); assertEquals("calling it with all 0s", 0, r); r = Triangle.classifyTriangle(0, 1, 2); assertEquals("calling it with s1 = 0", 0, r); r = Triangle.classifyTriangle(1, 0, 2); assertEquals("calling it with s2 = 0", 0, r); r = Triangle.classifyTriangle(1, 3, 0); assertEquals("calling it with s3 = 0", 0, r); } @Test public void test3DiffSides() { int s1 = 15;

int s2 = 34; int s3 = 32; int r = Triangle.classifyTriangle(s1, s2, s3); assertEquals("Scalene with three different sides", 3, r); } // Add more tests to increase coverage, shown by pink // line highlight in the source code view in Web-CAT }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres the updated TriangleTestjava file with additional test cases to cover all lines in the classifyTriangle method import static orgjunitAssert impo... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing A Business Risk Approach

Authors: Karla Johnstone, Audrey Gramling, Larry Rittenberg

8th edition

538476230, 978-0538476232

More Books

Students also viewed these Programming questions

Question

What is the decision rule for IRR?

Answered: 1 week ago

Question

What are the advantages and disadvantages of Agile PM?

Answered: 1 week ago