Skip to content

Instantly share code, notes, and snippets.

@takaiwa
Last active January 3, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaiwa/8396586 to your computer and use it in GitHub Desktop.
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
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());
}
}
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