コード例 #1
0
    def setUp(self):

        self.zone = Zone()

        self.card1 = Card()
        self.card2 = Card()
        self.card3 = Card()
コード例 #2
0
    def test_get_info(self):
        """
        Test getting zone info.
        """

        expected = {"stacked": True}
        self.zone = Zone(expected)
        self.assertDictEqual(expected, self.zone.get_info())
コード例 #3
0
    def test_registration(self):
        """
        Make sure that assigning IDs works.
        """

        card1 = Card()
        card2 = Card()

        zone1 = Zone()
        zone2 = Zone()

        self.assertIsNone(card1.game_id)
        self.assertIsNone(card2.game_id)
        self.assertIsNone(zone1.game_id)
        self.assertIsNone(zone2.game_id)

        # Make sure we can assign ids to a set of cards
        self.game.register((card1, card2))

        self.assertEqual(card1.game_id, 1)
        self.assertEqual(card2.game_id, 2)

        # Make sure we can access the objects from the game
        self.assertEqual(self.game.get_object_with_id("Card", 1), card1)
        self.assertEqual(self.game.get_object_with_id("Card", 2), card2)

        # Make sure that we don't change ids if the id
        # is already there.

        self.game.register((card2, card1))

        self.assertEqual(card1.game_id, 1)
        self.assertEqual(card2.game_id, 2)

        # Make sure that we assign different ids to different
        # classes.

        self.game.register((zone1, zone2))

        self.assertEqual(zone1.game_id, 1)
        self.assertEqual(zone2.game_id, 2)

        # Make sure we can access the objects from the game
        self.assertEqual(self.game.get_object_with_id("Zone", 1), zone1)
        self.assertEqual(self.game.get_object_with_id("Zone", 2), zone2)

        # Make sure we know what to do on edge cases
        self.assertIsNone(self.game.get_object_with_id("Zone", 3))
        self.game.register([])
コード例 #4
0
    def test_get_add_zones(self):
        """
        Test ability to get list of zones. Also tests adding zones.
        """

        zone1 = Zone()
        zone2 = Zone()
        zone3 = Zone()
        region = Region()

        self.assertEqual(0, len(region.get_zones()))

        region.add_zone(zone1)
        region.add_zone(zone2)

        self.assertListEqual([zone1, zone2], region.get_zones())
        self.assertNotIn(zone3, region.get_zones())
コード例 #5
0
    def add_zone(self, zone_config):
        """
        Takes in a single zone configuration and sets it up. This includes
        setting an attribute with that zone name and adding it to the zones
        dictionary.
        """

        zone_object = Zone(zone_config)
        self.zones[zone_object.name] = zone_object
        setattr(self, zone_object.name, zone_object)
コード例 #6
0
    def test_make_action_substitution(self):
        """
        Makes sure that make action actually makes proper substitutions
        depending on variable name.
        """

        card = Card()
        zone = Zone()
        self.game.register([card, zone])

        self.game.make_action('test_argument_types',
                              card=card.game_id,
                              zone=zone.game_id,
                              player=self.player.game_id)
コード例 #7
0
    def test_deregister(self):
        """
        Make sure that we can properly deregister objects.
        """

        player = Player()
        card = Card()
        zone = Zone()
        other = GameObject()
        unregistered = GameObject()

        self.game.register([player, card, zone, other])

        self.game.deregister([player, card, zone, other, unregistered])
        print self.game.registered_objects
        self.assertEqual(self.game.registered_objects["Player"][0], 2)
        self.assertEqual(self.game.registered_objects["Card"][0], 1)
        self.assertEqual(self.game.registered_objects["Zone"][0], 1)
        self.assertEqual(self.game.registered_objects["GameObject"][0], 1)
コード例 #8
0
class ZoneTestCase(TestCase):
    """
    Simple test case around Zones.
    """
    def setUp(self):

        self.zone = Zone()

        self.card1 = Card()
        self.card2 = Card()
        self.card3 = Card()

    def test_add_card(self):
        """
        Test adding cards to a Zone.
        """

        self.zone.add_card(self.card1)
        self.assertIn(self.card1, self.zone.get_cards())

        # No null cards, no duplicates
        self.assertFalse(self.zone.add_card(None))
        self.assertFalse(self.zone.add_card(self.card1))

        self.assertListEqual([self.card1], self.zone.get_cards())

        self.zone.add_card(self.card2)
        self.assertIn(self.card2, self.zone.get_cards())

        # Make sure we have both
        self.assertListEqual([self.card1, self.card2], self.zone.get_cards())

    def test_remove_card(self):
        """
        Test removing cards from a zone.
        """

        # Cannot add null cards, but other stuff is fine
        self.zone.add_card(self.card1)
        self.zone.add_card(self.card2)

        self.assertListEqual([self.card1, self.card2], self.zone.get_cards())

        # Check that the right card is removed, and only that card
        self.zone.remove_card(self.card1)

        self.assertNotIn(self.card1, self.zone.get_cards())
        self.assertIn(self.card2, self.zone.get_cards())

        # Cannot remove a card not in the list
        self.assertFalse(self.zone.remove_card(self.card3))

    def test_contains(self):
        """
        Test checking if a card is in the zone.
        """

        self.zone.add_card(self.card1)
        self.assertTrue(self.card1 in self.zone)
        self.assertFalse(self.card2 in self.zone)

    def test_shuffle(self):
        """
        Test shuffling the cards.
        """

        for _ in range(0, 100):
            self.zone.add_card(Card())

        temp = self.zone.get_cards()[:]
        self.zone.shuffle()

        # Make sure cards were shuffled and that we didn't lose any
        self.assertFalse(temp == self.zone.get_cards())
        self.assertEqual(len(temp), len(self.zone.get_cards()))

    def test_get_num_cards(self):
        """
        Test getting the number of cards in the zone.
        """

        self.zone.add_card(self.card1)
        self.zone.add_card(self.card2)

        self.assertEqual(2, self.zone.get_num_cards())

    def test_get_info(self):
        """
        Test getting zone info.
        """

        expected = {"stacked": True}
        self.zone = Zone(expected)
        self.assertDictEqual(expected, self.zone.get_info())

    def test_push(self):
        """
        Test pushing cards to our list.
        """

        # No duplicates
        self.assertTrue(self.zone.push(self.card1))
        self.assertFalse(self.zone.push(self.card1))

        self.assertTrue(self.zone.push(self.card3))
        self.assertTrue(self.zone.push(self.card2))

        # No null cards
        self.assertFalse(self.zone.push(None))

        self.assertListEqual([self.card1, self.card3, self.card2],
                             self.zone.get_cards())

    def test_pop(self):
        """
        Test popping a card from our list.
        """

        self.zone.push(self.card1)
        self.zone.push(self.card3)
        self.zone.push(self.card2)

        # Make sure we pop the right card
        self.assertEqual(self.card2, self.zone.pop())

        # Make sure it is popped
        self.assertListEqual([self.card1, self.card3], self.zone.get_cards())

        self.assertEqual(self.card3, self.zone.pop())
        self.assertEqual(self.card1, self.zone.pop())

        # Try to pop when there are no cards left
        self.assertEqual(0, len(self.zone.get_cards()))
        self.assertEqual(None, self.zone.pop())

    def test_notify_game(self):
        """
        Make sure that when we move/add/remove cards from a zone
        that the game picks up on it.
        """

        game = Game()
        game.register([self.zone, self.card1])

        expected_transitions = [("add", self.card1.game_id, self.zone.game_id)]

        expected_transitions2 = [("add", self.card1.game_id,
                                  self.zone.game_id),
                                 ("remove", self.card1.game_id)]

        # Test add card
        self.zone.add_card(self.card1)
        self.assertEqual(game.get_public_transitions(), expected_transitions)
        self.zone.remove_card(self.card1)
        game.flush_transitions()

        # Test push card
        self.zone.push(self.card1)
        self.assertEqual(game.get_public_transitions(), expected_transitions)
        self.zone.remove_card(self.card1)
        game.flush_transitions()

        # Test remove card
        self.zone.add_card(self.card1)
        self.zone.remove_card(self.card1)
        self.assertEqual(game.get_public_transitions(), expected_transitions2)
        game.flush_transitions()

        # Test pop card
        self.zone.push(self.card1)
        card = self.zone.pop()
        self.assertEqual(self.card1, card)
        self.assertEqual(game.get_public_transitions(), expected_transitions2)
        game.flush_transitions()

        # Make sure we don't get transitions if there's bad data
        self.zone.add_card(self.card1)
        self.zone.add_card(self.card1)
        self.assertEqual(game.get_public_transitions(), expected_transitions)
        self.zone.remove_card(self.card1)
        game.flush_transitions()

        self.zone.pop()
        self.zone.remove_card(self.card1)
        self.assertEqual(game.get_public_transitions(), [])

    def test_peek(self):
        """
        Make sure that we can peek at the top card of the zone.
        """

        self.assertIsNone(self.zone.peek())
        self.zone.push(self.card1)
        self.assertEqual(self.card1, self.zone.peek())

    def test_set_cards(self):
        """
        Make sure we can add a list of cards diretly. This won't just set
        the cards but will generate transitions to move the cards.
        """

        cards = [self.card1, self.card2, self.card3]
        self.zone.set_cards(cards)
        self.assertListEqual(self.zone.get_cards(), cards)

        cards = []
        self.zone.set_cards(cards)
        self.assertListEqual(self.zone.get_cards(), cards)