Source

PythonDojo / BowlingWithAVengeance / test.py

from nose.tools import assert_equal

import bowling

def test_parse_strike():
    assert_equal(bowling.parse_roll("X"),bowling.STRIKE)
    
def test_parse_spare():
    assert_equal(bowling.parse_roll("/"),bowling.SPARE)
    
def test_simple_frame():
    assert_equal(bowling.frame_score((3,2)), 5)
    
def test_simple_frame_2():
    assert_equal(bowling.frame_score((9,0)), 9)
    
def test_strike():
    assert_equal(bowling.frame_score((10,)), 10)
    
def test_get_score():
    assert_equal(bowling.get_score(((3,2), (4,5))), 14)

def test_get_score_2():
    assert_equal(bowling.get_score(((3,5), (4,5))), 17)
    
def test_get_score_3():
    assert_equal(bowling.get_score(((10,), (3,5))), 26)
    
def test_get_score_4():
    assert_equal(bowling.get_score(((10,), (10,), (5,4))), 25+19+9)
    
def test_get_score_5():
    assert_equal(bowling.get_score(((10,), (10,), (2,4))), 22+16+6)
    
def test_get_score_three_strikes():
    assert_equal(bowling.get_score(((10,), (10,), (10,), (2,4))), 30+22+16+6)
    
def test_spare():
    assert_equal(bowling.get_score(((1, 9), (2, 4))), 18)
        
def test_spare_2():
    assert_equal(bowling.get_score(((1, 9), (3, 4))), 20)
    
def test_perfect_game():
    assert_equal(bowling.get_score([(10,)] * 12), 300) 
    
def test_only_nines():
    assert_equal(bowling.get_score([(9,0)] * 10), 90)
        
def test_game_with_spares():
    assert_equal(bowling.get_score([(5,5)] * 10 + [(5,)]), 150)
    
def test_game_almostperfetc():
    assert_equal(bowling.get_score([(10,)] * 10 + [(3,7)]), 283)