diff options
author | clarkohw <66530369+clarkohw@users.noreply.github.com> | 2021-04-19 16:17:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 16:17:36 -0400 |
commit | 58dbfe9d7e511e47c8b50078f060911de74b1d4b (patch) | |
tree | e91feb27c711f65814753b0a41ad49da76cf62ea /src/test/java/edu/brown/cs/student/ProfitCalculationTest.java | |
parent | 534d0cc5070287b221fa77f5dd564dd4544b5780 (diff) | |
parent | 3780077f257b973426577d6168936a3ce0a904e3 (diff) |
Merge pull request #14 from cs0320-2021/profit-tests
more profit testing
Diffstat (limited to 'src/test/java/edu/brown/cs/student/ProfitCalculationTest.java')
-rw-r--r-- | src/test/java/edu/brown/cs/student/ProfitCalculationTest.java | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java index a4baa53..1291245 100644 --- a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java +++ b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java @@ -13,6 +13,8 @@ import org.junit.Before; import org.junit.Test; import java.time.LocalDate; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.sql.Date; import java.time.Instant; @@ -36,7 +38,7 @@ public class ProfitCalculationTest { @Before public void setUp() { try { - db = new DatabaseQuerier("data/lil_mock.sqlite3"); + db = new DatabaseQuerier("data/profit_testing.sqlite3"); } catch (Exception e) { System.out.println("DBQuerier Test, couldn't connect to db???"); } @@ -59,16 +61,83 @@ public class ProfitCalculationTest { assertEquals(trade.get(0).getUnrealizedGain(), 3842.25, .25); assertEquals(trade.get(0).getRealizedGain(), 0, .01); + //just sell + profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "SELL", new Date(1518010558000l), + new Date(1618698807000l)); + trade = profitCalculation.getHoldingsList(); + assertTrue(trade.isEmpty()); + assertEquals(profitCalculation.calculateGains(), 0, 0.001); + + tearDown(); } - public void checkAPICalls() { + @Test + public void otherBuySellCases() { + setUp(); + //buy and sell at same timestamp + ProfitCalculation profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "concurrentBS", new Date(1518010558000l), + new Date(1715629591000l)); + + assertEquals(profitCalculation.getProfitMap().get(100), 1, .01); + + //buys at multiple prices + profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "mulitpleBuyPrices", + new Date(1518010558000l), + new Date(1715629591000l)); + assertEquals(profitCalculation.getProfitMap().get(101), 1, .01); + assertEquals(profitCalculation.getMoneyInput(), 3750, .01); + assertEquals(profitCalculation.getHoldingsList().get(0).getRealizedGain(), 3750, 0.01); + + //left over holdings + profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "dontSellAll", + new Date(1518010558000l), + new Date(1715629591000l)); + + assertEquals(profitCalculation.getHoldingsList().get(0).getShares(), 25, .01); + tearDown(); + } + + @Test + public void testAPICalls() { ProfitCalculation profitCalculation = new ProfitCalculation(DatabaseQuerier.getConn(), "Don", new Date(1618234200000l), - new Date(1618814264000l)); + new Date(1618703800000l)); //check sp500 calculation. 411.28 to 417.30 assertEquals(profitCalculation.compareToSP500(), .01464, .001); + tearDown(); + + } + + @Test + public void databaseAndConnectionIssues() { + //no database connection + ProfitCalculation profitCalculation = + new ProfitCalculation(null, "Don", new Date(1518010558000l), + new Date(1618698807000l)); + assertEquals(profitCalculation.getProfitMap(), new HashMap<>()); + + assertEquals(profitCalculation.getHoldingsList(), new LinkedList<>()); + + setUp(); + //invalid person + profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "1234", new Date(1518010558000l), + new Date(1618698807000l)); + assertEquals(profitCalculation.getHoldingsList(), new LinkedList<>()); + + + //invalid stock ticker + profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "invalidTicker", new Date(1518010558000l), + new Date(1618698807000l)); + assertEquals(profitCalculation.getHoldingsList().get(0).getRealizedGain(), 0, .01); + assertEquals(profitCalculation.getHoldingsList().get(0).getUnrealizedGain(), 0, .01); } |