Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions.

Similar presentations


Presentation on theme: "Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions."— Presentation transcript:

1 Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions

2 Preconditions Conditions under which a method may be called and expected to produce correct results Tip: –use to check arguments passed to method to guarantee that they do have valid values Examples – (y!=0), (link==null), (x>=y)

3 Postconditions State of the program once the routine has been completed Postconditions should be correct only if Preconditions were met Tip: –Test if computed values fall within acceptable ranges Examples – (x!=0), (link!=null), (x<=y)

4 How to Implement Pre- and Post-Conditions: Assertions Assumption made about the state of the program Assert.pre(boolean test, String message) Assert.post(boolean test, String message) Assert.condition(boolean test, String message) Assert.fail(String message)

5 Example

6 Assignment #2 Problems: Due:


Download ppt "Chapter 2 Comments, Conditions, Assertions Comments Preconditions Postconditions Assertions."

Similar presentations


Ads by Google