From 3cb2ec7eab5a982175914c36c93582f9832d1a19 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Wed, 19 Sep 2018 11:58:41 -0400 Subject: [PATCH 01/26] Initial Test for emptyReturnsTotalEntered() Implement emptyReturnsTotalEntered test to check if paystation.empty() method returns total amount entered. currently RED (test fails) --- test/paystation/domain/PayStationImplTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 747dec5..c9bc3f6 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -138,4 +138,15 @@ public void shouldClearAfterCancel() assertEquals("Insert after cancel should work", 10, ps.readDisplay()); } + + /** + * Call to empty returns the total amount entered. + */ + @Test + public void emptyReturnsTotalEntered() throws IllegalCoinException { + ps.addPayment(10); + assertEquals("Empty should show total amount entered", + 0, ps.empty()); + } + } From 24ebbc30bf67e44eda0d286b36ef2477ca42924b Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Wed, 19 Sep 2018 12:08:29 -0400 Subject: [PATCH 02/26] Typo fix Test should have expected value of 10 --- test/paystation/domain/PayStationImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index c9bc3f6..4e6b501 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -146,7 +146,7 @@ public void shouldClearAfterCancel() public void emptyReturnsTotalEntered() throws IllegalCoinException { ps.addPayment(10); assertEquals("Empty should show total amount entered", - 0, ps.empty()); + 10, ps.empty()); } } From 91c6dfbf253fa5c51ca017cd5bf6822978900794 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Wed, 19 Sep 2018 12:12:18 -0400 Subject: [PATCH 03/26] Add Empty() Method - Add to interface - Add to Impl - Ensure returns total inserted so far makes emptyReturnsTotalEntered() test GREEN --- src/paystation/domain/PayStation.java | 6 ++++++ src/paystation/domain/PayStationImpl.java | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/paystation/domain/PayStation.java b/src/paystation/domain/PayStation.java index bc74e4d..9d6033c 100644 --- a/src/paystation/domain/PayStation.java +++ b/src/paystation/domain/PayStation.java @@ -50,4 +50,10 @@ public interface PayStation { * Cancel the present transaction. Resets the machine for a new transaction. */ public void cancel(); + + /** + * Return the total amount of money collected since the last call and empties + * it, setting the total to zero. Note: Money only collected after call to Buy + */ + public int empty(); } diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 979f379..bd478e2 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -58,4 +58,9 @@ public void cancel() { private void reset() { timeBought = insertedSoFar = 0; } + + @Override + public int empty() { + return insertedSoFar; + } } From b676e0d2ffc07a3b7e56037fd7bcd50eb838d02d Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Wed, 19 Sep 2018 12:16:12 -0400 Subject: [PATCH 04/26] Add cancelDoesNotAddFromEmpty() Add test case to ensure cancel method does not include any coins in a cancelled transaction when it returns the total value. Test is RED --- test/paystation/domain/PayStationImplTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 4e6b501..245e34f 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -149,4 +149,18 @@ public void emptyReturnsTotalEntered() throws IllegalCoinException { 10, ps.empty()); } + /** + * Call to empty returns the total amount entered. + */ + @Test + public void cancelDoesNotAddFromEmpty() throws IllegalCoinException { + ps.addPayment(25); + assertEquals("Empty should show total amount entered", + 23, ps.empty()); + ps.addPayment(25); + ps.cancel(); + assertEquals("Empty should not include cancelled amount entered", + 25, ps.empty()); + } + } From 68bca3087f6b9bb6a5dc8359514162f8400b058b Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Wed, 19 Sep 2018 12:16:56 -0400 Subject: [PATCH 05/26] Another typo fix I'm the worst --- test/paystation/domain/PayStationImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 245e34f..e87c80d 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -156,7 +156,7 @@ public void emptyReturnsTotalEntered() throws IllegalCoinException { public void cancelDoesNotAddFromEmpty() throws IllegalCoinException { ps.addPayment(25); assertEquals("Empty should show total amount entered", - 23, ps.empty()); + 25, ps.empty()); ps.addPayment(25); ps.cancel(); assertEquals("Empty should not include cancelled amount entered", From 3d6299e41e13246db026d4d481a67ea04943f7a3 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 11:41:23 -0400 Subject: [PATCH 06/26] Remove redundant access modifiers in interfaces Access modifiers (public, private, etc.) in interfaces are redundant. --- src/paystation/domain/PayStation.java | 18 +++++++++--------- src/paystation/domain/Receipt.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/paystation/domain/PayStation.java b/src/paystation/domain/PayStation.java index 9d6033c..e26dbfd 100644 --- a/src/paystation/domain/PayStation.java +++ b/src/paystation/domain/PayStation.java @@ -3,10 +3,10 @@ * * Responsibilities: * - * 1) Accept payment; - * 2) Calculate parking time based on payment; - * 3) Know earning, parking time bought; - * 4) Issue receipts; + * 1) Accept payment; + * 2) Calculate parking time based on payment; + * 3) Know earning, parking time bought; + * 4) Issue receipts; * 5) Handle buy and cancel events. * * This source code is from the book "Flexible, Reliable Software: Using @@ -28,7 +28,7 @@ public interface PayStation { * is, a quarter is coinValue=25, etc. * @throws IllegalCoinException in case coinValue is not a valid coin value */ - public void addPayment(int coinValue) throws IllegalCoinException; + void addPayment(int coinValue) throws IllegalCoinException; /** * Read the machine's display. The display shows a numerical description of @@ -36,7 +36,7 @@ public interface PayStation { * * @return the number to display on the pay station display */ - public int readDisplay(); + int readDisplay(); /** * Buy parking time. Terminate the ongoing transaction and return a parking @@ -44,16 +44,16 @@ public interface PayStation { * * @return a valid parking receipt object. */ - public Receipt buy(); + Receipt buy(); /** * Cancel the present transaction. Resets the machine for a new transaction. */ - public void cancel(); + void cancel(); /** * Return the total amount of money collected since the last call and empties * it, setting the total to zero. Note: Money only collected after call to Buy */ - public int empty(); + int empty(); } diff --git a/src/paystation/domain/Receipt.java b/src/paystation/domain/Receipt.java index 8925d20..7ee3518 100644 --- a/src/paystation/domain/Receipt.java +++ b/src/paystation/domain/Receipt.java @@ -20,5 +20,5 @@ public interface Receipt { * * @return number of minutes parking time */ - public int value(); + int value(); } From 911fac01040b440ab067e0411a28effbea007ef6 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 11:52:46 -0400 Subject: [PATCH 07/26] Change return type of 'cancel' From void to Map. Also return the appropriate typed object in implementation so that build does not fail. --- src/paystation/domain/PayStation.java | 12 ++++++++++-- src/paystation/domain/PayStationImpl.java | 18 +++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/paystation/domain/PayStation.java b/src/paystation/domain/PayStation.java index e26dbfd..3604b50 100644 --- a/src/paystation/domain/PayStation.java +++ b/src/paystation/domain/PayStation.java @@ -19,6 +19,8 @@ */ package paystation.domain; +import java.util.Map; + public interface PayStation { /** @@ -47,9 +49,15 @@ public interface PayStation { Receipt buy(); /** - * Cancel the present transaction. Resets the machine for a new transaction. + * Cancel the present transaction. Resets the paystation for a new transaction. + * @return A Map defining the coins returned to the user. + * The key is the coin type and the associated value is the number of these coins that are + * returned. + * The Map object is never null even if no coins are returned. + * The Map will only contain only keys for coins to be returned. + * The Map will be cleared after a cancel or buy. */ - void cancel(); + Map cancel(); /** * Return the total amount of money collected since the last call and empties diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index bd478e2..627733d 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -1,14 +1,17 @@ package paystation.domain; +import java.util.HashMap; +import java.util.Map; + /** * Implementation of the pay station. * * Responsibilities: * - * 1) Accept payment; - * 2) Calculate parking time based on payment; - * 3) Know earning, parking time bought; - * 4) Issue receipts; + * 1) Accept payment; + * 2) Calculate parking time based on payment; + * 3) Know earning, parking time bought; + * 4) Issue receipts; * 5) Handle buy and cancel events. * * This source code is from the book "Flexible, Reliable Software: Using @@ -20,7 +23,7 @@ * purposes. For any commercial use, see http://www.baerbak.com/ */ public class PayStationImpl implements PayStation { - + private int insertedSoFar; private int timeBought; @@ -51,10 +54,11 @@ public Receipt buy() { } @Override - public void cancel() { + public Map cancel() { reset(); + return null; } - + private void reset() { timeBought = insertedSoFar = 0; } From 2d25719ec45fe63ed8a35ef0962815b39726aa81 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:24:05 -0400 Subject: [PATCH 08/26] Refactor to add new property insertedMap insertedMap is a HashMap recording the coin types and their respective quantities entered. --- src/paystation/domain/PayStationImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 627733d..f8abec1 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -25,8 +25,15 @@ public class PayStationImpl implements PayStation { private int insertedSoFar; + private HashMap insertedMap; /* map recording coin types and quantities */ private int timeBought; + public PayStationImpl() { + insertedSoFar = 0; + insertedMap = new HashMap<>(); + timeBought = 0; + } + @Override public void addPayment(int coinValue) throws IllegalCoinException { @@ -38,6 +45,10 @@ public void addPayment(int coinValue) throw new IllegalCoinException("Invalid coin: " + coinValue); } insertedSoFar += coinValue; + if (insertedMap.containsKey(coinValue)) + insertedMap.put(coinValue, insertedMap.get(coinValue) + 1); + else + insertedMap.put(coinValue, 1); timeBought = insertedSoFar / 5 * 2; } @@ -61,6 +72,7 @@ public Map cancel() { private void reset() { timeBought = insertedSoFar = 0; + insertedMap.clear(); } @Override From 59c9843bf4c195148f6b54c56099dcb90f9cf8d8 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:40:07 -0400 Subject: [PATCH 09/26] Modify shouldClearAfterCancel and fail test To reflect change in return type. --- src/paystation/domain/PayStationImpl.java | 4 +++- test/paystation/domain/PayStationImplTest.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index f8abec1..cdc8c4d 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -67,7 +67,9 @@ public Receipt buy() { @Override public Map cancel() { reset(); - return null; + HashMap returnedMap = new HashMap<>(); + returnedMap.put(1, 1); + return returnedMap; } private void reset() { diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index e87c80d..781a984 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -15,6 +15,8 @@ import static org.junit.Assert.*; import org.junit.Before; +import java.util.HashMap; + public class PayStationImplTest { PayStation ps; @@ -134,6 +136,8 @@ public void shouldClearAfterCancel() ps.cancel(); assertEquals("Cancel should clear display", 0, ps.readDisplay()); + HashMap emptyMap = (HashMap) ps.cancel(); + assertTrue("Cancel should clear map", emptyMap.isEmpty()); ps.addPayment(25); assertEquals("Insert after cancel should work", 10, ps.readDisplay()); From 272f5d1aef15301189ee3f6040b713fe84d41769 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:41:32 -0400 Subject: [PATCH 10/26] Pass shouldClearAfterCancel test --- src/paystation/domain/PayStationImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index cdc8c4d..8ee952a 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -66,9 +66,8 @@ public Receipt buy() { @Override public Map cancel() { + HashMap returnedMap = insertedMap; reset(); - HashMap returnedMap = new HashMap<>(); - returnedMap.put(1, 1); return returnedMap; } From 1c05add56839add8f0862a50a1aca369a46b75a7 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:53:05 -0400 Subject: [PATCH 11/26] Add cancelShouldReturnMapContainingOneCoin test --- test/paystation/domain/PayStationImplTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 781a984..94922cd 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -143,6 +143,16 @@ public void shouldClearAfterCancel() 10, ps.readDisplay()); } + @Test + public void cancelShouldReturnMapContainingOneCoin() throws IllegalCoinException { + ps.addPayment(25); + HashMap returnedMap = (HashMap) ps.cancel(); + assertEquals("Cancel should return a map containing one coin entered", + 1, returnedMap.size()); + assertEquals("Cancel should return a map containing one coin entered", + 1, (int) returnedMap.get(25)); + } + /** * Call to empty returns the total amount entered. */ From cc41ea0dc2e8a230f595030e673cecc11cfd1512 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:57:49 -0400 Subject: [PATCH 12/26] Pass cancelShouldReturnMapContainingOneCoin test In 'cancel,' supposed to make a deep copy of the insertedMap but made a shallow copy instead. This fixes that. --- src/paystation/domain/PayStationImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 8ee952a..791c0e6 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -66,7 +66,7 @@ public Receipt buy() { @Override public Map cancel() { - HashMap returnedMap = insertedMap; + HashMap returnedMap = (HashMap) insertedMap.clone(); reset(); return returnedMap; } From 5a35f2426059047d07443f7c8438529be7a8e134 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 12:59:35 -0400 Subject: [PATCH 13/26] Add documentation for cancelShouldReturnMapContainingOneCoin --- test/paystation/domain/PayStationImplTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 94922cd..dd86ad9 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -143,6 +143,9 @@ public void shouldClearAfterCancel() 10, ps.readDisplay()); } + /** + * Call to cancel should return a map containing one coin entered. + */ @Test public void cancelShouldReturnMapContainingOneCoin() throws IllegalCoinException { ps.addPayment(25); From 5e5091162def71b0cb25747b45ff7871e4c70156 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 13:05:07 -0400 Subject: [PATCH 14/26] Add and pass cancelShouldReturnMapContainingMixtureOfCoins --- .../paystation/domain/PayStationImplTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index dd86ad9..8b2fac8 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -156,6 +156,26 @@ public void cancelShouldReturnMapContainingOneCoin() throws IllegalCoinException 1, (int) returnedMap.get(25)); } + /** + * Call to cancel should return a map containing a mixture of coins entered. + */ + @Test + public void cancelShouldReturnMapContainingMixtureOfCoins() throws IllegalCoinException { + ps.addPayment(25); + ps.addPayment(5); + ps.addPayment(10); + ps.addPayment(5); + HashMap returnedMap = (HashMap) ps.cancel(); + assertEquals("Cancel should return a map containing a mixture of coins entered", + 3, returnedMap.size()); + assertEquals("Cancel should return a map containing a mixture of coins entered", + 1, (int) returnedMap.get(25)); + assertEquals("Cancel should return a map containing a mixture of coins entered", + 1, (int) returnedMap.get(10)); + assertEquals("Cancel should return a map containing a mixture of coins entered", + 2, (int) returnedMap.get(5)); + } + /** * Call to empty returns the total amount entered. */ From 8476c135802e2ef63c109f7aed97f81c07b3a7d0 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 13:14:06 -0400 Subject: [PATCH 15/26] Add and pass cancelShouldReturnMapNotContainingKeyNotEntered --- test/paystation/domain/PayStationImplTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 8b2fac8..d430611 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -176,6 +176,18 @@ public void cancelShouldReturnMapContainingMixtureOfCoins() throws IllegalCoinEx 2, (int) returnedMap.get(5)); } + /** + * Call to cancel should return a map that does not contain a key for a coin not entered. + */ + @Test + public void cancelShouldReturnMapNotContainingKeyNotEntered() throws IllegalCoinException { + assertFalse("Returned map should not create key for a coin not entered", + ps.cancel().containsKey(25)); + ps.addPayment(25); + assertFalse("Returned map should not create key for a coin not entered", + ps.cancel().containsKey(5)); + } + /** * Call to empty returns the total amount entered. */ From 584dfb0533f9556f60407eab62ba38e309b16b38 Mon Sep 17 00:00:00 2001 From: Binh Nguyen Date: Sat, 22 Sep 2018 13:23:48 -0400 Subject: [PATCH 16/26] Refactor shouldClearAfterCancel Into two separate tests: shouldClearAfterCancel and shouldClearMapAfterCancel, to match requirements. --- test/paystation/domain/PayStationImplTest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index d430611..cf86fb8 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -130,19 +130,27 @@ public void shouldClearAfterBuy() * Verify that cancel clears the pay station */ @Test - public void shouldClearAfterCancel() - throws IllegalCoinException { + public void shouldClearAfterCancel() throws IllegalCoinException { ps.addPayment(10); ps.cancel(); assertEquals("Cancel should clear display", 0, ps.readDisplay()); - HashMap emptyMap = (HashMap) ps.cancel(); - assertTrue("Cancel should clear map", emptyMap.isEmpty()); ps.addPayment(25); assertEquals("Insert after cancel should work", 10, ps.readDisplay()); } + /** + * Call to cancel should clear the map. + */ + @Test + public void shouldClearMapAfterCancel() throws IllegalCoinException { + ps.addPayment(10); + ps.cancel(); + HashMap emptyMap = (HashMap) ps.cancel(); + assertTrue("Cancel should clear map", emptyMap.isEmpty()); + } + /** * Call to cancel should return a map containing one coin entered. */ From 163d25283b610288bef498c74164c93378a98279 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:08:51 -0400 Subject: [PATCH 17/26] Rewrite Empty() Tests Empty is dependent on buy(). Without a call to buy(), the coin amounts are not collected. These rewrite addresses that requirement. Tests are now RED. --- test/paystation/domain/PayStationImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index cf86fb8..85cb777 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -202,6 +202,7 @@ public void cancelShouldReturnMapNotContainingKeyNotEntered() throws IllegalCoin @Test public void emptyReturnsTotalEntered() throws IllegalCoinException { ps.addPayment(10); + ps.buy(); assertEquals("Empty should show total amount entered", 10, ps.empty()); } @@ -212,8 +213,7 @@ public void emptyReturnsTotalEntered() throws IllegalCoinException { @Test public void cancelDoesNotAddFromEmpty() throws IllegalCoinException { ps.addPayment(25); - assertEquals("Empty should show total amount entered", - 25, ps.empty()); + ps.buy(); ps.addPayment(25); ps.cancel(); assertEquals("Empty should not include cancelled amount entered", From 936fbba1528270767f96ff8c89b36f0e370427c2 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:13:18 -0400 Subject: [PATCH 18/26] Edit Empty() in Impl to pass tests Add totalCollected which only accrues value after a call to buy() as per requirements. Reset totalCollected after call to empty(). Both tests written for empty() are now GREEN. --- src/paystation/domain/PayStationImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 791c0e6..14ad111 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -27,11 +27,13 @@ public class PayStationImpl implements PayStation { private int insertedSoFar; private HashMap insertedMap; /* map recording coin types and quantities */ private int timeBought; + private int totalCollected; /* Stores the total amount (in cents) collected by paystation */ public PayStationImpl() { insertedSoFar = 0; insertedMap = new HashMap<>(); timeBought = 0; + totalCollected = 0; } @Override @@ -60,6 +62,7 @@ public int readDisplay() { @Override public Receipt buy() { Receipt r = new ReceiptImpl(timeBought); + totalCollected += insertedSoFar; /* Each buy action accrues more total money collected */ reset(); return r; } @@ -77,7 +80,10 @@ private void reset() { } @Override + /* Returns total money collected in the paystation since the last call to empty, and resets total */ public int empty() { - return insertedSoFar; + int retval = totalCollected; + totalCollected = 0; + return retval; } } From 2e57cc939dd867aff63fc0dd9a5ef3fbc4888cd7 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:19:39 -0400 Subject: [PATCH 19/26] Add final test for empty() Add emptyResetsTotalCollected() test. Temporarily comment out totalCollected set to 0 in empty() in Impl to demonstrate test in fail state. Test is currently RED. --- src/paystation/domain/PayStationImpl.java | 2 +- test/paystation/domain/PayStationImplTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 14ad111..36e22c4 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -83,7 +83,7 @@ private void reset() { /* Returns total money collected in the paystation since the last call to empty, and resets total */ public int empty() { int retval = totalCollected; - totalCollected = 0; + //totalCollected = 0; return retval; } } diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 85cb777..096e26e 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -220,4 +220,20 @@ public void cancelDoesNotAddFromEmpty() throws IllegalCoinException { 25, ps.empty()); } + /** + * Call to empty resets totalCollected to 0 + */ + @Test + public void emptyResetsTotalCollected() throws IllegalCoinException { + ps.addPayment(25); + ps.buy(); + ps.addPayment(25); + ps.buy(); + assertEquals("Empty should return total collected.", + 50, ps.empty()); + assertEquals("Previous empty should have reset total to zero.", + 0, ps.empty()); + } + + } From 124cfb2cb084fbe6f214b70460dacf62f1c63b6c Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:20:25 -0400 Subject: [PATCH 20/26] Make totalCollected reset after empty() Uncomment relevant line to fix test. Test is now GREEN. --- src/paystation/domain/PayStationImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 36e22c4..14ad111 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -83,7 +83,7 @@ private void reset() { /* Returns total money collected in the paystation since the last call to empty, and resets total */ public int empty() { int retval = totalCollected; - //totalCollected = 0; + totalCollected = 0; return retval; } } From a676d8fceb63283c1669b0c97f6166ac40abdbf3 Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:29:18 -0400 Subject: [PATCH 21/26] Add shouldClearMapAfterBuy() Test Add test to check that map of coins is cleared after a call to buy(). Comment out code in Impl to demonstrate fail state. Test is currently RED. --- src/paystation/domain/PayStationImpl.java | 2 +- test/paystation/domain/PayStationImplTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 14ad111..121a0ec 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -76,7 +76,7 @@ public Map cancel() { private void reset() { timeBought = insertedSoFar = 0; - insertedMap.clear(); + //insertedMap.clear(); } @Override diff --git a/test/paystation/domain/PayStationImplTest.java b/test/paystation/domain/PayStationImplTest.java index 096e26e..b10cd64 100644 --- a/test/paystation/domain/PayStationImplTest.java +++ b/test/paystation/domain/PayStationImplTest.java @@ -235,5 +235,15 @@ public void emptyResetsTotalCollected() throws IllegalCoinException { 0, ps.empty()); } + /** + * Call to buy should clear the map. + */ + @Test + public void shouldClearMapAfterBuy() throws IllegalCoinException { + ps.addPayment(25); + ps.buy(); + HashMap emptyMap = (HashMap) ps.cancel(); + assertTrue("Buy should clear map.", emptyMap.isEmpty()); + } } From 6c40c5334d47a1e66b750fea271cf51d3769b86b Mon Sep 17 00:00:00 2001 From: kmbosworth321 Date: Sun, 23 Sep 2018 18:30:42 -0400 Subject: [PATCH 22/26] Make shouldClearMapAfterBuy() test pass Reimplement insertedMap.clear() inside reset() method of Impl to clear map after call to cancel() or buy() Test is now GREEN --- src/paystation/domain/PayStationImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 121a0ec..14ad111 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -76,7 +76,7 @@ public Map cancel() { private void reset() { timeBought = insertedSoFar = 0; - //insertedMap.clear(); + insertedMap.clear(); } @Override From ed49fb5ef673d661734e1e132629d93ab361e179 Mon Sep 17 00:00:00 2001 From: Shmuel Jacobs Date: Wed, 26 Sep 2018 11:55:29 -0400 Subject: [PATCH 23/26] Create abstract class RateStrategy with calculateTime abstract method. --- src/paystation/domain/RateStrategy.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/paystation/domain/RateStrategy.java diff --git a/src/paystation/domain/RateStrategy.java b/src/paystation/domain/RateStrategy.java new file mode 100644 index 0000000..72e8fbf --- /dev/null +++ b/src/paystation/domain/RateStrategy.java @@ -0,0 +1,6 @@ +package paystation.domain; + +public abstract class RateStrategy { + + public abstract int calculateTime(int payment); +} From 9d3edfdfbf13524beb6ec55a69bdd195c1ba9abe Mon Sep 17 00:00:00 2001 From: Shmuel Jacobs Date: Sat, 29 Sep 2018 23:48:54 -0400 Subject: [PATCH 24/26] Wrote JUnit setup to test existence of Linear Rate Strategy. Test cases: No money, base case, 10 cents, into second hour, into third hour. --- .../domain/LinearRateStrategyTests.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/paystation/domain/LinearRateStrategyTests.java diff --git a/test/paystation/domain/LinearRateStrategyTests.java b/test/paystation/domain/LinearRateStrategyTests.java new file mode 100644 index 0000000..cad412c --- /dev/null +++ b/test/paystation/domain/LinearRateStrategyTests.java @@ -0,0 +1,82 @@ + +package paystation.domain; + +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Before; + +public class LinearRateStrategyTests { + /** + * Test Cases for behavior of PayStation Using LinearRateStrategyTests + */ + PayStationImpl ps; + + /** + * Tests existence of linear rate strategy in setup + */ + @Before + public void setup() { + ps = new PayStationImpl(new LinearRateStrategy()); + } + +// @Test +// public void existsClassLinearRateStrategy() { +// rs = new LinearRateStrategy(); +// } + // Don't use @Test -- test in setup + + /** + * Assert that meter starts with no time on it + */ + @Test + public void shouldHaveNoTimeAfterNoMoney(){ + assertEquals("Time should be zero until payment", 0, ps.readDisplay()); + } + + /** + * Entering 5 cents should make the display report 2 minutes parking time. + */ + @Test + public void shouldDisplay2MinFor5Cents() + throws IllegalCoinException { + ps.addPayment(5); + assertEquals("Should display 2 min for 5 cents", + 2, ps.readDisplay()); + } + + /** + * Entering 25 cents should make the display report 10 minutes parking time. + */ + @Test + public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { + ps.addPayment(25); + assertEquals("Should display 10 min for 25 cents", + 10, ps.readDisplay()); + } + + /** + * Check that linear price model continued into second hour. + * + * Checks divergence between Alpha and Beta. + * Uses whole number of minutes to avoid complication with testing whether time is double or int. + */ + @Test + public void shouldDisplay70Minfor175Cents() throws IllegalCoinException { + for (int i = 0; i < 7; i++) { + ps.addPayment(25); + } + assertEquals("Should display 70 minutes for $1.75.", 70, ps.readDisplay()); + } + + /** + * Check that linear price model continues into third hour. + */ + @Test + public void shouldDisplay130MinFor310Cents() throws IllegalCoinException { + for(int i = 0; i < 13; i++) { + ps.addPayment(25); + } + assertEquals("Should display 130 minutes for $3.25", 130, ps.readDisplay()); + } + +} From b1c5ca0c9b1e1236fc05042789ccd768b1731ba2 Mon Sep 17 00:00:00 2001 From: Shmuel Jacobs Date: Wed, 3 Oct 2018 23:36:27 -0400 Subject: [PATCH 25/26] Wrote JUnit setup to test existence of Progressive Rate Strategy. Test cases: No money, base case, 10 cents, into second hour, into third hour. --- .../domain/ProgressiveRateStrategyTests.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/paystation/domain/ProgressiveRateStrategyTests.java diff --git a/test/paystation/domain/ProgressiveRateStrategyTests.java b/test/paystation/domain/ProgressiveRateStrategyTests.java new file mode 100644 index 0000000..c816400 --- /dev/null +++ b/test/paystation/domain/ProgressiveRateStrategyTests.java @@ -0,0 +1,83 @@ + +package paystation.domain; + +import org.junit.Test; +import static org.junit.Assert.*; +import static paystation.domain.Strategy.PROGRESSIVE; + +import org.junit.Before; + +public class ProgressiveRateStrategyTests { + /** + * Test Cases for behavior of PayStation Using LinearRateStrategyTests + */ + PayStationImpl ps; + + /** + * Tests existence of linear rate strategy in setup + */ + @Before + public void setup() { + ps = new PayStationImpl(); + ps.setRateStrategy(PROGRESSIVE); + } + + /** + * Assert that meter starts with no time on it + */ + @Test + public void shouldHaveNoTimeAfterNoMoney(){ + assertEquals("Time should be zero until payment", 0, ps.readDisplay()); + } + + /** + * Entering 5 cents should make the display report 2 minutes parking time. + */ + @Test + public void shouldDisplay2MinFor5Cents() + throws IllegalCoinException { + ps.addPayment(5); + assertEquals("Should display 2 min for 5 cents", + 2, ps.readDisplay()); + } + + /** + * Entering 25 cents should make the display report 10 minutes parking time. + */ + @Test + public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { + ps.addPayment(25); + assertEquals("Should display 10 min for 25 cents", + 10, ps.readDisplay()); + } + + /** + * Check that progressive price model begins in second hour. + * + * Checks divergence between Alpha and Beta. + * Uses whole number of minutes to avoid complication with testing whether time is double or int. + */ + @Test + public void shouldDisplay63Minfor160Cents() throws IllegalCoinException { + for (int i = 0; i < 6; i++) { + ps.addPayment(25); + } + ps.addPayment(10); + assertEquals("Should display 63 minutes for $1.60.", 63, ps.readDisplay()); + } + + /** + * Check that progressive price model implements third hour pricing. + * + * Uses whole numbers. + */ + @Test + public void shouldDisplay121MinFor355Cents() throws IllegalCoinException { + for(int i = 0; i < 14; i++) { + ps.addPayment(25); + } // Pay $3.50 for first two hours. + ps.addPayment(5); + assertEquals("Should display 121 minutes for $3.55", 121, ps.readDisplay()); + } + +} From 0474766d407bad3fb5e7701972e4fbc1e8390862 Mon Sep 17 00:00:00 2001 From: Shmuel Jacobs Date: Fri, 5 Oct 2018 11:29:54 -0400 Subject: [PATCH 26/26] Dummy setRateStrategy() method --- src/paystation/domain/PayStation.java | 8 + src/paystation/domain/PayStationImpl.java | 5 + src/paystation/domain/RateStrategy.java | 12 +- src/paystation/domain/Strategy.java | 7 + .../domain/LinearRateStrategyTests.java | 167 +++++++++--------- .../domain/ProgressiveRateStrategyTests.java | 166 ++++++++--------- 6 files changed, 194 insertions(+), 171 deletions(-) create mode 100644 src/paystation/domain/Strategy.java diff --git a/src/paystation/domain/PayStation.java b/src/paystation/domain/PayStation.java index 3604b50..ad074ae 100644 --- a/src/paystation/domain/PayStation.java +++ b/src/paystation/domain/PayStation.java @@ -64,4 +64,12 @@ public interface PayStation { * it, setting the total to zero. Note: Money only collected after call to Buy */ int empty(); + + /** + * Dummy header for setting current rate strategy of paystation instance. + * Resolve clashes by overrulling this change. Header is to make tests more coherent. + * @param newStrategy enum indicating selected strategy. + */ + void setRateStrategy(Strategy newStrategy); + } diff --git a/src/paystation/domain/PayStationImpl.java b/src/paystation/domain/PayStationImpl.java index 14ad111..cf0a31e 100644 --- a/src/paystation/domain/PayStationImpl.java +++ b/src/paystation/domain/PayStationImpl.java @@ -86,4 +86,9 @@ public int empty() { totalCollected = 0; return retval; } + + @Override + public void setRateStrategy(Strategy newStrategy) { + System.err.println("set rate strategy unimplemented"); + } } diff --git a/src/paystation/domain/RateStrategy.java b/src/paystation/domain/RateStrategy.java index 72e8fbf..eb081e1 100644 --- a/src/paystation/domain/RateStrategy.java +++ b/src/paystation/domain/RateStrategy.java @@ -1,6 +1,6 @@ -package paystation.domain; - -public abstract class RateStrategy { - - public abstract int calculateTime(int payment); -} +package paystation.domain; + +public abstract class RateStrategy { + + public abstract int calculateTime(int payment); +} diff --git a/src/paystation/domain/Strategy.java b/src/paystation/domain/Strategy.java new file mode 100644 index 0000000..8e395c1 --- /dev/null +++ b/src/paystation/domain/Strategy.java @@ -0,0 +1,7 @@ +package paystation.domain; + +/** + * Convenience enum for setting rate strategy in dummy setRateStrategy method. + * Resolve for merge by overrulling this commit and accepting the work of whoever took on this problem. + */ +public enum Strategy {LINEAR, PROGRESSIVE} \ No newline at end of file diff --git a/test/paystation/domain/LinearRateStrategyTests.java b/test/paystation/domain/LinearRateStrategyTests.java index cad412c..ba0b7e2 100644 --- a/test/paystation/domain/LinearRateStrategyTests.java +++ b/test/paystation/domain/LinearRateStrategyTests.java @@ -1,82 +1,85 @@ - -package paystation.domain; - -import org.junit.Test; -import static org.junit.Assert.*; -import org.junit.Before; - -public class LinearRateStrategyTests { - /** - * Test Cases for behavior of PayStation Using LinearRateStrategyTests - */ - PayStationImpl ps; - - /** - * Tests existence of linear rate strategy in setup - */ - @Before - public void setup() { - ps = new PayStationImpl(new LinearRateStrategy()); - } - -// @Test -// public void existsClassLinearRateStrategy() { -// rs = new LinearRateStrategy(); -// } - // Don't use @Test -- test in setup - - /** - * Assert that meter starts with no time on it - */ - @Test - public void shouldHaveNoTimeAfterNoMoney(){ - assertEquals("Time should be zero until payment", 0, ps.readDisplay()); - } - - /** - * Entering 5 cents should make the display report 2 minutes parking time. - */ - @Test - public void shouldDisplay2MinFor5Cents() - throws IllegalCoinException { - ps.addPayment(5); - assertEquals("Should display 2 min for 5 cents", - 2, ps.readDisplay()); - } - - /** - * Entering 25 cents should make the display report 10 minutes parking time. - */ - @Test - public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { - ps.addPayment(25); - assertEquals("Should display 10 min for 25 cents", - 10, ps.readDisplay()); - } - - /** - * Check that linear price model continued into second hour. - * - * Checks divergence between Alpha and Beta. - * Uses whole number of minutes to avoid complication with testing whether time is double or int. - */ - @Test - public void shouldDisplay70Minfor175Cents() throws IllegalCoinException { - for (int i = 0; i < 7; i++) { - ps.addPayment(25); - } - assertEquals("Should display 70 minutes for $1.75.", 70, ps.readDisplay()); - } - - /** - * Check that linear price model continues into third hour. - */ - @Test - public void shouldDisplay130MinFor310Cents() throws IllegalCoinException { - for(int i = 0; i < 13; i++) { - ps.addPayment(25); - } - assertEquals("Should display 130 minutes for $3.25", 130, ps.readDisplay()); - } - -} + +package paystation.domain; + +import org.junit.Test; +import static org.junit.Assert.*; +import static paystation.domain.Strategy.LINEAR; + +import org.junit.Before; + +public class LinearRateStrategyTests { + /** + * Test Cases for behavior of PayStation Using LinearRateStrategyTests + */ + PayStationImpl ps; + + /** + * Tests existence of linear rate strategy in setup + */ + @Before + public void setup() { + ps = new PayStationImpl(); + ps.setRateStrategy(LINEAR); + } + +// @Test +// public void existsClassLinearRateStrategy() { +// rs = new LinearRateStrategy(); +// } + // Don't use @Test -- test in setup + + /** + * Assert that meter starts with no time on it + */ + @Test + public void shouldHaveNoTimeAfterNoMoney(){ + assertEquals("Time should be zero until payment", 0, ps.readDisplay()); + } + + /** + * Entering 5 cents should make the display report 2 minutes parking time. + */ + @Test + public void shouldDisplay2MinFor5Cents() + throws IllegalCoinException { + ps.addPayment(5); + assertEquals("Should display 2 min for 5 cents", + 2, ps.readDisplay()); + } + + /** + * Entering 25 cents should make the display report 10 minutes parking time. + */ + @Test + public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { + ps.addPayment(25); + assertEquals("Should display 10 min for 25 cents", + 10, ps.readDisplay()); + } + + /** + * Check that linear price model continued into second hour. + * + * Checks divergence between Alpha and Beta. + * Uses whole number of minutes to avoid complication with testing whether time is double or int. + */ + @Test + public void shouldDisplay70Minfor175Cents() throws IllegalCoinException { + for (int i = 0; i < 7; i++) { + ps.addPayment(25); + } + assertEquals("Should display 70 minutes for $1.75.", 70, ps.readDisplay()); + } + + /** + * Check that linear price model continues into third hour. + */ + @Test + public void shouldDisplay130MinFor310Cents() throws IllegalCoinException { + for(int i = 0; i < 13; i++) { + ps.addPayment(25); + } + assertEquals("Should display 130 minutes for $3.25", 130, ps.readDisplay()); + } + +} diff --git a/test/paystation/domain/ProgressiveRateStrategyTests.java b/test/paystation/domain/ProgressiveRateStrategyTests.java index c816400..9bfeb97 100644 --- a/test/paystation/domain/ProgressiveRateStrategyTests.java +++ b/test/paystation/domain/ProgressiveRateStrategyTests.java @@ -1,83 +1,83 @@ - -package paystation.domain; - -import org.junit.Test; -import static org.junit.Assert.*; -import static paystation.domain.Strategy.PROGRESSIVE; - -import org.junit.Before; - -public class ProgressiveRateStrategyTests { - /** - * Test Cases for behavior of PayStation Using LinearRateStrategyTests - */ - PayStationImpl ps; - - /** - * Tests existence of linear rate strategy in setup - */ - @Before - public void setup() { - ps = new PayStationImpl(); - ps.setRateStrategy(PROGRESSIVE); - } - - /** - * Assert that meter starts with no time on it - */ - @Test - public void shouldHaveNoTimeAfterNoMoney(){ - assertEquals("Time should be zero until payment", 0, ps.readDisplay()); - } - - /** - * Entering 5 cents should make the display report 2 minutes parking time. - */ - @Test - public void shouldDisplay2MinFor5Cents() - throws IllegalCoinException { - ps.addPayment(5); - assertEquals("Should display 2 min for 5 cents", - 2, ps.readDisplay()); - } - - /** - * Entering 25 cents should make the display report 10 minutes parking time. - */ - @Test - public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { - ps.addPayment(25); - assertEquals("Should display 10 min for 25 cents", - 10, ps.readDisplay()); - } - - /** - * Check that progressive price model begins in second hour. - * - * Checks divergence between Alpha and Beta. - * Uses whole number of minutes to avoid complication with testing whether time is double or int. - */ - @Test - public void shouldDisplay63Minfor160Cents() throws IllegalCoinException { - for (int i = 0; i < 6; i++) { - ps.addPayment(25); - } - ps.addPayment(10); - assertEquals("Should display 63 minutes for $1.60.", 63, ps.readDisplay()); - } - - /** - * Check that progressive price model implements third hour pricing. - * - * Uses whole numbers. - */ - @Test - public void shouldDisplay121MinFor355Cents() throws IllegalCoinException { - for(int i = 0; i < 14; i++) { - ps.addPayment(25); - } // Pay $3.50 for first two hours. - ps.addPayment(5); - assertEquals("Should display 121 minutes for $3.55", 121, ps.readDisplay()); - } - -} + +package paystation.domain; + +import org.junit.Test; +import static org.junit.Assert.*; +import static paystation.domain.Strategy.PROGRESSIVE; + +import org.junit.Before; + +public class ProgressiveRateStrategyTests { + /** + * Test Cases for behavior of PayStation Using LinearRateStrategyTests + */ + PayStationImpl ps; + + /** + * Tests existence of linear rate strategy in setup + */ + @Before + public void setup() { + ps = new PayStationImpl(); + ps.setRateStrategy(PROGRESSIVE); + } + + /** + * Assert that meter starts with no time on it + */ + @Test + public void shouldHaveNoTimeAfterNoMoney(){ + assertEquals("Time should be zero until payment", 0, ps.readDisplay()); + } + + /** + * Entering 5 cents should make the display report 2 minutes parking time. + */ + @Test + public void shouldDisplay2MinFor5Cents() + throws IllegalCoinException { + ps.addPayment(5); + assertEquals("Should display 2 min for 5 cents", + 2, ps.readDisplay()); + } + + /** + * Entering 25 cents should make the display report 10 minutes parking time. + */ + @Test + public void shouldDisplay10MinFor25Cents() throws IllegalCoinException { + ps.addPayment(25); + assertEquals("Should display 10 min for 25 cents", + 10, ps.readDisplay()); + } + + /** + * Check that progressive price model begins in second hour. + * + * Checks divergence between Alpha and Beta. + * Uses whole number of minutes to avoid complication with testing whether time is double or int. + */ + @Test + public void shouldDisplay63Minfor160Cents() throws IllegalCoinException { + for (int i = 0; i < 6; i++) { + ps.addPayment(25); + } + ps.addPayment(10); + assertEquals("Should display 63 minutes for $1.60.", 63, ps.readDisplay()); + } + + /** + * Check that progressive price model implements third hour pricing. + * + * Uses whole numbers. + */ + @Test + public void shouldDisplay121MinFor355Cents() throws IllegalCoinException { + for(int i = 0; i < 14; i++) { + ps.addPayment(25); + } // Pay $3.50 for first two hours. + ps.addPayment(5); + assertEquals("Should display 121 minutes for $3.55", 121, ps.readDisplay()); + } + +}