Skip to content

Instantly share code, notes, and snippets.

@FranckSilvestre
Created January 21, 2018 09:21
Show Gist options
  • Save FranckSilvestre/98b2bc192a87ebc98791926ee05ca11b to your computer and use it in GitHub Desktop.
Save FranckSilvestre/98b2bc192a87ebc98791926ee05ca11b to your computer and use it in GitHub Desktop.
Tests du calcul du score d'une partie de bowling avec framework de tests
import unittest
import Bowling
class TestBowlingWithUnittest(unittest.TestCase):
def setUp(self):
self.strike = (10, 0)
self.spare_0_10 = (0, 10)
self.spare_5_5 = (5, 5)
self.jeu_nominal_5_0 = (5, 0)
def test_jeu_est_un_strike(self):
self.assertTrue(Bowling.jeu_est_un_strike(self.strike), "Ce jeu est bien un strike !")
self.assertFalse(Bowling.jeu_est_un_strike(self.spare_0_10), "Ce jeu n'est pas un strike !")
self.assertFalse(Bowling.jeu_est_un_strike(self.spare_5_5), "Ce jeu n'est pas un strike !")
self.assertFalse(Bowling.jeu_est_un_strike(self.jeu_nominal_5_0), "Ce jeu n'est pas un strike !")
def test_jeu_est_un_spare(self):
self.assertFalse(Bowling.jeu_est_un_spare(self.strike), "Ce jeu n'est pas un spare !")
self.assertTrue(Bowling.jeu_est_un_spare(self.spare_0_10), "Ce jeu est bien un spare !")
self.assertTrue(Bowling.jeu_est_un_spare(self.spare_5_5), "Ce jeu est bien un spare !")
self.assertFalse(Bowling.jeu_est_un_spare(self.jeu_nominal_5_0), "Ce jeu n'est pas un spare !")
def test_calcule_score_cas_nominal(self):
liste_jeux_nominaux = [self.jeu_nominal_5_0] * 10
self.assertEqual(50,Bowling.calcule_score_partie(liste_jeux_nominaux),"Score devrait valoir 50")
def test_calcule_score_cas_spares_seulement(self):
liste_spares = [self.spare_5_5] * 10 + [(5, 0)]
self.assertEqual(150,Bowling.calcule_score_partie(liste_spares), "Score devrait valoir 150")
def test_calcule_score_cas_strikes_seulement(self):
liste_strikes = [self.strike] * 10 + [(10, 10)]
self.assertEqual(300,Bowling.calcule_score_partie(liste_strikes), "Score devrait valoir 300")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment