@@ -12,14 +12,13 @@ def setUp(self):
1212 def test_price_of_a_new_stock_class_should_be_None (self ):
1313 self .assertIsNone (self .goog .price )
1414
15- @unittest .expectedFailure
1615 def test_stock_update (self ):
1716 """An update should set the price on the stock object
1817
1918 We will be using the `datetime` module for the timestamp
2019 """
2120 self .goog .update (datetime (2014 , 2 , 12 ), price = 10 )
22- self .assertEqual (100 , self .goog .price )
21+ self .assertEqual (10 , self .goog .price )
2322
2423 def test_negative_price_should_throw_ValueError (self ):
2524 with self .assertRaises (ValueError ):
@@ -37,26 +36,24 @@ def test_price_is_the_latest_even_if_updates_are_made_out_of_order(self):
3736
3837
3938class 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 ):
4440 timestamps = [datetime (2014 , 2 , 10 ), datetime (2014 , 2 , 11 ),
4541 datetime (2014 , 2 , 12 ), datetime (2014 , 2 , 13 )]
4642 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 ())
6057
6158
6259class StockCrossOverSignalTest (unittest .TestCase ):
0 commit comments