-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
249 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Crea una variable llamada `edad` y asígnale el valor 25. | ||
Crea otra variable llamada `nombre` y asígnale tu nombre. | ||
Devuelve un string con el formato: | ||
"Mi nombre es {nombre} y tengo {edad} años" | ||
""" | ||
|
||
# Escribe tu solución aquí |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# test_solucion.py | ||
|
||
from solucion import edad, nombre, presentar | ||
|
||
def test_tipos_correctos(): | ||
assert isinstance(edad, int), "La variable `edad` debe ser un entero" | ||
assert isinstance(nombre, str), "La variable `nombre` debe ser un string" | ||
|
||
def test_valores_correctos(): | ||
assert edad == 25, "La variable `edad` debe ser igual a 25" | ||
assert "Mi nombre es" in presentar(), "El formato del mensaje es incorrecto" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Suma dos números, añade comentarios explicando cada paso y devuelve el resultado. | ||
""" | ||
|
||
# Escribe tu solución aquí |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# test_solucion.py | ||
|
||
from solucion import resultado | ||
|
||
def test_resultado_correcto(): | ||
assert resultado == 15, "El resultado debe ser igual a 15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Crea funciones para: | ||
- Sumar dos números. | ||
- Restar dos números. | ||
- Calcular el resto de una división. | ||
""" | ||
|
||
def sumar(a, b): | ||
pass | ||
|
||
def restar(a, b): | ||
pass | ||
|
||
def residuo(a, b): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# test_solucion.py | ||
|
||
from solucion import sumar, restar, residuo | ||
|
||
def test_operadores(): | ||
assert sumar(10, 5) == 15 | ||
assert restar(10, 5) == 5 | ||
assert residuo(10, 3) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Crea una función que reciba un string y lo devuelva en mayúsculas. | ||
""" | ||
|
||
def convertir_a_mayusculas(texto): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# test_solucion.py | ||
|
||
from solucion import convertir_a_mayusculas | ||
|
||
def test_strings(): | ||
assert convertir_a_mayusculas("hola") == "HOLA" | ||
assert convertir_a_mayusculas("Python") == "PYTHON" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Crea una función que sume todos los elementos de una lista. | ||
""" | ||
|
||
def suma_lista(lista): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# test_solucion.py | ||
|
||
from solucion import suma_lista | ||
|
||
def test_vectores(): | ||
assert suma_lista([1, 2, 3]) == 6 | ||
assert suma_lista([10, -5, 5]) == 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Determina si un número es par o impar. | ||
""" | ||
|
||
def par_impar(numero): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# test_solucion.py | ||
|
||
from solucion import par_impar | ||
|
||
def test_estructuras_control(): | ||
assert par_impar(4) == "Par" | ||
assert par_impar(7) == "Impar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# solucion.py | ||
""" | ||
Ejercicio: | ||
Crea una función llamada `es_primo` que reciba un número entero positivo y | ||
devuelva `True` si el número es primo, o `False` si no lo es. | ||
Un número primo es un número mayor que 1 que solo es divisible entre 1 y sí mismo. | ||
Ejemplo: | ||
es_primo(2) => True | ||
es_primo(4) => False | ||
""" | ||
|
||
def es_primo(numero): | ||
# Escribe tu solución aquí | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# test_solucion.py | ||
|
||
from solucion import es_primo | ||
|
||
def test_numero_primo(): | ||
assert es_primo(2) == True | ||
assert es_primo(3) == True | ||
assert es_primo(13) == True | ||
|
||
def test_numero_no_primo(): | ||
assert es_primo(1) == False # 1 no es primo | ||
assert es_primo(4) == False | ||
assert es_primo(9) == False | ||
|
||
def test_numeros_especiales(): | ||
assert es_primo(0) == False # 0 no es primo | ||
assert es_primo(-5) == False # Números negativos no son primos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# solucion.py | ||
|
||
""" | ||
Ejercicio: | ||
Crea una clase `Persona` que tenga: | ||
- Atributos: `nombre`, `edad`. | ||
- Método: `saludar` que devuelva "Hola, mi nombre es {nombre} y tengo {edad} años". | ||
""" | ||
|
||
class Persona: | ||
pass |
9 changes: 9 additions & 0 deletions
9
ejercicios/8_programacion_orientada_a_objetos/test_solucion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# test_solucion.py | ||
|
||
from solucion import Persona | ||
|
||
def test_poo(): | ||
persona = Persona("Juan", 30) | ||
assert persona.nombre == "Juan" | ||
assert persona.edad == 30 | ||
assert persona.saludar() == "Hola, mi nombre es Juan y tengo 30 años" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import subprocess | ||
import requests | ||
import sys | ||
|
||
# Configuración del usuario y del backend | ||
USER_MAIL = "" # Cambiar según sea necesario, agrega tu correo | ||
ENDPOINT_URL = "https://apiprogreso.hackademy.lat/submit-progress" # Cambia la URL según tu backend | ||
|
||
def ejecutar_pruebas(archivo_prueba): | ||
""" | ||
Ejecuta pytest en el archivo de prueba especificado. | ||
""" | ||
try: | ||
resultado = subprocess.run( | ||
["pytest", archivo_prueba, "--tb=short", "--disable-warnings"], | ||
stdout=subprocess.PIPE, | ||
text=True | ||
) | ||
print(resultado.stdout) | ||
return resultado.returncode, resultado.stdout | ||
except Exception as e: | ||
print(f"Error al ejecutar las pruebas: {e}") | ||
sys.exit(1) | ||
|
||
def enviar_progreso(exercise_name, status, score): | ||
""" | ||
Envía el progreso al backend. | ||
""" | ||
payload = { | ||
"user_mail": USER_MAIL, | ||
"exercise_name": exercise_name, | ||
"status": status, | ||
"score": score | ||
} | ||
|
||
try: | ||
response = requests.post(ENDPOINT_URL, json=payload) | ||
if response.status_code == 201: | ||
print("✅ Progreso registrado exitosamente.") | ||
else: | ||
print(f"❌ Error al registrar progreso: {response.json().get('error')}") | ||
except Exception as e: | ||
print(f"❌ Error al conectar con el backend: {e}") | ||
|
||
def main(): | ||
""" | ||
Ejecuta las pruebas y envía los resultados si todas las pruebas pasan. | ||
""" | ||
if len(sys.argv) != 3: | ||
print("Uso: python main.py <carpeta_ejercicio> <nombre_ejercicio>") | ||
sys.exit(1) | ||
|
||
carpeta_ejercicio = sys.argv[1] | ||
nombre_ejercicio = sys.argv[2] | ||
|
||
archivo_prueba = f"ejercicios/{carpeta_ejercicio}/test_solucion.py" | ||
|
||
print(f"🔍 Ejecutando pruebas para el ejercicio: {nombre_ejercicio}...") | ||
return_code, pytest_output = ejecutar_pruebas(archivo_prueba) | ||
|
||
if return_code == 0: | ||
print("✅ Todas las pruebas pasaron.") | ||
enviar_progreso(nombre_ejercicio, status="completado", score=100) | ||
else: | ||
print("❌ Las pruebas fallaron. Por favor, revisa los errores e intenta nuevamente.") | ||
print(pytest_output) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ notebook==7.3.1 | |
matplotlib==3.9.3 | ||
pandas==2.2.3 | ||
numpy==2.0.2 | ||
requests==2.32.3 | ||
requests==2.32.3 | ||
pytest==8.1.1 |