diff options
author | clarkohw <clark_oh-willeke@brown.edu> | 2021-04-19 20:36:33 -0400 |
---|---|---|
committer | clarkohw <clark_oh-willeke@brown.edu> | 2021-04-19 20:36:33 -0400 |
commit | 905460902c06e9df370c91109554ecbbeb730ac7 (patch) | |
tree | e65315fbf514d0d9f03b5ecbec3eb1be1228ffc6 /src/test/java/edu/brown/cs/student/ProfitCalculationTest.java | |
parent | 43d42b0b88927a552c09bc32145f7e7ef2222652 (diff) |
heavily optimized profit calculations
Diffstat (limited to 'src/test/java/edu/brown/cs/student/ProfitCalculationTest.java')
-rw-r--r-- | src/test/java/edu/brown/cs/student/ProfitCalculationTest.java | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java index 4ca1780..68f53fc 100644 --- a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java +++ b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java @@ -67,7 +67,7 @@ public class ProfitCalculationTest { new Date(1618698807000l)); trade = profitCalculation.getHoldingsList(); assertTrue(trade.isEmpty()); - assertEquals(profitCalculation.calculateGains(), 0, 0.001); + assertEquals(profitCalculation.calculateGainsSingle(), 0, 0.001); tearDown(); } @@ -80,16 +80,18 @@ public class ProfitCalculationTest { new ProfitCalculation(DatabaseQuerier.getConn(), "concurrentBS", new Date(1518010558000l), new Date(1715629591000l)); - assertEquals(profitCalculation.getProfitMap().get(100), 1, .01); + Map<Integer, Double> map = profitCalculation.getProfitMap(); + + assertEquals(map.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); + assertEquals(profitCalculation.getMoneyInput(), 3750, .01); //left over holdings profitCalculation = @@ -136,25 +138,8 @@ public class ProfitCalculationTest { 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); - } + assertTrue(profitCalculation.getHoldingsList().isEmpty()); - @Test - public void optimizationTest() { - try { - db = new DatabaseQuerier("data/trades.sqlite3"); - } catch (Exception e) { - System.out.println("DBQuerier Test, couldn't connect to db???"); - } - - ProfitCalculation profitCalculation = new ProfitCalculation(DatabaseQuerier.getConn(), "invalidTicker", new Date(1618223864000l), - new Date(1618483064000l)); - - long startTime = System.currentTimeMillis(); - profitCalculation.getProfitMap(); - System.out.println("DATA ENDPOINT " + ((System.currentTimeMillis() - startTime) / 1000) + "seconds"); } - }
\ No newline at end of file |