def test_a_PriceRule_is_False_if_the_stock_hasnt_got_an_update_yet(self):
     """
     Tests if a PriceRule is False if the stock hasn't got an update yet
     """
     self.exchange["AAPL"] = Stock("AAPL")
     rule = PriceRule("AAPL", lambda stock: stock.price > 10)
     self.assertFalse(rule.matches(self.exchange))
Beispiel #2
0
from datetime import datetime
from stock_alerter.stock import Stock
from stock_alerter.rule import PriceRule

# słownik zawierający aktywa
exchange = {"GOOG": Stock("GOOG"), "MSFT": Stock("MSFT")}

# reguła dla danego aktywu
rule = PriceRule("GOOG", lambda stock: stock.price > 100)

print(rule.matches(exchange))
# False, cena jest na razie None

exchange["GOOG"].update(datetime(2015, 11, 9), 50)
print(rule.matches(exchange))
# False, cena nie jest > 100

exchange["GOOG"].update(datetime(2015, 11, 10), 101)
print(rule.matches(exchange))
# True, cena jest > 100
Beispiel #3
0
 def test_a_rule_depends_on_its_stock(self):
     rule = PriceRule("MSFT", lambda stock: stock.price > 10)
     assert rule.depends_on() == "MSFT"
Beispiel #4
0
 def test_matches_is_false_if_stock_has_not_been_updated(self, exchange):
     exchange["AAPL"] = Stock("AAPL")
     rule = PriceRule("AAPL", lambda stock: stock.price > 10)
     assert rule.matches(exchange) is False
Beispiel #5
0
 def test_matches_on_condition_not_otherwise(self, exchange, stock,
                                             condition, assertion):
     rule = PriceRule(stock, condition)
     assert rule.matches(exchange) is assertion
 def test_a_PriceRule_only_depends_on_its_stock(self):
     """Tests if a PriceRule only depends on its stock"""
     rule = PriceRule("MSFT", lambda stock: stock.price > 10)
     self.assertEqual({"MSFT"}, rule.depends_on())
 def test_a_PriceRule_is_False_if_the_stock_is_not_in_the_exchange(self):
     """Tests if a PriceRule is False if the stock is not in the exchange"""
     rule = PriceRule("MSFT", lambda stock: stock.price > 10)
     self.assertFalse(rule.matches(self.exchange))
 def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
     """Tests if a PriceRule is False if the condition is not met"""
     rule = PriceRule("GOOG", lambda stock: stock.price < 10)
     self.assertFalse(rule.matches(self.exchange))
 def test_a_PriceRule_matches_when_it_meets_the_condition(self):
     """Tests if a PriceRule matches when it meets the condition"""
     rule = PriceRule("GOOG", lambda stock: stock.price > 10)
     self.assertTrue(rule.matches(self.exchange))
 def test_an_AndRule_matches_if_all_component_rules_are_true(self):
     """Tests if an AndRule matches if all component rules are True"""
     rule = AndRule(PriceRule("GOOG", lambda stock: stock.price > 8),
                    PriceRule("MSFT", lambda stock: stock.price > 10))
     self.assertTrue(rule.matches(self.exchange))
Beispiel #11
0
 def test_a_PriceRule_is_False_if_the_stock_is_not_in_the_exchange(self):
     rule = PriceRule("MSFT", lambda stock: stock.price > 10)
     self.assertFalse(rule.matches(self.exchange))
Beispiel #12
0
 def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
     rule = PriceRule("GOOG", lambda stock: stock.price < 10)
     self.assertFalse(rule.matches(self.exchange))