Design predicates

Design predicates are a method invented by Thomas McCabe,[1] to quantify the complexity of the integration of two units of software. Each of the four types of design predicates have an associated integration complexity rating. For pieces of code that apply more than one design predicate, integration complexity ratings can be combined.

The sum of the integration complexity for a unit of code, plus one, is the maximum number of test cases necessary to exercise the integration fully. Though a test engineer can typically reduce this by covering as many previously uncovered design predicates as possible with each new test. Also, some combinations of design predicates might be logically impossible.

Types of calls

Unconditional call

Unit A always calls unit B. This has an integration complexity of 0. For example:

unitA::functionA() {
   unitB->functionB();
}

Conditional call

Unit A may or may not call unit B. This integration has a complexity of 1, and needs two tests: one that calls B, and one that doesn't.

unitA::functionA() {
   if (condition) 
      unitB->functionB();
}

Mutually exclusive conditional call

This is like a programming language's switch statement. Unit A calls exactly one of several possible units. Integration complexity is n − 1, where n is the number of possible units to call.

unitA::functionA() {
   switch (condition) {
      case 1:
         unitB->functionB();
         break;
      case 2:
         unitC->functionC();
         break;
      ...
      default:
         unitN->functionN();
         break;
   }
}

Iterative call

In an iterative call, unit A calls unit B at least once, but maybe more. This integration has a complexity of 1. It also requires two tests: one that calls unit B once, and one test that calls it more than once.

unitA::functionA() {
   do {
      unitB->functionB();
   } while (condition);
}

Combining calls

Any particular integration can combine several types of calls. For example, unit A may or may not call unit B; and if it does, it can call it one or more times. This integration combines a conditional call, with its integration complexity of 1, and an iterative call, with its integration complexity of 1. The combined integration complexity totals 2.

unitA::functionA() {
   if (someNumber > 0) {
      for (i = 0; i < someNumber; i++) {
         unitB->functionB();
      }
   }
}

Number of tests

Since the number of necessary tests is the total integration complexity plus one, this integration would require 3 tests. In one, where someNumber isn't greater than 0, unit B isn't called. In another, where someNumber is 1, unit B is called once. And in the final, someNumber is greater than 1, unit B is called more than once.

See also

References

  1. ^ McCabe, Thomas J.; Butler, Charles W. (12 Dec 1989). "Design complexity measurement and testing". Communications of the ACM. 32 (12): 1415–1425. doi:10.1145/76380.76382. S2CID 14112936.

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.