Last active
January 3, 2016 02:39
-
-
Save takaiwa/8396586 to your computer and use it in GitHub Desktop.
「Let's Play TDD #1: How Does This Thing Work, Again?」の写経
http://www.takaiwa.net/2014/01/lets-play-tdd-1-how-does-this-thing.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jamesshore.screencast; | |
import static org.junit.Assert.*; | |
import org.junit.*; | |
/** | |
* <p> | |
* Let's Play TDD #1: How Does This Thing Work, Again? | |
* https://www.youtube.com/watch?v=f3G7gu1IHws | |
* </p> | |
* Current Source code: | |
* https://www.youtube.com/watch?v=f3G7gu1IHws&t=495 | |
* | |
* @author takaiwa.net | |
*/ | |
public class _SavingsAccountTest { | |
@Test | |
public void depositAndWithdrawal() { | |
SavingAccount account = new SavingAccount(); | |
account.deposit(100); | |
assertEquals("after deposit", 100, account.balance()); | |
account.withdraw(50); | |
assertEquals("after withdrawal", 50, account.balance()); | |
} | |
@Test | |
public void negativeBalanceIsJustFine() { | |
SavingAccount account = new SavingAccount(); | |
account.withdraw(75); | |
assertEquals(-75, account.balance()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jamesshore.screencast; | |
/** | |
* <p> | |
* Let's Play TDD #1: How Does This Thing Work, Again? | |
* https://www.youtube.com/watch?v=f3G7gu1IHws | |
* </p> | |
* Current Source code: | |
* https://www.youtube.com/watch?v=f3G7gu1IHws&t=504 | |
* | |
* @author takaiwa.net | |
*/ | |
public class SavingAccount { | |
private int balance = 0; | |
public void deposit(int amount) { | |
balance += amount; | |
} | |
public int balance() { | |
return balance; | |
} | |
public void withdraw(int amount) { | |
balance -= amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment