SWE 637 In Class Exercise Number 10


This is an exercise for logic testing of source code. This is exercise 12 from Section 8.3. (Page 223). The general instructions are to derive RACC tests for two different versions of the isSatisfactory() method.

There is a solution given for part (a). The key to part (b) is reachability analysis. Consider the last predicate in the refactored version first. Reachability constraints will force "don't care" values to have specific values.

Both the original and refactored versions are shown below.

// GoodFastCheap: Investigating logic testing with an old engineering joke

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() {          // exercise 12a
       if ((good && fast) || (good && cheap) || (fast && cheap)) {
          return true;
       }
       return false;
    }

    public boolean isSatisfactoryRefactored() {   // exercise 12b
       if (good && fast)  return true;
       if (good && cheap) return true;
       if (fast && cheap) return true;
       return false;
    }
}