All homework assignments are due before class on the due date. All homework assignments must reflect your own understanding of the topic and be communicated in your own words. You may use one of the collaborative options. You may also request help and advice from your classmates on Piazza as long as the help/advice follows the course's collaborative policy. Any help not allowed by that policy will be an honor violation.
Purpose: To encourage students to start working on the homework assignments early and recognize students who are actively engaged in the content
You will receiveNote: The final submission timestamp shown on Gradescope will be used. No extension/exception on the early submission bonus points.
Consider the following Java class. PrimeNumbers.java has three methods.
public class PrimeNumbers implements Iterable<Integer>
{
private List<Integer> primes = new ArrayList<Integer>();
public void computePrimes(int n)
{
int count = 1; // count of primes
int number = 2; // number tested for primeness
boolean isPrime; // is this number a prime
while (count <= n)
{
isPrime = true;
for (int divisor = 2; divisor <= number / 2; divisor++)
{
if (number % divisor == 0)
{
isPrime = false;
break; // for loop
}
}
if (isPrime && (number % 10 != 9)) // FAULT
{
primes.add(number);
count++;
}
number++;
}
}
@Override public Iterator<Integer> iterator()
{
return primes.iterator();
}
@Override public String toString()
{
return primes.toString();
}
}
computePrimes() has a fault that causes it not to include prime numbers whose last digit is 9 (for example, it omits 19, 29, 59, 79, 89, 109, ...).
If possible, describe the following five tests. You can describe the tests as sequences of calls to the above methods, or briefly describe them in words. Be sure to include test input values and expected outputs.
Note: For the last two tests, in addition to the test input values and the corresponding expected outputs, you are required to describe the test oracle. You may describe them in words or as JUnit assertion statements.
[Reminder: Two mandatory components of each test case: input value(s) and expected output — point(s) will always be deducted if any of these is missing]
If a test cannot be created, explain why.
Use PrimeNumbers.java from part 1.
Develop JUnit tests for the computePrimes() method.
Although we do not expect you to satisfy any specific test criterion, at minimum, your tests must reach every line of code in the method.
For each test, include comments (directly in your JUnit test file) that specify
Your JUnit tests must include the two tests you designed in part 1
Do NOT modify or refactor the given Java source file.
The only exception is the package's name.package package_name; line.Run your tests and take a screenshot showing the test results. You will later include the screenshot in your report.
If the tests fail, analyze and briefly describe/discuss what causes the failure.
Consider the computeRangeSum() method of someOps.java.
Note: There exists a fault in the subject under test. At least one of your tests must detect it.
Do NOT modify or refactor the given Java source file.
The only exception is the package's name.package package_name; line.Apply RIPR model to design tests, develop JUnit data-driven tests for the computeRangeSum() method.
Although we do not expect you to satisfy any specific test criterion, at minimum, your tests must reach every line of code in the method.
You are required to develop JUnit data-driven tests.
Run your tests and take a screenshot showing the test results. You will later include the screenshot in your report.
If the tests fail, analyze and briefly describe/discuss what causes the failure.
( -5 points) for 24 hours late (submitted after 21-September 1pm, by 22-September 1pm)
(-10 points) for 48 hours late (submitted after 22-September 1pm, by 23-September 1pm)
(-2 points) for submitting a Word document or handwriting, or a write-up that is not a typed PDF file.
Save your assignment as a PDF file. — No handwriting. No hand-drawing. No Word document.
Log in to Canvas, then upload your report as a PDF to Assignment1 on Gradescope. Make sure you connect your partner to your group on Gradescope so that everyone receives credit.
Each team submits only one copy.
Making your submission available to instructor and course staff is your responsibility; if we cannot access or open your file, you will not get credit. Be sure to test access to your file before the due date.
CC-BY-NC-SA 4.0 license.