You are going to write tests for the following program. Its requirements are to Take an integer array data of SIZE elements Take...

hankan

You are going to write tests for the following program.

Its requirements are to

  • Take an integer array data of SIZE elements

  • Take a positive, non-null, integer value n

  • If the value is null or negative, the program should not alter the array

  • If it is positive, each element in the array should be shifted right by n positions

  • If an element is pushed past the end of the array, we keep pushing it as if the end of the array connected to its start. Our array is a kind of “ring”.

 

Your objective is to write tests which will guarantee

  • The program conforms to the requirements; the program below might or might not, your tests need to be able to determine this

  • All possible execution paths have been tested

  • Your program does not feature any of the novice errors discussed in the textbook / videos / …

Program to Test

 

  1. // all arrays in this program will have same size

  2. #define SIZE 3

  3.  

  4. void rotate(int data[], int n){

  5. int index = 0;

  6. int tmp[SIZE];

  7.  

  8. // copying data into tmp array

  9. for(index = 0 ; index < SIZE ; index++){

  10. tmp[index] = data[index];

  11. }

  12.  

  13. for(index = 0 ; index < SIZE ; index++){

  14. next = (index + n) % SIZE;

  15. data[next] = tmp[index];

  16. }

  17. }

    • 12 years ago
    • 5
    Answer(0)
    Bids(0)