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

Comp 401 Assertions Practical Example and The Importance of Being Earnest

Feb 24, 2016

Download

Documents

nat

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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