def setUp(self): self.card_one = Card("Heart", "5", 5) self.card_two = Card("Diamond", "Jack", 11) self.card_three = Card("Spade", "7", 7) self.card_four = Card("Spade", "Ace", 14) cards = [self.card_one, self.card_two, self.card_three, self.card_four] self.deck = Deck(cards)
def setUp(self): card_one = Card("Heart", "5", 5) card_two = Card("Diamond", "Jack", 11) card_three = Card("Spade", "7", 7) card_four = Card("Spade", "Ace", 14) cards = [card_one, card_two, card_three, card_four] self.deck = Deck(cards) self.player = Player("John", self.deck)
def test_failing_defense_pushes_attack_cards_into_defender_hand(self): game = Game() game.turn = 'player' game.attack_cards = [Card(Suit.CLUBS, Rank.JACK)] game.defender.hand = [] game.defend() assert game.defender.hand[0] == Card(Suit.CLUBS, Rank.JACK)
def test_it_exists(self): card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography") card_2 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", "STEM") card_3 = Card( "Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", "STEM") cards = [card_1, card_2, card_3] deck = Deck(cards) self.assertIsInstance(deck, Deck)
def setUp(self): self.card_1 = Card("Geography", "What is the capital of Alaska?", "Juneau") self.card_2 = Card( "STEM", "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars") self.card_3 = Card( "STEM", "Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west") self.deck = Deck([self.card_1, self.card_2, self.card_3])
def test_it_exists(self): category_1 = {"category": "Geography"} card_1 = Card("What is the capital of Alaska?", "Juneau", category_1) category_2 = {"category": "Art"} card_2 = Card("Who painted Starry Night?", "Vincent Van Gogh", category_2) category_3 = {"category": "STEM"} card_3 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", category_3) deck = Deck([card_1, card_2, card_3]) assert isinstance(deck, Deck)
def test_cards_in_category(self): card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography") card_2 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", "STEM") card_3 = Card( "Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", "STEM") cards = [card_1, card_2, card_3] deck = Deck(cards) self.assertEqual(deck.cards_in_category("Geography"), [card_1]) self.assertEqual(deck.cards_in_category("STEM"), [card_2, card_3]) self.assertEqual(deck.cards_in_category("Pop Culture"), [])
def test_round(self): card_1 = Card("What is the capital of Alaska?", "Juneau", 'Geography') card_2 = Card("What is the square root of 169?", "13", 'STEM') card_3 = Card("What is the power house of the freaking cell?", "Mitochondria", 'STEM') cards = [card_1, card_2, card_3] deck = Deck(cards) round = Round(deck) assert round.deck == deck assert round.turns == [] assert round.current_card() == card_1 new_turn = round.take_turn('Juneau') assert isinstance(new_turn, Turn) assert new_turn.correct() == True assert round.turns == [new_turn] assert round.number_correct() == 1 assert round.current_card() == card_2 newer_turn = round.take_turn('12') assert len(round.turns) == 2 assert (round.total_turns()) == 2 assert newer_turn.correct() == False assert newer_turn.feedback() == 'Incorrect.' assert round.number_correct() == 1 assert round.number_correct_by_category('Geography') == 1 assert round.number_correct_by_category('STEM') == 0 assert round.percent_correct() == 50.0 assert round.percent_correct_by_category('Geography') == 100.0 assert round.percent_correct_by_category('STEM') == 0.0 assert round.current_card() == card_3
def test_percent_correct(self): card_1 = Card("What is the capital of Alaska?", "Juneau", "Geography") card_2 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", "STEM") card_3 = Card( "Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", "STEM") cards = [card_1, card_2, card_3] deck = Deck(cards) round = Round(deck) round.take_turn("Juneau") round.take_turn("Topeka") self.assertEqual(round.percent_correct(), 50.0)
def generate_cards(cls): cards = [] with open('lib/cards.csv', 'r') as file: reader = csv.reader(file) for row in reader: cards.append(Card(row[2], row[0], row[1])) return cards
def test_it_gives_feedback(self): category_1 = {"category": "Geography"} card_1 = Card("What is the capital of Alaska?", "Juneau", category_1) category_2 = {"category": "Art"} card_2 = Card("Who painted Starry Night?", "Vincent Van Gogh", category_2) category_3 = {"category": "STEM"} card_3 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", category_3) turn_1 = Turn("Juneau", card_1) turn_2 = Turn("Monet", card_2) turn_3 = Turn("Mars", card_3) assert turn_1.feedback() == "Great job! Correct!" assert turn_2.feedback() == "Not quite. Try again!" assert turn_3.feedback() == "Great job! Correct!"
def test_incorrect_guess(self): card = Card("What is the capital of Alaska?", "Juneau", "Geography") turn = Turn("Topeka", card) self.assertEqual(turn.card, card) self.assertEqual(turn.guess, "Topeka") self.assertFalse(turn.is_correct()) self.assertEqual(turn.feedback(), "Incorrect")
def test_deck(self): card_1 = Card("What is the capital of Alaska?", "Juneau", 'Geography') card_2 = Card("What is the square root of 169?", "13", 'STEM') card_3 = Card("What is the power house of the freaking cell?", "Mitochondria", 'STEM') cards = [card_1, card_2, card_3] deck = Deck(cards) assert deck.cards == [card_1, card_2, card_3] assert deck.count() == 3 assert deck.cards_in_category('Geography') == [card_1] assert deck.cards_in_category('STEM') == [card_2, card_3] assert deck.cards_in_category('pop culture') == []
def test_card_attributes(self): card = Card("What is the capital of Alaska?", "Juneau", 'Geography') assert isinstance(card, Card) assert card.question == 'What is the capital of Alaska?' assert card.answer == 'Juneau' assert card.category == 'Geography'
def test_correct_guess(self): card = Card("What is the capital of Alaska?", "Juneau", "Geography") turn = Turn("Juneau", card) self.assertEqual(turn.card, card) self.assertEqual(turn.guess, "Juneau") self.assertTrue(turn.is_correct()) self.assertEqual(turn.feedback(), "Correct!")
def test_it_can_tell_accuracy(self): category_1 = {"category": "Geography"} card_1 = Card("What is the capital of Alaska?", "Juneau", category_1) category_2 = {"category": "Art"} card_2 = Card("Who painted Starry Night?", "Vincent Van Gogh", category_2) category_3 = {"category": "STEM"} card_3 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", category_3) turn_1 = Turn("Juneau", card_1) turn_2 = Turn("Monet", card_2) turn_3 = Turn("Mars", card_3) assert turn_1.correct() == True assert turn_2.correct() == False assert turn_3.correct() == True
def test_add_card(self): self.assertEqual(self.deck.cards, [self.card_1, self.card_2, self.card_3]) self.card4 = Card("Geography", "What is it?", "I don't know!") expected = [self.card_1, self.card_2, self.card_3, self.card4] self.deck.add_card(self.card4) self.assertEqual(self.deck.cards, expected)
def test_turn(self): card = Card("What is the capital of Alaska?", "Juneau", 'Geography') turn = Turn('Juneau', card) assert turn.card == card assert turn.guess == 'Juneau' assert turn.correct() == True assert turn.feedback() == 'Correct!'
def test_it_has_attributes(self): category_1 = {"category": "Geography"} card_1 = Card("What is the capital of Alaska?", "Juneau", category_1) category_2 = {"category": "Art"} card_2 = Card("Who painted Starry Night?", "Vincent Van Gogh", category_2) category_3 = {"category": "STEM"} card_3 = Card( "The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", category_3) turn_1 = Turn("Juneau", card_1) turn_2 = Turn("Monet", card_2) turn_3 = Turn("Mars", card_3) assert turn_1.guess == "Juneau" assert turn_1.card == card_1 assert turn_2.guess == "Monet" assert turn_2.card == card_2 assert turn_3.guess == "Mars" assert turn_3.card == card_3
def _card_bootstrap(session, game_id): # mfw SQLite doesn't support autoinc on composite primary keys :( count = 0 for number in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12): for color in (1, 1, 2, 2, 3, 3, 4, 4): session.add( Card(game_id=game_id, number=number, color=color, pos=count, card_id=count)) count += 1 for x in range(8): session.add(Card(game_id=game_id, wild=True, pos=count, card_id=count)) count += 1 for x in range(4): session.add(Card(game_id=game_id, skip=True, pos=count, card_id=count)) count += 1
def __init__(self): super().__init__() # 초기화 self.setupUi(self) self.UpgradeButton1.setDisabled(True) self.UpgradeButton2.setDisabled(True) self.UpgradeButton3.setDisabled(True) self.UpgradeButton4.setDisabled(True) # 시작버튼을 누를 시 시작 self.check.setText("시작") self.wordInput.setReadOnly(True) self.wordInput.setText("시작버튼을 눌러주세요.") self.check.clicked.connect(self.button_clicked) # 이벤트카드 생성 self.cards = [Card(), Card(), Card(), Card()] self.card_buttons = [self.UpgradeButton1, self.UpgradeButton2, self.UpgradeButton3, self.UpgradeButton4] # 이벤트카드 누를 시 self.UpgradeButton1.clicked.connect(self.action) self.UpgradeButton2.clicked.connect(self.action) self.UpgradeButton3.clicked.connect(self.action) self.UpgradeButton4.clicked.connect(self.action) # 스테이지 설정 self.stage = 1 # 캐릭터 생성 self.hero = Hero() # 타이머 쓰레드 self.timer = AAThread() self.timer.start() # 시그널 슬롯 연결 self.timer.change_value.connect(self.auto_attack) # 단어 퀴즈 self.word_game = WordGame()
def test_defense_when_cant_beat_attack(self): hand = [ Card(Suit.CLUBS, Rank.SEVEN), Card(Suit.HEARTS, Rank.SEVEN), Card(Suit.SPADES, Rank.SEVEN), Card(Suit.HEARTS, Rank.JACK), Card(Suit.CLUBS, Rank.JACK), Card(Suit.SPADES, Rank.JACK) ] game = Game() game.trump = Card(Suit.DIAMONDS, Rank.SIX) game.attack_cards = [Card(Suit.CLUBS, Rank.ACE)] p = AIPlayer(hand=hand, game=game) assert p.defend() == None
def setUp(self): card_one = Card("Heart", "5", 5) card_two = Card("Diamond", "Jack",11) card_three = Card("Spade", "7", 7) card_four = Card("Spade", "Ace", 14) cards = [card_one, card_two, card_three, card_four] self.deck = Deck(cards) self.player1 = Player("John", self.deck) card_five = Card("Heart", "8", 8) card_six = Card("Diamond", "Jack",11) card_seven = Card("Spade", "3", 3) card_eight = Card("Club", "Queen", 12) cards2 = [card_five, card_six, card_seven, card_eight] self.deck2 = Deck(cards2) self.player2 = Player("John", self.deck2) self.turn = Turn(self.player1, self.player2)
def update(strings, names, order, maxlen, asc_order=False, is_karsten=False): os.system('cls') for string in strings: print("> %s" % string) print("") largeset = set() for nameset in names: if len(nameset) == maxlen: continue for name in nameset: largeset.add(Card(name, order[name], is_karsten)) cardset = sorted(largeset) cardset = cardset if asc_order else cardset[::-1] for name in cardset: print(name)
def test_attack_with_all_cards_with_lowest_value(self): hand = [ Card(Suit.CLUBS, Rank.SEVEN), Card(Suit.HEARTS, Rank.SEVEN), Card(Suit.SPADES, Rank.SEVEN), Card(Suit.HEARTS, Rank.JACK), Card(Suit.CLUBS, Rank.JACK), Card(Suit.SPADES, Rank.JACK) ] game = Game() game.trump = Card(Suit.SPADES, Rank.SIX) p = AIPlayer(hand=hand, game=game) attack = p.attack() assert len(attack) == 2 assert attack[0].rank == attack[1].rank == Rank.SEVEN assert len(p.hand) == 4
def test_it_exists(self): category = {"category": "Geography"} card = Card("What is the capital of Alaska?", "Juneau", category) assert isinstance(card, Card)
def test_add_card(self): new_card = Card("Heart", "King", 13) self.deck.add_card(new_card) assert len(self.deck.cards) == 5
def __init__(self, file): self.file = open(file, "r") self.cards = [] for line in self.file: card = line.split(",") self.cards.append(Card(card[0], card[1], card[2]))
def test_attributes(self): card = Card("What is the capital of Alaska?", "Juneau", "Geography") self.assertEqual(card.question, "What is the capital of Alaska?") self.assertEqual(card.answer, "Juneau") self.assertEqual(card.category, "Geography")
def test_it_exists(self): card = Card("What is the capital of Alaska?", "Juneau", "Geography") self.assertIsInstance(card, Card)