Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose This assignment is aimed at helping you understand how the white box testing method known as control flow testing works. You are required to

Purpose

This assignment is aimed at helping you understand how the white box testing method known as control flow testing works.

You are required to complete the tasks described below.

Test software

The following program has been implemented for a newly proposed tax calculation formula for residents of a fictitious country.

// incomeList[]: the array recording the individual income items

// childList[]: the array recording the ages of children supported by this person

// parentList[]: the array recording the ages of parents supported by this person

  1. public double computeTax(double[] incomeList, int[] parentList, int[] childList) {
  2. double taxAmount = 0.0;
  3. double incomeAmount = 0.0;

// calculate the income amount

  1. for (int i = 0; i < incomeList.length; i++) {
  2. incomeAmount = incomeAmount + incomeList[i]; 6 }

// calculate the basic tax

  1. if (incomeAmount <= 40000) {
  2. taxAmount = incomeAmount * 0.02;
  3. } else if (incomeAmount > 40000 && incomeAmount <= 80000) {
  4. taxAmount = 800 + incomeAmount * 0.07;
  5. } else if (incomeAmount > 80000 && incomeAmount <= 120000) {
  6. taxAmount = 800 + 2800 + incomeAmount * 0.12;
  7. } else if (incomeAmount > 120000) {
  8. taxAmount = 800 + 2800 + 4800 + incomeAmount * 0.17; 15 }

// calculate the tax exemption from having children

  1. int taxExemption = 0;
  2. int numOfChild = childList.length;
  3. while (numOfChild > 0) {
  4. if (childList[numOfChild - 1] < 18) {
  5. taxAmount = taxAmount - 4000;
  6. taxExemption = taxExemption + 4000; 22 }

23 numOfChild--; 24 }

// calculate the tax exemption from having parents

  1. for (int j = 0; j < parentList.length; j++) {
  2. if (parentList[j] > 60) {
  3. taxAmount = taxAmount - 2000;
  4. taxExemption = taxExemption + 2000; 29 }

30 }

// the maximum tax exemption is 8000 each person

  1. if (taxExemption <= 8000) {
  2. if (taxAmount >= 0) {
  3. return taxAmount;
  4. } else { // i.e., taxAmount <0
  5. return 0; 36 }
  1. } else { // i.e., taxExemption > 8000
  2. taxAmount = taxAmount + (taxExemption - 8000);
  3. return taxAmount; 40 }

41}

Your Tasks

(1) Draw the control flow graph for this program.

(2) Design test cases to achieve the statement coverage on the function computeTax (list the statements covered by each test case using the line number of each statement). If it is not feasible, explain the reason. Use the minimum number of test cases to achieve the statement coverage.

(3) Design test cases to achieve branch coverage on the function computeTax (list the branches covered by each test case). If it is not feasible, explain the reason. Use the minimum number of test cases to achieve the branch coverage.

(4) Design test cases to achieve loop coverage on the function computeTax (list the loops covered by each test case). If it is not feasible, explain the reason. Try your best to use the minimum number of test cases to achieve the loop coverage. Consider a loop covered if at least in one test the loop body was executed 0 times, in a second test the body was executed exactly once, and in another test the body was executed more than once.

Special Instructions

Test cases should be presented in a table with each row showing the following:

Test ID #, input data, statements/branches/loops covered by the test case, expected output and % coverage . You may add additional columns to display key variables such as tax exemption.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago