Assignment 2 - White Box Testing

Due - Sunday, February 23, 2025

This is a group project of 2 or 3 students per group. The groups can be found in the document Assignment2_Groups.docx.

Introduction

White box testing, also known as clear box testing, glass box testing, or structural testing, is a software testing technique that focuses on the internal structures or workings of a software application. The primary goal of white box testing is to ensure that all the internal components, paths, and conditions are correctly implemented and work as expected. This assignment contains exercises in white box testing.

Calculating Standard Deviation

  1. Given below is a simple C program to accept a set of inputs and calculate standard deviation. It has consciously been seeded with defects. If you were asked to perform white box testing on this program, identify some of the defects in the program. Also, list the methodology you used to identify these defects.
            //StandardDev.cpp - Code for calculating the standard deviation
            //
            // 02-Jan-24  M. Watler         Created.
            
            #include 
            void main(argc, argv)
            {
                int no_numbers; /* The number of numbers for which std dev is to be calculated */
                float mean, stdev; / *temporary variables * /
                int i, total; /* temporary variables */
                int numbers[100]; /* the actual numbers */
                do {
                    printf("Please enter the number of numbers \n");
                    scanf("%d", &no_numbers);
                    if (no_numbers < 2) printf("Invalid number of numbers, try again...\n");
                } while (no_numbers < 2);
                /* First accept the numbers and calculate their sum as we go along */
                for (i = 0; i < no_numbers; i++)
                (
                    scanf("%d", &numbers[i]);
                    total += numbers[i];
                }
                mean = total / no_numbers;
                /* now start calculating standard deviation */
                total = 0;
                for (i = 0; i < no_numbers; i++)
                {
                    total += ((mean - numbers[i]) * (mean - numbers[i]))
                }
                stdev = total / no_numbers;
                printf("The standard deviation is %d\n", stdev);
                return (0);
            }
            
    The code can also be seen at StandardDev.cpp.
  2. For the above program, draw the flow graph and hence calculate the cyclomatic complexity of the program.

Deleting Elements from a Doubly Linked List

  1. Given below is a C program for deleting an element from a linked list. Suggest a set of test data to cover each and every statement of this program.
          /* definition of the list is assumed to be given by the following structure:
          struct llist {
              int value;
              llist * next;
              llist * prev;
          }
          The caller is supposed to pass a pointer to the
          start of the llist and the value to be deleted; There
          is assumed to be at most one value to be deleted */
          
          void delete_list (llist * list, int value_to_be_deleted)
          {
              llist* temp;
              for (temp = list; temp != NULL, temp = temp->next)
              {
                  if (temp->value == value_to_be_deleted)
                      if (temp->prev ! = NULL)
                          temp->prev->next = temp->next;
                      if (temp->next ! = NULL)
                          temp->next->prev = temp->prev;
                  return (0);
              }
              return (1); /* value to be deleted is not found at the end of search */
          }  
          
    The code can also be seen at DoublyLinkedList.cpp.
  2. In the example of the previous problem, even when the set of test data provides 100% statement coverage, show that there are still uncovered defects.

Date Validation

  1. Given below are parts of the code segment actually written by two students for date validation. The two students used two different approaches as given in the code segments a and b. Which of these two would you think is easier from a white box testing perspective? Which of the techniques of white box testing discussed in this chapter would be most relevant to apply for a and which for b? How would you improve the effectiveness of the code in terms of susceptibility to defects in either case and ability to detect defects more easily?

    Date Validation - Part a
    int month_days [13]= {0, 31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31 };
    valid = TRUE;
    if (is_leap-year(yy))
        month_days [2] = 29;
    if (mm < 1 !! mm > 12) valid = FALSE;
    else
        if (day < 1 !! day> month_days[mm])
            valid = FALSE;
        else if (year < 1)
            valid = FALSE;
    return (valid);
    /* In the above, the function is_leap-year is defined as follows */
    int is_leap-year (int year)
    {
        int result;
        if ((year%4) != 0 ) result = FALSE;
        else if (( year %400) == 0) result = TRUE;
        else if ((year %100) == 0) result = FALSE;
        return (result);
    } 
    
    Date Validation - Part b
    //return 0 - success, return -1 - failure
    if (!(dd > 0 && dd < 32)) {
        printf ("enter a number between 1 and 32 only\n");
        return (-1);
    }
    if ((mm=4) !! (mm==6) !! (mm==9) !! (mm==11)) & day> 30)
    {
        printf ("invalid date; maximum days should be 30");
        return (-1);
    }
    if (((year%100==0) || (year%4==0)||(year%400==0)) && (day==29))||(day < 29))
    {
        printf ("valid date \n");
        return (0);
    }
    else
    {
        printf("invalid date\n");
        return (-1);
    }  
    
    The code can also be seen at DateValidation.cpp.
  2. In part b, the test data presented in Table P1 was used to test the leap year part of the validation. Calculate the various coverage factors for this test data for the leap year part of the code.
    Values for testing segment B

Questions

  1. Coverage Criteria: Describe the main coverage criteria used in white box testing, such as statement coverage, branch coverage, path coverage, and condition coverage. Explain the significance of each criterion and how they ensure thorough testing of the internal structure of a software application.
  2. Advantages and Limitations: Compare and contrast the advantages and limitations of white box testing with other software testing techniques, such as black box testing. Provide specific examples to illustrate your points and discuss scenarios where white box testing would be most beneficial.
  3. Techniques and Tools: Discuss the various techniques and tools available for conducting white box testing. Explain how these techniques, such as static analysis, dynamic analysis, and code reviews, contribute to identifying defects, vulnerabilities, and areas for optimization in the software code.
  4. Integration with Development Lifecycle: Evaluate the role of white box testing within the software development lifecycle (SDLC). Describe how white box testing can be integrated into different phases of the SDLC, such as requirements analysis, design, implementation, testing, and maintenance. Provide recommendations for best practices to ensure effective collaboration between developers and testers throughout the development lifecycle.

Marking Rubric

You will be marked out of 10 according to the following:

Does not meet expectationsSatisfactoryGoodExceeds Expectations
Calculating Standard Deviation
(3 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors
Deleting Elements of a Doubly Linked List
(2 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors
Date Validation
(3 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors
Questions
(2 marks)
Does not meet requirementsMeets the most important requirementsMeets all requirements with minor errorsMeets all requirements with no errors

Submission

Please email all source code and answers to questions to: miguel.watler@senecapolytechnic.ca

Your answers to questions can be submitted in a separate document or embedded within your source code.

Late Policy

You will be docked 10% if your assignment is submitted 1-2 days late.
You will be docked 20% if your assignment is submitted 3-4 days late.
You will be docked 30% if your assignment is submitted 5-6 days late.
You will be docked 40% if your assignment is submitted 7 days late.
You will be docked 50% if your assignment is submitted over 7 days late.