Skip to content

Commit 029445c

Browse files
author
Siddharta Govindaraj
committed
Refactored to use price_history - trend test still failing
1 parent 5630788 commit 029445c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

stock_alerter/stock.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
class Stock:
22
def __init__(self, symbol):
33
self.symbol = symbol
4-
self.price = None
4+
self.price_history = []
5+
6+
@property
7+
def price(self):
8+
return self.price_history[-1] \
9+
if self.price_history else None
510

611
def update(self, timestamp, price):
712
if price < 0:
813
raise ValueError("price should not be negative")
9-
self.price = price
14+
self.price_history.append(price)

stock_alerter/tests/test_stock.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ def test_stock_price_should_give_the_latest_price(self):
2727
self.goog.update(datetime(2014, 2, 12), price=10)
2828
self.goog.update(datetime(2014, 2, 13), price=8.4)
2929
self.assertAlmostEqual(8.4, self.goog.price, delta=0.0001)
30+
31+
def test_increasing_trend_is_true_if_price_increase_for_3_updates(self):
32+
timestamps = [datetime(2014, 2, 11), datetime(2014, 2, 12),
33+
datetime(2014, 2, 13)]
34+
prices = [8, 10, 12]
35+
for timestamp, price in zip(timestamps, prices):
36+
self.goog.update(timestamp, price)
37+
self.assertTrue(self.goog.is_increasing_trend())

0 commit comments

Comments
 (0)