Commits

Christoph Schindler committed 887f94a

Ergebnis der zweiten Dojo-Session.

  • Participants
  • Parent commits 4394a6c

Comments (0)

Files changed (2)

File Bowling/bowling.py

+class Frame(object):
+    def __init__(self, roll_char):
+        self.roll_char = roll_char
+
+    def __str__(self):
+        return self.roll_char
+
+    def __eq__(self, other):
+        return self.roll_char == other.roll_char
+
+    def score(self, next1, next2):
+        pass
+        #return sum(map(parse_int, self.roll_char))
+
+    @classmethod
+    def parse_int(cls, char):
+        if char == "X":
+            return 10
+    
+def parse_input(rolls):
+
+    frames = []
+    
+    skip = False
+    for i in range(len(rolls)):
+        if not skip:
+            roll = rolls[i]
+            if roll == "X":
+                frames.append(Frame(roll))
+            else:
+                frames.append(Frame(roll+rolls[i+1]))
+                skip = True
+        else:
+            skip = False
+    
+    return frames
+    
+def parse_roll(roll):
+
+    return Frame(roll)
+
+
+
+
+
+
+

File Bowling/test.py

+import unittest
+import textwrap
+
+import bowling
+
+class TestBowling(unittest.TestCase):
+    def test_parse_input(self):
+        self.assertEqual(bowling.parse_input("X" * 12), [bowling.Frame("X")] *12)
+
+    def test_parse_roll(self):
+        self.assertEqual(bowling.parse_roll("9-"), bowling.Frame("9-"))
+        self.assertEqual(bowling.parse_roll("X"), bowling.Frame("X"))
+
+    def test_parse_miss(self):
+        self.assertEqual(bowling.parse_input("9-9-9-9-9-9-9-9-9-9-"), [bowling.Frame("9-")]*10)
+
+class TestFrame(unittest.TestCase):
+    def test_parse_int(self):
+        self.assertEqual(bowling.Frame.parse_int("X"), 10)
+    
+    def test_score(self):
+        
+#        5/
+#        10
+#        
+#        5/ 7-
+#        17 24
+#        
+#        5/ 7- X  9/ 2-
+#        17 24 54 56 58
+#    
+#       X  X  X  X   X   X   7-
+#                    34  17  7
+#
+#        30 60 90 120 147 164 171
+        
+#        self.assertEqual(bowling.Frame('X').score(carry=1), 20)
+#        self.assertEqual(bowling.Frame('5/').score(carry=1), 15)
+        
+        self.assertEqual(bowling.Frame('5-').score(None, None), 5)
+#        self.assertEqual(bowling.Frame('5/').score(carry=0), 10)
+        
+        
+        
+        
+        
+        
+        
+