Testing

Here is your testing assignment. Follow these steps to fulfill the goals of the assignment.

  1. Read the handout on Testing Programs.
  2. Extract the source dode from this message, and compile it.
  3. Run the program a few times to get a feel for what it does, and how it does it. You will need to read the code to do this.
  4. Prepare a set of files to be used as input to the program that will test its behavior according to the principles in the handout. Try to test any extremes of the program, if any; its behavior with special cases; its behavior with unexpected input and its behvaior in typical cases. Print the results of each test along with the input that produced the test. Your aim is really to show the program failings, not just its good points.
  5. Analyze the test output and draw conclusions as to whether the program works correctly or not. Notice that correctness is really determined by the intended behavior, not necessarily the actual behavior. The description in the source code gives the intended behavior. Write your conclusions in a brief report (just a few sentences).
  6. Hand in your test with their results, and the report, by 5pm on Friday 28th. March.

(Note that this source code will be sent by e-mail)

/***********************************************************
 Spring 1997 A grading program
 Roger Hartley
 This program reads a list of grades, and prints the number 
 of grades in each of the standard grading ranges: 90% and
 above is A, 80-89% is B, 70-79% is C, 60-69% is D, and below 
 60% is F
 ***********************************************************/

#include <stdio.h>


float ReadGrade() {
  float grade;
  int n;

  printf("Type a grade: ");
  n = scanf("%f", &grade);
  if (n == EOF)  /* scanf read end of file */
    return -1;
  else
    return grade;
}

void ProcessGrade(float g, int ga[]) {
  int gradeIndex;
  
  if (g >= 90.0)
    gradeIndex = 0;
  else if (g >= 80.0)
    gradeIndex = 1;
  else if (g >= 70.0)
    gradeIndex = 2;
  else if (g >= 60.0)
    gradeIndex = 3;
  else
    gradeIndex = 4;
  
  ++ga[gradeIndex];
}

void printGrades(int ga[]) {
  int gradeIndex;
  char gradeLetter;

  printf("The number of each grade input is:\n\n");
  for (gradeIndex = 0; gradeIndex < 5; gradeIndex++) {
    if (gradeIndex < 4)
      gradeLetter = 'A' + gradeIndex;
    else
      gradeLetter = 'F';
    printf("%c %d\n", gradeLetter, ga[gradeIndex]);
  }
}

int main() {
  float grade = 1;
  int gradeArray[5] = {0};

  while (grade > 0) {
      grade = ReadGrade();
      ProcessGrade(grade, gradeArray);
  }

  printGrades(gradeArray);
}