Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JUnit testing: Part 1 : Draw a Control Flow Graph for the printPrimes() method defined inside the provided PrintPrimes.java file below . Label the nodes

JUnit testing:

Part 1: Draw a Control Flow Graph for the printPrimes() method defined inside the provided PrintPrimes.java file below. Label the nodes and edges appropriately you should be able to easily match them to the source code state or decision they represent.

Part 2: For the printPrimes() function, find a test case such that the corresponding test path visits the edge that connects the beginning of the WHILE statement to the IF statement that appears after the WHILE loop, without going through the body of the WHILE loop.

Part 3: Write a (set of) test path(s) that achieve Edge Coverage but not Prime Path Coverage on the graph. For each of them, identify the input(s) that will allow its execution. Suggestions: (1) Start by identifying the Test Requirements for both criteria (2) Multiple simple test paths will make your job easier when you have to identify the corresponding input, rather than one single complex path.

Part 4: Convert the test cases described in Part 2 and Part 3 into JUnit test cases.

---------------------------

Deliverable:

Parts 1 3: Texts containing your answers to each part Part 4: A single JUnit file that implements the tests you defined in the previous parts. (Copy and paste here)

---------------------------

PrintPrimes.java

/** ***************************************************** * Finds and prints n prime integers ********************************************************* */ public class PrintPrimes { //Empty Constructor public PrintPrimes(){} private boolean isDivisible (int i, int j) { if (j%i == 0) return true; else return false; } public int[] printPrimes (int n, boolean showAll) { int curPrime; // Value currently considered for primeness int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime? int [] primes = new int [100]; // The list of prime number candidates. // Initialize 2 into the list of primes. primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; // next number to consider ... isPrime = true; for (int i = 0; i <= numPrimes - 1; i++) { // for each previous prime. if (isDivisible (primes[i], curPrime)) { // Found a divisor, curPrime is not prime. isPrime = false; break; // out of loop through primes. } } if (isPrime) { // save it! primes[numPrimes] = curPrime; numPrimes++; } } // End while // Add prime(s) to final output array (flag dependent). int[] listOfPrimes = new int[numPrimes]; if(showAll){ int count = 0; for (int thisPrime: primes) { if(thisPrime != 0) { // Add primes to final array up to index "numPrimes - 1" listOfPrimes[count++] = thisPrime; } else { break; } } } else { listOfPrimes = new int[1]; listOfPrimes[0] = primes[numPrimes - 1]; } return listOfPrimes; } // end printPrimes }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

1. Describe the types of power that effective leaders employ

Answered: 1 week ago