@@ -12,14 +12,13 @@ def setUp(self):
12
12
def test_price_of_a_new_stock_class_should_be_None (self ):
13
13
self .assertIsNone (self .goog .price )
14
14
15
- @unittest .expectedFailure
16
15
def test_stock_update (self ):
17
16
"""An update should set the price on the stock object
18
17
19
18
We will be using the `datetime` module for the timestamp
20
19
"""
21
20
self .goog .update (datetime (2014 , 2 , 12 ), price = 10 )
22
- self .assertEqual (100 , self .goog .price )
21
+ self .assertEqual (10 , self .goog .price )
23
22
24
23
def test_negative_price_should_throw_ValueError (self ):
25
24
with self .assertRaises (ValueError ):
@@ -37,26 +36,24 @@ def test_price_is_the_latest_even_if_updates_are_made_out_of_order(self):
37
36
38
37
39
38
class StockTrendTest (unittest .TestCase ):
40
- def setUp (self ):
41
- self .goog = Stock ("GOOG" )
42
-
43
- def given_a_series_of_prices (self , prices ):
39
+ def given_a_series_of_prices (self , goog , prices ):
44
40
timestamps = [datetime (2014 , 2 , 10 ), datetime (2014 , 2 , 11 ),
45
41
datetime (2014 , 2 , 12 ), datetime (2014 , 2 , 13 )]
46
42
for timestamp , price in zip (timestamps , prices ):
47
- self .goog .update (timestamp , price )
48
-
49
- def test_increasing_trend_is_true_if_price_increase_for_3_updates (self ):
50
- self .given_a_series_of_prices ([8 , 10 , 12 ])
51
- self .assertTrue (self .goog .is_increasing_trend ())
52
-
53
- def test_increasing_trend_is_false_if_price_decreases (self ):
54
- self .given_a_series_of_prices ([8 , 12 , 10 ])
55
- self .assertFalse (self .goog .is_increasing_trend ())
56
-
57
- def test_increasing_trend_is_false_if_price_equal (self ):
58
- self .given_a_series_of_prices ([8 , 10 , 10 ])
59
- self .assertFalse (self .goog .is_increasing_trend ())
43
+ goog .update (timestamp , price )
44
+
45
+ def test_stock_trends (self ):
46
+ dataset = [
47
+ ([8 , 10 , 12 ], True ),
48
+ ([8 , 12 , 10 ], False ),
49
+ ([8 , 10 , 10 ], False )
50
+ ]
51
+ for data in dataset :
52
+ prices , output = data
53
+ with self .subTest (prices = prices , output = output ):
54
+ goog = Stock ("GOOG" )
55
+ self .given_a_series_of_prices (goog , prices )
56
+ self .assertEqual (output , goog .is_increasing_trend ())
60
57
61
58
62
59
class StockCrossOverSignalTest (unittest .TestCase ):
0 commit comments