Пример #1
0
    def setUp(self):
        """
        Sets up cards for the tests.
        """

        self.cardA = Card({"Color": "purple", "Number": "2", "Shape": "square", "Fill": "empty"})
        self.cardA2 = Card({"Color": "purple", "Number": "2", "Shape": "square", "Fill": "empty"})
        self.cardB = Card({"Color": "blue", "Number": "1", "Shape": "circle", "Fill": "lines"})
        self.cardC = Card({"Color": "black", "Direction": "west", "Polarity": "negative", "Temperature": "cold"})
        self.cardD = Card({"Color": "teal", "Direction": "south", "Polarity": "positive"})
        self.cardE = Card({"Color": "teal", "Direction": "south", "Polarity": "positive", "Temperature": "hot"})
Пример #2
0
class TestCardFunctions(unittest.TestCase):
    """
    This tests the basic card functions of equality and compatibility.
    """

    def setUp(self):
        """
        Sets up cards for the tests.
        """

        self.cardA = Card({"Color": "purple", "Number": "2", "Shape": "square", "Fill": "empty"})
        self.cardA2 = Card({"Color": "purple", "Number": "2", "Shape": "square", "Fill": "empty"})
        self.cardB = Card({"Color": "blue", "Number": "1", "Shape": "circle", "Fill": "lines"})
        self.cardC = Card({"Color": "black", "Direction": "west", "Polarity": "negative", "Temperature": "cold"})
        self.cardD = Card({"Color": "teal", "Direction": "south", "Polarity": "positive"})
        self.cardE = Card({"Color": "teal", "Direction": "south", "Polarity": "positive", "Temperature": "hot"})

    def test_equal(self):
        """
        Test the equality function that tells whether two cards have equal
        features and  values.
        """

        # these two cards are the same
        self.assertEqual(self.cardA, self.cardA2)
        # these are not
        self.assertNotEqual(self.cardA, self.cardB)
        # want to make sure one card isn't equal to another with a superset of features
        self.assertNotEqual(self.cardD, self.cardE)

    def test_compatible(self):
        """
        Tests the compatibility function that tells whether two cards have
        compatible features.
        """

        # a card should be compatible with itself
        self.assertTrue(self.cardA.compatible(self.cardA))
        # and another card with all the same features
        self.assertTrue(self.cardA.compatible(self.cardB))
        # make sure cards with different features are not compatible
        self.assertFalse(self.cardA.compatible(self.cardC))
        # make sure a card with a superset of features is not compatible with the subset
        self.assertFalse(self.cardC.compatible(self.cardD))

        # test against feature lists
        self.assertTrue(self.cardA.compatible(["Color", "Number", "Shape", "Fill"]))
        self.assertFalse(self.cardA.compatible(["Color", "Number", "Shape"]))
        self.assertFalse(self.cardA.compatible(["Color", "Direction", "Polarity", "Temperature"]))