Activity: Logic coverage for source code

(no submission)

Purpose: Practice applying logic-based testing for program source code; get ready to work on homework assignment, and prepare for quiz 4 and the final exam

You may make a copy of a worksheet and complete this activity, or type your answers in any text editor.

You may work alone or with at most two other students in this course.


Consider an implementation of the old engineering joke: Good, Fast, Cheap.

public final class GoodFastCheap 
{
   boolean good  = false;
   boolean fast  = false;
   boolean cheap = false;

   public void makeGood () 
   {
      good = true;
      if (fast && cheap)   { cheap = false; }
   }

   public void makeFast () 
   {
      fast = true; 
      if (good && cheap)   { good = false; }
   }

   public void makeCheap () 
   {
      cheap = true;
      if (fast && good)   { fast = false; }
   }

   public void makeBad ()         { good = false; }
   public void makeSlow ()        { fast = false; }
   public void makeExpensive ()   { cheap = false; }

   public boolean isSatisfactory() 
   {
      if ((good && fast) || (good && cheap) || (fast && cheap)) 
          return true;
       
      return false;
   }

   public static void main(String[] args) 
   {
      // Question:  How well do the following tests exercise the clauses?

      GoodFastCheap gfc = new GoodFastCheap();     // g f c
                           gfc.isSatisfactory();   // F F F
      gfc.makeGood();      gfc.isSatisfactory();   // T F F
      gfc.makeFast();      gfc.isSatisfactory();   // T T F
      gfc.makeCheap();     gfc.isSatisfactory();   // T F T
      gfc.makeSlow();      gfc.isSatisfactory();   // T F T
   }
}   

Focus on the predicate in isSatisfactory(). We will start with the truth table. (Note: in reality, if tools are available, use the tools. For practice purposes and to help you prepare for the exam: we will fill the truth table ourselves)

Row# g f c P Pg Pf Pc
1 T T T        
2 T T          
3 T   T        
4 T            
5   T T        
6   T          
7     T        
8              

  1. List at least one possible test pair that satisfies Predicate Coverage (PC)
  2. List at least one possible test pair that satisfies Clause Coverage (CC)
  3. List all possible test pairs that satisfy Correlated Active Clause Coverage (CACC), and then assemble the result into a CACC-adequate test set for all clauses
  4. List all possible test pairs that satisfy Restricted Active Clause Coverage (RACC), and then assemble the result into a RACC-adequate test set for all clauses
  5. At least 4 tests are needed for a RACC-adequate test. Why?
  6. What are the possible assertions for the JUnit tests (for the RACC-adequate test)?
  7. Does the given sequence in the main() method achieve RACC?
  8. What happens if we refactor the predicate in isSatisfactory()
    public boolean isSatisfactory() 
    {
       if (good && fast)   return true;
       if (good && cheap)  return true;
       if (fast && cheap)  return true;
           
       return false;
    }  


Copyright © 2025 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2025-10-25 16:34