from datetime import datetime
from unittest import TestCase

from rule import PriceRule
from stock import Stock


class TestPriceRule(TestCase):
    @classmethod
    def setUpClass(cls):
        goog = Stock("GOOG")
        goog.update(datetime(2014, 2, 10), 11)
        cls.exchange = {"GOOG": goog}

    def test_a_PriceRule_matches_when_it_meets_the_condition(self):
        """Tests if true is returned when an exchange matches a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price > 10)
        self.assertTrue(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
        """Tests if false is returned when an exchange does not match a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price < 10)
        self.assertFalse(rule.matches(self.exchange))

from datetime import datetime
from unittest import TestCase

from rule import PriceRule
from stock import Stock


class TestPriceRule(TestCase):
    @classmethod
    def setUpClass(cls):
        goog = Stock("GOOG")
        goog.update(datetime(2014, 2, 10), 11)
        cls.exchange = {"GOOG": goog}

    def test_a_PriceRule_matches_when_it_meets_the_condition(self):
        """Tests if true is returned when an exchange matches a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price > 10)
        self.assertTrue(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
        """Tests if false is returned when an exchange does not match a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price < 10)
        self.assertFalse(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_stock_is_not_in_the_exchange(self):
        """Tests if false is returned if a match is attempted when the stock is not in the exchange.

        """
        rule = PriceRule("MSFT", lambda stock: stock.price > 10)
        self.assertFalse(rule.matches(self.exchange))

Add a PriceRule test if match is attempted when stock is not in the exchange.
Add a PriceRule test if match is attempted when stock is not in the exchange.

  from datetime import datetime
  from unittest import TestCase
  
  from rule import PriceRule
  from stock import Stock
  
  
  class TestPriceRule(TestCase):
      @classmethod
      def setUpClass(cls):
          goog = Stock("GOOG")
          goog.update(datetime(2014, 2, 10), 11)
          cls.exchange = {"GOOG": goog}
  
      def test_a_PriceRule_matches_when_it_meets_the_condition(self):
          """Tests if true is returned when an exchange matches a rule.
  
          """
          rule = PriceRule("GOOG", lambda stock: stock.price > 10)
          self.assertTrue(rule.matches(self.exchange))
  
      def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
          """Tests if false is returned when an exchange does not match a rule.
  
          """
          rule = PriceRule("GOOG", lambda stock: stock.price < 10)
          self.assertFalse(rule.matches(self.exchange))
  
+     def test_a_PriceRule_is_False_if_the_stock_is_not_in_the_exchange(self):
+         """Tests if false is returned if a match is attempted when the stock is not in the exchange.
+ 
+         """
+         rule = PriceRule("MSFT", lambda stock: stock.price > 10)
+         self.assertFalse(rule.matches(self.exchange))
+ 
Add a PriceRule test if match is attempted when stock is not in the exchange.
## Code Before:
from datetime import datetime
from unittest import TestCase

from rule import PriceRule
from stock import Stock


class TestPriceRule(TestCase):
    @classmethod
    def setUpClass(cls):
        goog = Stock("GOOG")
        goog.update(datetime(2014, 2, 10), 11)
        cls.exchange = {"GOOG": goog}

    def test_a_PriceRule_matches_when_it_meets_the_condition(self):
        """Tests if true is returned when an exchange matches a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price > 10)
        self.assertTrue(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
        """Tests if false is returned when an exchange does not match a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price < 10)
        self.assertFalse(rule.matches(self.exchange))

## Instruction:
Add a PriceRule test if match is attempted when stock is not in the exchange.
## Code After:
from datetime import datetime
from unittest import TestCase

from rule import PriceRule
from stock import Stock


class TestPriceRule(TestCase):
    @classmethod
    def setUpClass(cls):
        goog = Stock("GOOG")
        goog.update(datetime(2014, 2, 10), 11)
        cls.exchange = {"GOOG": goog}

    def test_a_PriceRule_matches_when_it_meets_the_condition(self):
        """Tests if true is returned when an exchange matches a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price > 10)
        self.assertTrue(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_condition_is_not_met(self):
        """Tests if false is returned when an exchange does not match a rule.

        """
        rule = PriceRule("GOOG", lambda stock: stock.price < 10)
        self.assertFalse(rule.matches(self.exchange))

    def test_a_PriceRule_is_False_if_the_stock_is_not_in_the_exchange(self):
        """Tests if false is returned if a match is attempted when the stock is not in the exchange.

        """
        rule = PriceRule("MSFT", lambda stock: stock.price > 10)
        self.assertFalse(rule.matches(self.exchange))
