SWE 637 In Class Exercise Number 10


This is an exercise for logic testing of source code. This week, the in-class exercise is identical to the homework exercise.

In class, you should make sure that you understand the part of the exercise where a solutions is provided (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;
    }
}