comp 401 assertions practical example and the importance of being earnest

11
COMP 401 ASSERTIONS PRACTICAL EXAMPLE AND THE IMPORTANCE OF BEING EARNEST Instructor: Prasun Dewan

Upload: nat

Post on 24-Feb-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Comp 401 Assertions Practical Example and The Importance of Being Earnest. Instructor: Prasun Dewan. Prerequisite. Assertions (Preconditions and Postconditions ). Bank Account with Withdraw. public class ABankAccount implements BankAccount { int currentBalance = 0; - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

Comp 401Assertions Practical Example and The Importance of Being EarnestInstructor: Prasun Dewan

#PrerequisiteAssertions (Preconditions and Postconditions)

#Bank Account with Withdrawpublic class ABankAccount implements BankAccount {int currentBalance = 0;public static final int MIN_BALANCE = 100;public ABankAccount (int initialBalance) {currentBalance = initialBalance;}public int getCurrentBalance () {return currentBalance;}public void deposit (int amount) {currentBalance += amount;}public boolean withdraw (int amount) {int minNecessaryBalance = MIN_BALANCE + amount; if (minNecessaryBalance 0: "amount < 0"; boolean retVal = withdraw(amount); assert currentBalance >= MIN_BALANCE: "currentBalance < MIN_BALANCE"); return retVal;}

#9Using Safe Withdraw with MaxInt: The Importance of Being Earnest

#10Integer Overflow in Real LifeGoogle for integer overflow security

#11