Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

End of episode 132

  • Loading branch information...
commit 3322fc89ce0cb1f0c9ec03daf332f06de412f3a2 1 parent 68815de
James Shore authored
4 src/com/jamesshore/finances/domain/ValidDollars.java
View
@@ -58,6 +58,10 @@ public Dollars min(Dollars value2) {
return create(Math.min(this.amount, amount(value2)));
}
+ public ValidDollars flipSign(ValidDollars dollars) {
+ return dollars;
+ }
+
private boolean isNegative() {
return amount < 0;
}
34 src/com/jamesshore/finances/domain/_ValidDollarsTest.java
View
@@ -9,15 +9,12 @@
public class _ValidDollarsTest {
- private Dollars twentyDollars;
+ private Dollars zeroDollars = ValidDollars.create(0);
+ private Dollars twentyDollars = ValidDollars.create(20);
+ private Dollars minusTwentyDollars = ValidDollars.create(-20);
private Dollars MAX_VALID = ValidDollars.create(ValidDollars.MAX_VALUE);
private Dollars MIN_VALID = ValidDollars.create(ValidDollars.MIN_VALUE);
- @Before
- public void setup() {
- twentyDollars = ValidDollars.create(20);
- }
-
@Test
public void cannotConstructDollarsOutsideValidRange() {
assertEquals("overflow", new InvalidDollars(), ValidDollars.create(ValidDollars.MAX_VALUE + 1));
@@ -39,31 +36,36 @@ public void addition() {
@Test
public void subtraction() {
- assertEquals("positive result", ValidDollars.create(20), ValidDollars.create(50).minus(ValidDollars.create(30)));
+ assertEquals("positive result", twentyDollars, ValidDollars.create(50).minus(ValidDollars.create(30)));
assertEquals("negative result", ValidDollars.create(-60), ValidDollars.create(40).minus(ValidDollars.create(100)));
assertEquals("overflow", new InvalidDollars(), MAX_VALID.minus(ValidDollars.create(-1)));
assertEquals("underflow", new InvalidDollars(), MIN_VALID.minus(ValidDollars.create(1)));
}
@Test
- public void minusToZero() {
- assertEquals("positive result", ValidDollars.create(20), ValidDollars.create(50).subtractToZero(ValidDollars.create(30)));
+ public void subtractToZero() {
+ assertEquals("positive result", twentyDollars, ValidDollars.create(50).subtractToZero(ValidDollars.create(30)));
assertEquals("no negative result--return zero instead", ValidDollars.create(0), ValidDollars.create(40).subtractToZero(ValidDollars.create(100)));
assertEquals("overflow", new InvalidDollars(), MAX_VALID.subtractToZero(ValidDollars.create(-1)));
}
@Test
+ public void flipSign() {
+ assertEquals("zero to zero", zeroDollars, zeroDollars.flipSign());
+ }
+
+ @Test
public void percentage() {
- assertEquals("percent", ValidDollars.create(20), ValidDollars.create(100).percentage(20));
+ assertEquals("percent", twentyDollars, ValidDollars.create(100).percentage(20));
assertEquals("overflow", new InvalidDollars(), MAX_VALID.percentage(200));
}
@Test
public void min() {
- Dollars value1 = ValidDollars.create(20);
+ Dollars value1 = twentyDollars;
Dollars value2 = ValidDollars.create(30);
- assertEquals("value 1", ValidDollars.create(20), Dollars.min(value1, value2));
- assertEquals("value 2", ValidDollars.create(20), Dollars.min(value2, value1));
+ assertEquals("value 1", twentyDollars, Dollars.min(value1, value2));
+ assertEquals("value 2", twentyDollars, Dollars.min(value2, value1));
}
@Test
@@ -76,16 +78,14 @@ public void rendersItself() {
@Test
public void rendersNegativeValuesInRed() {
__RenderTargetStub target = new __RenderTargetStub();
- Dollars minusTwenty = ValidDollars.create(-20);
- minusTwenty.render(new Resources(), target);
+ minusTwentyDollars.render(new Resources(), target);
assertEquals("red when negative", Color.RED, target.foregroundColor);
}
@Test
public void rendersZeroAndPositiveInBlack() {
__RenderTargetStub target = new __RenderTargetStub();
- Dollars zero = ValidDollars.create(0);
- zero.render(new Resources(), target);
+ zeroDollars.render(new Resources(), target);
assertEquals("black when zero", Color.BLACK, target.foregroundColor);
target = new __RenderTargetStub();
2  src/com/jamesshore/finances/ui/StockMarketTableModel.java
View
@@ -55,7 +55,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
case 2:
return currentYear.startingCostBasis();
case 3:
- return currentYear.totalSellOrders();
+ return ValidDollars.create(0).minus(currentYear.totalSellOrders());
case 4:
return ValidDollars.create(0).minus(currentYear.capitalGainsTaxIncurred());
case 5:
2  src/com/jamesshore/finances/ui/_StockMarketTableModelTest.java
View
@@ -54,7 +54,7 @@ public void oneRow() {
assertEquals("year", STARTING_YEAR, model.getValueAt(0, 0));
assertEquals("starting balance", STARTING_BALANCE, model.getValueAt(0, 1));
assertEquals("starting principal", STARTING_COST_BASIS, model.getValueAt(0, 2));
- assertEquals("sell orders", YEARLY_SPENDING, model.getValueAt(0, 3));
+ assertEquals("sell orders", ValidDollars.create(0).minus(YEARLY_SPENDING), model.getValueAt(0, 3));
assertEquals("taxes", ValidDollars.create(-12), model.getValueAt(0, 4));
assertEquals("appreciation", ValidDollars.create(995), model.getValueAt(0, 5));
assertEquals("ending balance", ValidDollars.create(10947), model.getValueAt(0, 6));
Please sign in to comment.
Something went wrong with that request. Please try again.