Album Cover

Test-Driven Development Java

Close Preview
So how did we TDD task 1? Click on the tabs below to find out...
Here is the first in a series of videos showing how we applied TDD to the problem at hand. The video is about 13 minutes long.

public class Account {
	private final int numberOfLines;
	private final double monthlyRate;
	private final double additionalLineRate;
public Account(int numberOfLines, double monthlyRate, double additionalLineRate) { this.numberOfLines = numberOfLines; this.monthlyRate = monthlyRate; this.additionalLineRate = additionalLineRate; }
public double computeBill() { return monthlyRate + (numberOfLines - 1) * additionalLineRate; } }

public class AccountTest {
	private static final double GOLD_ADDITIONAL_LINE_RATE = 14.50;
	private static final double GOLD_MONTHLY_RATE = 49.95;
	private static final int ONE_LINE = 1;
	private static final int TWO_LINES = 2;
	private static final int THREE_LINES = 3;
	private static final double SILVER_MONTHLY_RATE = 29.95;
	private static final double SILVER_ADDITIONAL_LINE_RATE = 21.50;
@Test public void goldAccounts() { assertEquals(49.95, goldAccountWith(ONE_LINE).computeBill()); assertEquals(64.45, goldAccountWith(TWO_LINES).computeBill()); }
@Test public void silverAccounts() { assertEquals(29.95, silverAccountWith(ONE_LINE).computeBill()); assertEquals(72.95, silverAccountWith(THREE_LINES).computeBill()); }
private Account silverAccountWith(int numberOfLines) { return new Account(numberOfLines, SILVER_MONTHLY_RATE, SILVER_ADDITIONAL_LINE_RATE); }
private Account goldAccountWith(int numberOfLines) { return new Account(numberOfLines, GOLD_MONTHLY_RATE, GOLD_ADDITIONAL_LINE_RATE); } }
Click on the link below to download the source code for this task.
(Reading...)
| Tweet...
Page rating: | Rate this Page