ArticleslgStudy

computer science

Design predicates

Design predicates is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Design predicates rather than just read about it. In short: Design predicates are a method invented by Thomas McCabe, 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.

Key takeaways

  • Design predicates belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Design predicates to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Design predicates from memory before moving on to harder problems.

Reference excerpt

Design predicates are a method invented by Thomas McCabe, 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 Cyclomatic complexity Integration testing White-box testing

References

Worked examples

Example 1 — a first encounter with Design predicates

Start with the simplest possible case. Write down what Design predicates claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Design predicates before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Design predicates ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Design predicates

In research
Design predicates appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Design predicates in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Design predicates is common in secondary-school and first-year university syllabi. It links to neighbouring topics Software metrics, Software testing, so understanding it makes those chapters shorter.
In everyday life
Look for Design predicates outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Design predicates” →

How to study Design predicates in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Design predicates means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Design predicates out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Design predicates in simple terms?

Design predicates are a method invented by Thomas McCabe, 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.

Why does Design predicates matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Design predicates?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Design predicates.

Tags

  • Software metrics
  • Software testing

Keep exploring