def test_small_straight(): ### Si la tirada de los dados es 1,2,3,4,5 signicará escalera pequeña y el jugador obtendrá 15 puntos ### assert 15 == Yatzy.small_straight(1, 2, 3, 4, 5) assert 0 == Yatzy.small_straight(2, 3, 4, 5, 6) assert 0 == Yatzy.small_straight(1, 3, 4, 5, 5) assert 0 == Yatzy.small_straight(6, 6, 6, 6, 6) assert 0 == Yatzy.small_straight(1, 2, 3, 4, 6)
def test_large_straight(): ### Si la tirada de los dados es 2,3,4,5,6 signicará escalera grande y el jugador obtendrá 20 puntos ### assert 20 == Yatzy.large_straight(2, 3, 4, 5, 6) assert 0 == Yatzy.large_straight(1, 2, 3, 4, 5) assert 0 == Yatzy.large_straight(1, 3, 4, 5, 5) assert 0 == Yatzy.large_straight(6, 6, 6, 6, 6) assert 0 == Yatzy.large_straight(1, 2, 3, 4, 6)
def test_two_pairs(): ### Suma dos parejas ### assert 8 == Yatzy.two_pairs(1, 1, 2, 3, 3) assert 0 == Yatzy.two_pairs(1, 1, 2, 3, 4) assert 6 == Yatzy.two_pairs(1, 1, 2, 2, 2) assert 0 == Yatzy.two_pairs(1, 2, 3, 4, 5)
def test_pair(): ### Se le ha cambiado el nómbre del método de score_pair a pair, consiste en la suma de una pareja, #### #### en caso de dos parejas se le sumará la más alta #### assert 8 == Yatzy.pair(3, 3, 3, 4, 4) assert 12 == Yatzy.pair(1, 1, 6, 2, 6) assert 6 == Yatzy.pair(3, 3, 3, 4, 1) assert 6 == Yatzy.pair(3, 3, 3, 3, 1) assert 0 == Yatzy.pair(1, 2, 3, 4, 5)
def test_chance(): ''' Chance The player scores the sum of all dice, no matter what they read. ''' # iterar sobre *args evita codigo cableado a 5 argumentos assert 15 == Yatzy.chance(1, 2, 3, 4, 5) assert 14 == Yatzy.chance(1, 1, 3, 3, 6) assert 21 == Yatzy.chance(4, 5, 5, 6, 1)
def test_fours(): dice = Yatzy(1, 4, 3, 4, 5) assert dice.fours() == 8, "fallo en función fours, primer assert" dice = Yatzy(1, 4, 4, 6, 4) assert dice.fours() == 12, "fallo en función fours, segundo assert" dice = Yatzy(1, 2, 3, 5, 6) assert dice.fours() == 0, "fallo en función fours , tercer assert"
def test_fives(): dice = Yatzy(1, 4, 3, 4, 5) assert dice.fives() == 5, "fallo en función fives, primer assert" dice = Yatzy(1, 4, 4, 6, 4) assert dice.fives() == 0, "fallo en función fives, segundo assert" dice = Yatzy(5, 5, 3, 5, 6) assert dice.fives() == 15, "fallo en función fives, tercer assert"
def test_sixes(): dice = Yatzy(1, 6, 3, 6, 5) assert dice.sixes() == 12, "fallo en función sixes, primer assert" dice = Yatzy(1, 4, 4, 3, 4) assert dice.sixes() == 0, "fallo en función sixes, segundo assert" dice = Yatzy(5, 5, 3, 5, 6) assert dice.sixes() == 6, "fallo en función sixes, tercer assert"
def test_yatzy(): ''' Yatzy If all dice have the same number, the player scores 50 points. ''' # dice significa "dados" pero exige un unico argumento # => interfaz abstraccion del metodo no es coherente # con el resto de metodos # El codigo para iterar sobre dice es muy complejo # El algoritmo para averiguar si todos los dados son iguales # es muy complejo assert 50 == Yatzy.yatzy(1, 1, 1, 1, 1) assert 0 == Yatzy.yatzy(1, 1, 1, 2, 1)
def test_pair(): ''' Pair: The player scores the sum of the two highest matching dice. ''' # El algoritmo del metodo no es optimo, es complicado e ilegible. # La abstraccion, el nombre del metodo, no es adecuada # puesto que la categoria se llama pair. assert 8 == Yatzy.score_pair(3, 3, 3, 4, 4) assert 12 == Yatzy.score_pair(1, 1, 6, 2, 6) assert 6 == Yatzy.score_pair(3, 3, 3, 4, 1) assert 6 == Yatzy.score_pair(3, 3, 3, 3, 1) assert 0 == Yatzy.score_pair(1, 2, 3, 4, 5)
def test_pair(): assert 6 == Yatzy.pair(3, 4, 3, 5, 6) assert 10 == Yatzy.pair(5, 3, 3, 3, 5) assert 12 == Yatzy.pair(5, 3, 6, 6, 5) assert 12 == Yatzy.pair(5, 3, 6, 6, 6) assert 8 == Yatzy.pair(3, 3, 3, 4, 4) assert 12 == Yatzy.pair(1, 1, 6, 2, 6) assert 6 == Yatzy.pair(3, 3, 3, 4, 1) assert 6 == Yatzy.pair(3, 3, 3, 3, 1) assert 2 == Yatzy.pair(1, 1, 3, 4, 5)
def test_two_pairs(): ''' Two pairs: If there are two pairs of dice with the same number, the player scores the sum of these dice. ''' # La categoria se llama "two pairs": la abstraccion del metodo # no es adecuada. # Mantengo notacion snake_case # El algoritmo del metodo no es optimo, es complicado e ilegible. assert 8 == Yatzy.score_two_pairs(1, 1, 2, 3, 3) assert 0 == Yatzy.score_two_pairs(1, 1, 2, 3, 4) assert 6 == Yatzy.score_two_pairs(1, 1, 2, 2, 2) assert 0 == Yatzy.score_two_pairs(1, 2, 3, 4, 5)
def test_fullHouse(): assert Yatzy.fullHouse(6, 2, 2, 2, 6) == 18 assert Yatzy.fullHouse(2, 3, 4, 5, 6) == 0 assert Yatzy.fullHouse(6, 2, 1, 2, 6) == 0 assert Yatzy.fullHouse(6, 2, 6, 1, 6) == 0 assert Yatzy.fullHouse(6, 6, 2, 2, 2) == 18 assert Yatzy.fullHouse(6, 6, 6, 2, 2) == 22 assert Yatzy.fullHouse(1, 2, 3, 1, 6) == 0
def test_pair(): assert 8 == Yatzy.pair(3,3,3,4,4) assert 12 == Yatzy.pair(1,1,6,2,6) assert 6 == Yatzy.pair(3,3,3,4,1) assert 6 == Yatzy.pair(3,3,3,3,1) assert 4 == Yatzy.pair(2,2,2,2,2) assert 0 == Yatzy.pair(1,2,3,4,5)
def test_four_of_a_knd(): assert 12 == Yatzy.four_of_a_kind(3, 3, 3, 3, 5) assert 20 == Yatzy.four_of_a_kind(5, 5, 5, 4, 5) assert 12 == Yatzy.four_of_a_kind(3, 3, 3, 3, 3) assert 0 == Yatzy.four_of_a_kind(3, 3, 3, 2, 1)
def test_one_pair(): assert 6 == Yatzy.score_pair(3, 4, 3, 5, 6) assert 10 == Yatzy.score_pair(5, 3, 3, 3, 5) assert 12 == Yatzy.score_pair(5, 3, 6, 6, 5)
def test_two_Pair(): assert 16 == Yatzy.two_pair(3, 3, 5, 4, 5) assert 18 == Yatzy.two_pair(3, 3, 6, 6, 6) assert 0 == Yatzy.two_pair(3, 3, 6, 5, 4)
def test_threes(): assert 6 == Yatzy.threes(1, 2, 3, 2, 3) assert 12 == Yatzy.threes(2, 3, 3, 3, 3)
def test_fives(): assert 10 == Yatzy(4, 4, 4, 5, 5).fives() assert 15 == Yatzy(4, 4, 5, 5, 5).fives() assert 20 == Yatzy(4, 5, 5, 5, 5).fives()
def test_1s(): assert Yatzy.ones(1, 2, 3, 4, 5) == 1 assert 2 == Yatzy.ones(1, 2, 1, 4, 5) assert 0 == Yatzy.ones(6, 2, 2, 4, 5) assert 4 == Yatzy.ones(1, 2, 1, 1, 1)
def test_chance_scores_sum_of_all_dice(): assert Yatzy.chance(2, 3, 4, 5, 1) == 15 assert Yatzy.chance(3, 3, 4, 5, 1) == 16
def test_smallStraight(): assert 15 == Yatzy.smallStraight(1, 2, 3, 4, 5) assert 15 == Yatzy.smallStraight(2, 3, 4, 5, 1) assert 0 == Yatzy.smallStraight(1, 2, 2, 4, 5)
def test_largeStraight(): assert 20 == Yatzy.largeStraight(6, 2, 3, 4, 5) assert 20 == Yatzy.largeStraight(2, 3, 4, 5, 6) assert 0 == Yatzy.largeStraight(1, 2, 2, 4, 5)
def test_fullHouse(): assert 18 == Yatzy.fullHouse(6, 2, 2, 2, 6) assert 0 == Yatzy.fullHouse(2, 3, 4, 5, 6)
def test_2s(): assert 4 == Yatzy.twos(1, 2, 3, 2, 6) assert 10 == Yatzy.twos(2, 2, 2, 2, 2)
def test_yatzy_scores_50(): expected = 50 actual = Yatzy.yatzy([4, 4, 4, 4, 4]) assert expected == actual assert 50 == Yatzy.yatzy([6, 6, 6, 6, 6]) assert 0 == Yatzy.yatzy([6, 6, 6, 6, 3])
def test_largeStraight(): assert 40 == Yatzy.largeStraight(6, 2, 3, 4, 5) assert 40 == Yatzy.largeStraight(2, 3, 4, 5, 6) assert 0 == Yatzy.largeStraight(1, 2, 2, 4, 5)
def test_fours_test(): assert 12 == Yatzy(4, 4, 4, 5, 5).fours() assert 8 == Yatzy(4, 4, 5, 5, 5).fours() assert 4 == Yatzy(4, 5, 5, 5, 5).fours()
def test_sixes_test(): assert 0 == Yatzy(4, 4, 4, 5, 5).sixes() assert 6 == Yatzy(4, 4, 6, 5, 5).sixes() assert 18 == Yatzy(6, 5, 6, 6, 5).sixes()
def test_chance_scores_sum_of_all_dice(): expected = 15 actual = Yatzy.chance(2, 3, 4, 5, 1) assert expected == actual assert 16 == Yatzy.chance(3, 3, 4, 5, 1)
def test_three_of_a_kind(): assert 9 == Yatzy.three_of_a_kind(3, 3, 3, 4, 5) assert 15 == Yatzy.three_of_a_kind(5, 3, 5, 4, 5) assert 9 == Yatzy.three_of_a_kind(3, 3, 3, 3, 5)
def test_smallStraight(): assert 30 == Yatzy.smallStraight(1, 2, 3, 4, 5) assert 30 == Yatzy.smallStraight(2, 3, 4, 5, 1) assert 0 == Yatzy.smallStraight(1, 2, 2, 4, 5)
def test_fullHouse(): assert 25 == Yatzy.fullHouse(6, 2, 2, 2, 6) assert 0 == Yatzy.fullHouse(2, 3, 4, 5, 6)
def test_chance(): # iterar sobre *args evita codigo cableado a 5 argumentos assert 15 == Yatzy.chance(1, 2, 3, 4, 5) assert 14 == Yatzy.chance(1, 1, 3, 3, 6) assert 21 == Yatzy.chance(4, 5, 5, 6, 1)