Download presentation
Presentation is loading. Please wait.
Published byJoella Manning Modified over 9 years ago
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:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.