Commits

Christoph Schindler committed 3b3a721

15. Dojo: Tennis

Comments (0)

Files changed (3)

+[nosy]
+base_path = ./
+glob_pattern = *.py
+extra_paths = setup.cfg
+options = --stop --with-yanc
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+tennis.py
+
+Created by Coding Dojo on 2013-11-20.
+Copyright (c) 2013 PyUGAT. All rights reserved.
+"""
+
+class Match(object):
+    
+    def __init__(self, a=0, b=0):
+        self.a = a
+        self.b = b
+        self.score_map = ("Love", "Fifteen", "Thirty", "Forty")
+        self.players = ["Player 1", "Player 2"]
+    
+    def score(self):
+        if self.a >= 3 and self.b >= 3:
+            if self.a == self.b:
+                return "Deuce"
+            else:
+                return "Advantage {}".format(self.players[self.a < self.b])
+
+        return "{} - {}".format(self.score_map[self.a],
+                                self.score_map[self.b])
+            
+    def winplayer1(self):
+        self.a += 1
+     
+    def winplayer2(self):
+        self.b += 1

Tennis/test_tennis.py

+#!/usr/bin/env python
+# encoding: utf-8
+"""
+test_tennis.py
+
+Created by Coding Dojo on 2013-05-21.
+Copyright (c) 2013 PyUGAT. All rights reserved.
+"""
+
+from nose.tools import *
+
+import tennis
+    
+def test_foo():
+    
+    match = tennis.Match()
+    assert match.a == match.b == 0
+
+def test_score_0_0():
+    match = tennis.Match()
+    assert_equal(match.score(), "Love - Love")
+
+def test_score_15_love():
+    match = tennis.Match()
+    match.winplayer1()
+    assert match.score() == "Fifteen - Love"
+
+def test_15_15():
+    match = tennis.Match()
+    match.winplayer1()
+    match.winplayer2()
+    assert_equal(match.score(), "Fifteen - Fifteen")
+    
+def test_30_40():
+    match = tennis.Match(2, 3)
+    assert_equal(match.score(), "Thirty - Forty")
+    
+def test_deuce():
+    match = tennis.Match(3, 3)
+    assert_equal(match.score(), "Deuce")
+    
+def test_advantage():
+    match = tennis.Match(4, 3)
+    assert_equal(match.score(), "Advantage Player 1")
+    
+def test_disadvantage():
+    match = tennis.Match(3, 4)
+    assert_equal(match.score(), "Advantage Player 2")
+