# Commits

committed ba8735d

fix: grouping_cards

• Participants
• Branches default

# File poker.py

# 引数: 手札のリスト(cards)
# 返り値: 手札をグルーピングした辞書: card_dict
# テスト: 辞書のvalueの合計が5になる事
-# 変数: num_of_cards
+# 変数: valueを合計する num_of_cards
#
def grouping_cards(cards):
card_dict = {}
card_dict[card] += 1
else:
card_dict[card] = 1
+    return card_dict

def is_one_pair(cards):

# File test_poker.py

fullhouse = [13,13,1,1,13]
self.assertEqual(False, is_one_pair(fullhouse))

+        straight_a2k = [1,13,12,11,10]
+        self.assertEqual(False, is_one_pair(straight_a2k ))
+
+        normal_straight = [1,13,12,11,10]
+        self.assertEqual(False, is_one_pair(normal_straight ))
+
+        non_straight = [12,13,1,2,3]
+        self.assertEqual(False, is_one_pair(non_straight))
+
def test_is_two_pair(self):

no_pair = [13,9,10,11,12]
four_cards = [13,13,13,13,12]
self.assertEqual(False, is_two_pair(four_cards))

+        straight_a2k = [1,13,12,11,10]
+        self.assertEqual(False, is_two_pair(straight_a2k ))

-    def test_grouping_cards(cards):
-        #
-        #no_pair = [9,10,11,12,13]
-        #self.assertEqual(dict, type(grouping_cards(no_pair)))
+        normal_straight = [1,13,12,11,10]
+        self.assertEqual(False, is_two_pair(normal_straight ))

-        num_of_cards = 0
-        for values card_dict.values():
-            num_of_cards += values
+        non_straight = [12,13,1,2,3]
+        self.assertEqual(False, is_two_pair(non_straight))
+
+
+    def test_grouping_cards(self):
+
+        def count_cards(card_dict):
+            num_of_cards = 0
+            for values in card_dict.values():
+                num_of_cards += values
+            return num_of_cards

no_pair = [9,10,11,12,13]
-        self.assertEqual(5, grouping_cards(no_pair))
+        val = grouping_cards(no_pair)
+        self.assertEqual(5, count_cards(val))
+        self.assertEqual(1, val[13])

-        one_pair = [13,9,13,11,12]
-        self.assertEqual(5, grouping_cards(one_pair))
+        #one_pair = [13,9,13,11,12]
+        #self.assertEqual(5, grouping_cards(one_pair))
+        #self.assertEqual(2, val[13])

-        two_pair = [13,13,10,11,10]
-        self.assertEqual(5, grouping_cards(two_pair))
+        #two_pair = [13,13,10,11,10]
+        #self.assertEqual(5, grouping_cards(two_pair))

-        three_cards = [13,13,13,11,12]
-        self.assertEqual(5, grouping_cards(three_cards))
+        #three_cards = [13,13,13,11,12]
+        #self.assertEqual(5, grouping_cards(three_cards))

-        four_cards = [13,13,13,13,12]
-        self.assertEqual(5, grouping_cards(four_cards))
+        #four_cards = [13,13,13,13,12]
+        #self.assertEqual(5, grouping_cards(four_cards))

if __name__ == '__main__':
unittest.main()

-
-
-
-
-
-