From b47b88f811727fe69f6d3e7c098cb196b527b7d5 Mon Sep 17 00:00:00 2001 From: Fabiano Engler Neto Date: Fri, 12 Jan 2018 02:19:29 -0200 Subject: [PATCH 1/4] Added BDD tests for romanos_20170111 --- .../convert_roman_numbers_to_decimal.feature | 29 +++++++++++++++++++ romanos_20170111/features/steps/roman.py | 13 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 romanos_20170111/features/convert_roman_numbers_to_decimal.feature create mode 100644 romanos_20170111/features/steps/roman.py diff --git a/romanos_20170111/features/convert_roman_numbers_to_decimal.feature b/romanos_20170111/features/convert_roman_numbers_to_decimal.feature new file mode 100644 index 0000000..ecc4e8a --- /dev/null +++ b/romanos_20170111/features/convert_roman_numbers_to_decimal.feature @@ -0,0 +1,29 @@ +Feature: Convert roman number to decimal + + Scenario Outline: Enter a roman number and see it in decimal + When I enter the roman number + Then it should show me the decimal number + + Examples: number in roman and decimal + | roman_number | decimal_number | + | I | 1 | + | V | 5 | + | X | 10 | + | L | 50 | + | C | 100 | + | D | 500 | + | M | 1000 | + | II | 2 | + | III | 3 | + | XX | 20 | + | VI | 6 | + | VII | 7 | + | VIII | 8 | + | IV | 4 | + | IX | 9 | + | IL | 49 | + | MDXC | 1590 | + | MCMLXXXIV | 1984 | + | LII | 52 | + + diff --git a/romanos_20170111/features/steps/roman.py b/romanos_20170111/features/steps/roman.py new file mode 100644 index 0000000..a9d392d --- /dev/null +++ b/romanos_20170111/features/steps/roman.py @@ -0,0 +1,13 @@ +from romanos import romanos + + +@when('I enter the roman number {roman_number}') +def step_impl(context, roman_number): + context.decimal_result = romanos(roman_number) + + +@then('it should show me the decimal number {decimal_number:d}') +def step_impl(context, decimal_number): + assert context.decimal_result == decimal_number + + From e28123f70fe220507f6eb6483db695b046093415 Mon Sep 17 00:00:00 2001 From: Fabiano Engler Neto Date: Fri, 12 Jan 2018 02:36:00 -0200 Subject: [PATCH 2/4] Added instructions to README on how to run tests --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ requirements_dev.txt | 4 ++++ 2 files changed, 45 insertions(+) create mode 100644 requirements_dev.txt diff --git a/README.md b/README.md index c3f5d5e..9e85d57 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,44 @@ # dojo Grupy-PR Respositório contendo o código das sessões de dojo do Grupy-PR. + + +## Testes Unit Test e BDD + +A sessões do dojo são feitas com a metodologia TDD e códigos de teste +escritos em [unittest](https://docs.python.org/3/library/unittest.html). + +Alguns testes foram escritos também em BDD com [behave](http://python-behave.readthedocs.io). + + + +### Unit Test + +Para executar os testes em Unit Test, basta rodar os arquivos test_*.py + +Exemplo: + + $ cd romanos_20170111 + $ python test_romanos.py + + +### BDD + +Para executar os teste em BDD, é necessário instalar o behave primeiro: + + $ pip install behave + + +Depois basta rodar o comando behave. Exemplo: + + $ cd romanos_20170111 + $ behave + + +A saída do behave é mais extensa por padrão, cada passo de cada cenário é impresso. Se preferir uma saída mais compacta, parecida com a do unittest, com um ponto para cada cenário, pode rodar: + + $ behave --format progress + + + + diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..4dcf796 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +behave==1.2.5 +parse==1.8.2 +parse-type==0.4.2 +six==1.11.0 From 09f9d7ab88bf0a58ff637987dbeb665f6ef591d2 Mon Sep 17 00:00:00 2001 From: Fabiano Engler Neto Date: Fri, 12 Jan 2018 03:26:16 -0200 Subject: [PATCH 3/4] Added BDD tests to jokenpo_20171214 --- .../features/play_jokenpo.feature | 39 ++++++++++++++++ .../features/steps/jokenpo_steps.py | 44 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 jokenpo_20171214/features/play_jokenpo.feature create mode 100644 jokenpo_20171214/features/steps/jokenpo_steps.py diff --git a/jokenpo_20171214/features/play_jokenpo.feature b/jokenpo_20171214/features/play_jokenpo.feature new file mode 100644 index 0000000..c57e6f6 --- /dev/null +++ b/jokenpo_20171214/features/play_jokenpo.feature @@ -0,0 +1,39 @@ +Feature: Play Jokenpo game + + Scenario Outline: See who is the winner from two hands of play + When one player chooses + And the other player chooses + And players show their hands + Then the winner hand should be + + Examples: players hands and winner + | player1_hand | player2_hand | winner | + | pedra | pedra | EMPATE | + | pedra | tesoura | PEDRA | + | pedra | papel | PAPEL | + | tesoura | papel | TESOURA | + | tesoura | pedra | PEDRA | + | tesoura | tesoura | EMPATE | + | papel | papel | EMPATE | + | papel | pedra | PAPEL | + | papel | tesoura | TESOURA | + | Papel | pedra | PAPEL | + | papel | Pedra | PAPEL | + + + Scenario Outline: Try to play with invalid hands + When one player chooses + And the other player chooses + And players show their hands + Then we should get and error + + Examples: invalid players hands + | player1_hand | player2_hand | + | preda | preda | + | tezoura | preda | + | preda | tesoura | + | 1 | pedra | + | pedra | 1 | + | None | pedra | + | pedra | None | + diff --git a/jokenpo_20171214/features/steps/jokenpo_steps.py b/jokenpo_20171214/features/steps/jokenpo_steps.py new file mode 100644 index 0000000..d7327d4 --- /dev/null +++ b/jokenpo_20171214/features/steps/jokenpo_steps.py @@ -0,0 +1,44 @@ +from jokenpo import jokenpo, JogadaInvalidaError + + +@when('one player chooses None') +def step_impl(context): + context.hand_player1 = None + + +@when('one player chooses {hand:d}') +def step_impl(context, hand): + context.hand_player1 = hand + + +@when('one player chooses {hand}') +def step_impl(context, hand): + context.hand_player1 = hand + + +@when('the other player chooses {hand}') +def step_impl(context, hand): + context.hand_player2 = hand + + +@then('the winner hand should be {winner}') +def step_impl(context, winner): + assert context.exception is None + assert context.result == winner + + +@when('players show their hands') +def step_impl(context): + context.exception = None + try: + context.result = jokenpo(context.hand_player1, context.hand_player2) + except Exception as e: + context.exception = e + + +@then('we should get and error') +def step_impl(context): + assert isinstance(context.exception, JogadaInvalidaError) + + + From 12e3f34961a5bfe3a14d36a56456ae246271d855 Mon Sep 17 00:00:00 2001 From: Fabiano Engler Neto Date: Fri, 12 Jan 2018 04:18:00 -0200 Subject: [PATCH 4/4] Added BDD tests to fizzbuzz_20171116 --- .../features/play_fizzbuzz_game.feature | 46 +++++++++++++++++++ .../features/steps/fizzbuzz_steps.py | 43 +++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 fizzbuzz_20171116/features/play_fizzbuzz_game.feature create mode 100644 fizzbuzz_20171116/features/steps/fizzbuzz_steps.py diff --git a/fizzbuzz_20171116/features/play_fizzbuzz_game.feature b/fizzbuzz_20171116/features/play_fizzbuzz_game.feature new file mode 100644 index 0000000..b0bf113 --- /dev/null +++ b/fizzbuzz_20171116/features/play_fizzbuzz_game.feature @@ -0,0 +1,46 @@ +Feature: Play FizzBuzz game + Fizz buzz is a group word game for children to teach them about division [1]. + Players take turns to count incrementally, replacing any number divisible + by three with the word "fizz", and any number divisible by five with the + word "buzz". Numbers divisible by both become "fizzbuzz". + [1] https://en.wikipedia.org/wiki/Fizz_buzz + + + Scenario Outline: Function fizzbuzz should return correclty for each number input + When I choose number + And call the function + Then it should return + + Examples: + | number | fizzbuzz | + | 1 | 1 | + | 2 | 2 | + | 3 | 'fizz' | + | 4 | 4 | + | 5 | 'buzz' | + | 6 | 'fizz' | + | 7 | 7 | + | 9 | 'fizz' | + | 10 | 'buzz' | + | 15 | 'fizzbuzz' | + + + Scenario Outline: Method to_fizzbuzz from object Fizzbuzz should return correclty + When I choose number + And create a FizzBuzzInt object for the number + And call the method to_fizzbuzz + Then it should return + And its repr() should match repr() + + Examples: + | number | fizzbuzz | + | 1 | 1 | + | 2 | 2 | + | 3 | 'fizz' | + | 4 | 4 | + | 5 | 'buzz' | + | 6 | 'fizz' | + | 7 | 7 | + | 9 | 'fizz' | + | 10 | 'buzz' | + | 15 | 'fizzbuzz' | diff --git a/fizzbuzz_20171116/features/steps/fizzbuzz_steps.py b/fizzbuzz_20171116/features/steps/fizzbuzz_steps.py new file mode 100644 index 0000000..cfed849 --- /dev/null +++ b/fizzbuzz_20171116/features/steps/fizzbuzz_steps.py @@ -0,0 +1,43 @@ +from fizzbuzz import fizzbuzz, FizzBuzzInt + + +@when('I choose number {number:d}') +def step_impl(context, number): + context.number = number + + +@when('call the function') +def step_impl(context): + context.result = fizzbuzz(context.number) + + +@then('it should return {number:d}') +def step_impl(context, number): + assert context.result == number + + +@then('it should return \'{fizzbuzz_text}\'') +def step_impl(context, fizzbuzz_text): + assert context.result == fizzbuzz_text + + +@when('create a FizzBuzzInt object for the number') +def step_impl(context): + context.obj = FizzBuzzInt(context.number) + + +@when('call the method to_fizzbuzz') +def step_impl(context): + context.result = context.obj.to_fizzbuzz() + + +@then('its repr() should match repr({number:d})') +def step_impl(context, number): + assert repr(context.result) == repr(number) + + +@then('its repr() should match repr(\'{fizzbuzz_text}\')') +def step_impl(context, fizzbuzz_text): + assert repr(context.result) == repr(fizzbuzz_text) + +