Question

In: Computer Science

* Word file clearly describe the test suite (series of test cases) you design for each...

* Word file clearly describe the test suite (series of test cases) you design for each of the methods in TestWithJUnit.java (one test suite per method). Each test suite should contain at least 5 test cases. Each test case has to be justified: Why did you pick this test case and not another one? Imagine you are limited by time and money about the number of test cases you can pick and run. Why would you make run the test cases you propose? You have to be convincing. In particular, you have to address: WHAT each test case aims to test, and HOW you expect the method to run on this test case (what output do you expect?).

*In a new java file, that you will call TestWithJUnitTester.java, write a JUnit test for each of the test cases you have described in your word file.

* Run your test cases and report the results in your word document. In particular, you have to report whether the method behaves as expected or not on each test case, and propose an explanation in case the method does not behave as expected.

Note: your test cases cannot include the examples given within the code.

Advice: when designing test cases, think:

1/ regular functionality test: does the code perform as expected under normal/expected circumstances?

2/ edge case: does the code still perform when under stress of its expected conditions?

You need to have at least one of the first type (maybe two depending on how complex the code is), and 3 or 4 of the second type.

public class TestWithJUnit {

   /* Method withoutTen:
   * Return a version of the given array where all
   * the 10's have been removed.
   * The remaining elements should shift left
   * towards the start of the array as needed,
   * and the empty spaces a the end of the array
   * should be 0.
   * So {1, 10, 10, 2} yields {1, 2, 0, 0}.
   * {1, 10, 10, 2, 10, 3, 10} yields {1, 2, 3, 0, 0, 0, 0}.
   */
   public int[] withoutTen(int[] A) {
       int[] result = new int[A.length];
       int index = 0;
      
       for (int i = 0; i < A.length; i++) {
           if (A[i] != 10) {
               result[index] = A[i];
               index++;
           }
       }
       for (int i = index; i < result.length; i++)
           result[i] = 0;
      
       return result;
   }
  
   /* Method bigArray:
   * Given an integer n, bigArray creates and returns a 1D array
   * that contains {1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, ... n}
   * For instance, bigArray(4) = {1, 1, 2, 1, 2, 3, 1, 2, 3, 4}
   * bigArray(2) = {1, 1, 2}
   */
   public int[] bigArray(int n) {
       int[] result = new int[n*(n+1)/2];
       int index = 0;
      
       for (int i = 1; i <= n; i++) {
           for (int j = 1; j <= i; j++) {
               result[index] = j;
               index++;
           }
       }
      
       return result;
   }
      
}

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// TestWithJUnitTester.java

import static org.junit.Assert.*;

import org.junit.Before;

import org.junit.Test;

public class TestWithJUnitTester {

      // TestWithJUnit object

      TestWithJUnit test;

      @Before

      public void setup() {

            // initializing object of TestWithJUnit class

            test = new TestWithJUnit();

      }

      // suite testing withoutTen() method

      @Test

      public void testWithoutTen() {

            // test case 1 - normal case - an array containing some elements as 10,

            // and some elements as other than 10.

            int case1[] = { 1, 2, 10, 3, 4, 10, 10 }; // input array

            int expected1[] = { 1, 2, 3, 4, 0, 0, 0 }; // expected output array

            assertArrayEquals(test.withoutTen(case1), expected1);

            // test case 2 - edge case 1 - an array containing 10s only

            int case2[] = { 10, 10, 10, 10, 10 };

            int expected2[] = { 0, 0, 0, 0, 0 };

            assertArrayEquals(test.withoutTen(case2), expected2);

            // test case 3 - edge case 2 - an array containing no 10s

            int case3[] = { 1, 2, 3, 4, 5 };

            int expected3[] = { 1, 2, 3, 4, 5 };

            assertArrayEquals(test.withoutTen(case3), expected3);

            // test case 4 - edge case 3 - empty array

            int case4[] = {};

            int expected4[] = {};

            assertArrayEquals(test.withoutTen(case4), expected4);

            // test case 5 - edge case 4 - an array containing only one 10

            int case5[] = { 10 };

            int expected5[] = { 0 };

            assertArrayEquals(test.withoutTen(case5), expected5);

      }

      // suite testing bigArray() method

      @Test

      public void testBigArray() {

            // test case 1 - normal case - passing a positive integer value

            int case1 = 3;

            int expected1[] = { 1, 1, 2, 1, 2, 3 };

            assertArrayEquals(test.bigArray(case1), expected1);

            // test case 2 - edge case 1 - passing 0 as value for n

            int case2 = 0;

            int expected2[] = {};

            assertArrayEquals(test.bigArray(case2), expected2);

            // test case 3 - edge case 2 - passing 1 as value for n

            int case3 = 1;

            int expected3[] = { 1 };

            assertArrayEquals(test.bigArray(case3), expected3);

            // test case 4 - edge case 3 - passing negative value

            int case4 = -5;

            int expected4[] = {};

            // this test will fail since bigArray() method is not accounted for

            // negative input values. I'm just including this for fair and square

            // testing, if you need this. just uncomment below line

            // assertArrayEquals(test.bigArray(case4), expected4);

      }

}

/*OUTPUT of testing*/



Related Solutions

Create a Word file containing the following: The full name of the “test subject” The test...
Create a Word file containing the following: The full name of the “test subject” The test subject is a person, not yourself, who can say the names of the products. The best test subject is one who is adamant about being an expert who can distinguish brand A from B. You cannot be the test subject because you generate the sequence, and the test subject cannot see it for an unbiased test. Pets and babies are not allowed as they...
Design the Use Case Diagram and the test cases for Online Mobile Store Use Cases Phase...
Design the Use Case Diagram and the test cases for Online Mobile Store Use Cases Phase II
description 
 Example: Online Computer Store Requirement 1 – Laptops Requirement 2 - Desktops Requirement 3 - Mainframes Use Cases Testing phase 2 Requirement 1 - Laptops - Test case Requirement 2 - Desktops Requirement 3 - Mainframes
Clearly Explain on each step how are you going to design the sales force for Audi...
Clearly Explain on each step how are you going to design the sales force for Audi A3, if you need to recruit a new sales team for Audi A3. (Assuming that you are the one who has a responsibility on this) (300 words or more). (Note: The following 5 steps of the sales force we are using are 1. Sales force objective 2. Sales force strategy 3. Sales force structure 4. Sales force size and 5. Compensation)
Clearly Explain on each step how are you going to design the sales force for Audi...
Clearly Explain on each step how are you going to design the sales force for Audi A3 if you need to recruit a new sales team for Audi A3. (Assuming that you are the ones who has a responsibility on this). (300 words or more). (Note: the following 5 steps of the sales force we are using are 1. Sales force objective 2. Sales force strategy 3. Sales force structure 4. Sales force size and 5. Compensation)
For the test of significance questions, clearly indicate each of the formal steps in the test...
For the test of significance questions, clearly indicate each of the formal steps in the test of significance. Step 1: State the null and alternative hypothesis. Step 2: Calculate the test statistic. Step 3: Find the p-value. Step 4: State your conclusion. (Do not just say “Reject H0” or “Do not reject H0”, state the conclusion in the context of the problem.) Beetles in oats. In a study of leaf beetle damage on oats, researchers measured the number of beetle...
For the test of significance questions, clearly indicate each of the formal steps in the test...
For the test of significance questions, clearly indicate each of the formal steps in the test of significance. Step 1: State the null and alternative hypothesis. Step 2: Calculate the test statistic. Step 3: Find the p-value. Step 4: State your conclusion. (Do not just say “Reject H0” or “Do not reject H0”, state the conclusion in the context of the problem.) Does using premium gas increase your miles per gallon? A study was conducted with nine vehicles that can...
      Design an algorithm for each of the exercises and type it into a word document....
      Design an algorithm for each of the exercises and type it into a word document. Upload the document to PE1 assignment folder. The roots of quadratic equation: Design an algorithm to find the real roots of a quadratic equation of the form ax2+bx+c=0, where a, b, c are all real numbers and a is nonzero
Following is a series of independent cases. In each situation, indicate the cash distribution to be...
Following is a series of independent cases. In each situation, indicate the cash distribution to be made to partners at the end of the liquidation process. Unless otherwise stated, assume that all solvent partners will reimburse the partnership for their deficit capital balances. Part A The Buarque, Monte, and Vinicius partnership reports the following accounts. Vinicius is personally insolvent and can contribute only an additional $23,000 to the partnership. Cash $ 144,000 Liabilities 49,000 Monte, loan 48,000 Buarque, capital (50%...
Please Do it Clearly with each step and FAST Use music wire to make a series...
Please Do it Clearly with each step and FAST Use music wire to make a series of springs with wire diameters [0.075”, 0.080”, 0.085”, 0.090”]. Each spring should have a free length of 3” and rate of 50 lbf/ft and exactly 20 total coils. The ends are squared and ground and the load factor of safety should be 1.1. For each wire size, list the figure of merit and the spring index, C. All else being equal, which wire diameter...
Explain what you understand by the word configuration design?
Explain what you understand by the word configuration design?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT