From 64ad017452455f9d757936034e5e9061cd576c90 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 30 Nov 2025 09:31:10 -0400 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20estandarizar=20la=20entrada=20decima?= =?UTF-8?q?l=20negativa=20y=20anteponer=20autom=C3=A1ticamente=20cero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui.py | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/gui.py b/gui.py index 6ada399..c223f1d 100644 --- a/gui.py +++ b/gui.py @@ -185,29 +185,47 @@ def number_button_click(self, valor): def decimal_click(self): - """Maneja click del botón decimal. + """Maneja click del botón decimal con validaciones mejoradas. + + Corrige casos como: + "-" + "." → "-0." + "-.3" → "-0.3" - Agrega un punto decimal solo si no existe uno ya en el número actual. - - Examples: - >>> "5" → click(.) → "5." - >>> "5." → click(.) → "5." (no cambia) - >>> "" → click(.) → "0." + Previene: + "-." como número inválido. """ - # Validar que current_value sea válido antes de agregar punto - if self.current_value and self.current_value != '-': - try: - float(self.current_value) - except ValueError: - self.show_error("Número inválido") - return - - if '.' not in self.current_value: - if not self.current_value: - self.current_value = "0" - self.current_value += '.' + + # --- Caso 1: si el usuario presiona "." justo después de "-" --- + if self.current_value == "-": + # Autocompletar a -0. + self.current_value = "-0." self.display.delete(0, tk.END) self.display.insert(0, self.current_value) + return + + # --- Caso 2: si no hay nada escrito, iniciar con "0." --- + if not self.current_value: + self.current_value = "0." + self.display.delete(0, tk.END) + self.display.insert(0, self.current_value) + return + + # --- Caso 3: evitar doble punto --- + if '.' in self.current_value: + return + + # --- Caso 4: validar número antes de agregar punto --- + try: + # Permitir cadenas como "5", "-3", "12" + float(self.current_value) + except ValueError: + self.show_error("Número inválido") + return + + # --- Agregar el punto decimal --- + self.current_value += '.' + self.display.delete(0, tk.END) + self.display.insert(0, self.current_value) def operation_click(self, operation): From fd7e02d486161f1ce930685eabe53eec893076ff Mon Sep 17 00:00:00 2001 From: jose andres meneces lopez Date: Mon, 1 Dec 2025 16:10:55 -0400 Subject: [PATCH 2/3] fix: corregir importaciones de calculator eliminando el prefijo de punto --- src/cli.py | 2 +- src/gui.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli.py b/src/cli.py index 6b81ed7..a7b6cb9 100644 --- a/src/cli.py +++ b/src/cli.py @@ -4,7 +4,7 @@ un punto de entrada principal. """ -from .calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value +from calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value def main(): """Función principal del programa.""" diff --git a/src/gui.py b/src/gui.py index 01fbbf4..7733f0d 100644 --- a/src/gui.py +++ b/src/gui.py @@ -7,7 +7,7 @@ - Manejo de errores con mensajes visuales """ import tkinter as tk -from .calculator import (add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value) +from calculator import (add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value) class CalculatorGUI: def __init__(self, root): From 464edb5d505b097a7e26b9d6314849a8d56c913d Mon Sep 17 00:00:00 2001 From: Jandres Date: Mon, 1 Dec 2025 18:36:40 -0400 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20ajustar=20importaciones=20de=20calcu?= =?UTF-8?q?lator=20para=20manejar=20errores=20de=20importaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- src/cli.py | 5 ++++- src/gui.py | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f903de3..8a52514 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,4 +27,4 @@ jobs: pip install -r requirements.txt - name: Run tests - run: pytest tests/ -v + run: pytest -v diff --git a/src/cli.py b/src/cli.py index a7b6cb9..eafa893 100644 --- a/src/cli.py +++ b/src/cli.py @@ -4,7 +4,10 @@ un punto de entrada principal. """ -from calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value +try: + from .calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value +except ImportError: + from calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value def main(): """Función principal del programa.""" diff --git a/src/gui.py b/src/gui.py index 7733f0d..e2f52de 100644 --- a/src/gui.py +++ b/src/gui.py @@ -7,7 +7,11 @@ - Manejo de errores con mensajes visuales """ import tkinter as tk -from calculator import (add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value) + +try: + from .calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value +except ImportError: + from calculator import add, subtract, multiply, divide, power, valor_maximo, valor_minimo, abs_value class CalculatorGUI: def __init__(self, root):