diff --git a/exercises/21-factorial/README.es.md b/exercises/21-factorial/README.es.md index c1391272..f72157ab 100644 --- a/exercises/21-factorial/README.es.md +++ b/exercises/21-factorial/README.es.md @@ -2,14 +2,15 @@ ## 📝 Instrucciones -Escribe un programa que puede calcular el factorial de un número dado. -Los resultados deberían imprimirse en una secuencia separada por coma en una sola línea. Supongamos que se le entrega la siguiente entrada al programa: +1. Crea una función llamada `factorial`, que reciba un número como parámatro y retorne su valor factorial. + +## Ejemplo de entrada: ```bash -8 +factorial(8) ``` -Entonces el resultado debería ser: +## Ejemplo de salida: ```bash 40320 @@ -17,4 +18,4 @@ Entonces el resultado debería ser: ## 💡 Pistas: -En el caso de una entrada de datos entregada a la cuestión, debería asumirse como una entrada de la consola. ++ Si no sabes qué es un factorial, revisa la información de este link: https://factorial.mx/numero-funcion-factorial diff --git a/exercises/21-factorial/README.md b/exercises/21-factorial/README.md index 5847c798..e5224c90 100644 --- a/exercises/21-factorial/README.md +++ b/exercises/21-factorial/README.md @@ -1,21 +1,21 @@ # `21` Factorial -## 📝 Instructions +## 📝 Instructions: -Write a program which can compute the factorial of a given numbers. -The results should be printed in a comma-separated sequence on a single line. -Suppose the following input is supplied to the program: +1. Create a function named `factorial` which receives a number as parameter and returns the factorial of the given numbers. + +## Example input: ```bash -8 +factorial(8) ``` -Then, the output should be: +## Example output: ```bash 40320 ``` -## 💡Hints: +## 💡 Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file ++ If you don't know what a factorial is, you can check it out on this link: https://www.cuemath.com/numbers/factorial/ diff --git a/exercises/21-factorial/app.py b/exercises/21-factorial/app.py index e666e544..fce62c1d 100644 --- a/exercises/21-factorial/app.py +++ b/exercises/21-factorial/app.py @@ -1 +1 @@ -# Your code here \ No newline at end of file +# Your code here diff --git a/exercises/21-factorial/test.py b/exercises/21-factorial/test.py new file mode 100644 index 00000000..1852dcb4 --- /dev/null +++ b/exercises/21-factorial/test.py @@ -0,0 +1,31 @@ +import io, sys, os, re, pytest +import app + +@pytest.mark.it('You should create a function named factorial') +def test_factorial_exists(app): + try: + from app import factorial + assert factorial + except AttributeError: + raise AttributeError("The function 'factorial' should exist on app.py") + +@pytest.mark.it('Testing the function factorial with the number 8, it should return 40320') +def test_factorial_8(app): + try: + assert app.factorial(8) == 40320 + except AttributeError: + raise AttributeError("The function 'factorial' should return the value 40320") + +@pytest.mark.it('Testing the function factorial with the number 3, it should return 6') +def test_factorial_3(app): + try: + assert app.factorial(3) == 6 + except AttributeError: + raise AttributeError("The function 'factorial' should return the value 6") + +@pytest.mark.it('Testing the function factorial with the number 1, it should return 1') +def test_factorial_1(app): + try: + assert app.factorial(1) == 1 + except AttributeError: + raise AttributeError("The function 'factorial' should return the value 1") \ No newline at end of file