def test_Sudoku_4_gano(self): sudoku = Sudoku([["4", "2", "3", "1"], ["1", "3", "2", "4"], ["3", "1", "4", "2"], ["2", "4", "1", "3"]]) self.assertTrue(sudoku.gano())
def test_Sudoku_Gano(self): sudoku = Sudoku([["4", "1", "3", "8", "2", "5", "6", "7", "9"], ["5", "6", "7", "1", "4", "9", "8", "3", "2"], ["2", "8", "9", "7", "3", "6", "1", "4", "5"], ["1", "9", "5", "4", "6", "2", "7", "8", "3"], ["7", "2", "6", "9", "8", "3", "5", "1", "4"], ["3", "4", "8", "5", "1", "7", "2", "9", "6"], ["8", "5", "1", "6", "9", "4", "3", "2", "7"], ["9", "7", "2", "3", "5", "8", "4", "6", "1"], ["6", "3", "4", "2", "7", "1", "9", "5", "8"]]) self.assertTrue(sudoku.gano())
def test_Sudoku_Perdio(self): sudoku = Sudoku([["5", "3", "x", "x", "x", "7", "x", "x", "x"], ["6", "x", "x", "1", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.assertFalse(sudoku.gano())
def test_Sudoku_Perdio_ch(self): sudoku = Sudoku([["4", "x", "x", "1"], ["x", "1", "3", "x"], ["x", "4", "1", "x"], ["1", "x", "x", "3"]]) self.assertFalse(sudoku.gano())
class TestSudoku(unittest.TestCase): def setUp(self): self.sudoku9 = Sudoku([["5", "3", "x", "x", "7", "x", "x", "x", "x"], ["6", "x", "x", "x", "9", "5", "x", "x", "x"], ["x", "9", "8", "x", "x", "x", "x", "6", "x"], ["8", "x", "x", "x", "6", "x", "x", "x", "3"], ["4", "x", "x", "8", "x", "3", "x", "x", "1"], ["7", "x", "x", "x", "2", "x", "x", "x", "6"], ["x", "6", "x", "x", "x", "x", "2", "8", "x"], ["x", "x", "x", "4", "1", "9", "x", "x", "5"], ["x", "x", "x", "x", "8", "x", "x", "7", "9"]]) self.sudoku4 = Sudoku([["4", "x", "3", "1"], ["x", "3", "x", "x"], ["3", "1", "x", "2"], ["x", "4", "x", "x"]]) def test_Sudoku_9_tablero_correcto(self): self.assertTrue(self.sudoku9.validar()) @parameterized.expand([ (7, 0, 0), (5, 0, 1), (6, 0, 4), (8, 1, 0), (4, 1, 4), (7, 1, 5), (6, 2, 1), (9, 2, 2), (8, 2, 7), (5, 3, 0), (3, 3, 4), (8, 3, 8), (4, 4, 0), (7, 4, 3), (9, 4, 5), (2, 4, 8), (6, 5, 0), (9, 5, 4), (3, 5, 8), (9, 6, 1), (6, 6, 6), (7, 6, 7), (2, 7, 3), (6, 7, 4), (6, 7, 5), (9, 7, 8), (8, 8, 4), (6, 8, 7), (9, 8, 8), ]) def test_Sudoku_9_poner_numeros_en_lugar_fijo(self, numero, fila, columna): result = self.sudoku9.poner_numero(numero, fila, columna) self.assertEqual( result, "No puede ingresar ese numero ahi" ) @parameterized.expand([ (7, 0, 2), # misma fila (5, 1, 7), # (6, 2, 3), # (8, 3, 6), # (4, 4, 4), # (7, 5, 6), # (6, 6, 3), # (9, 7, 0), # (8, 8, 1), # misma fila (5, 8, 0), # misma columna (3, 8, 1), # (8, 7, 2), # (4, 0, 3), # (7, 6, 4), # (9, 0, 5), # (2, 0, 6), # (6, 7, 7), # (9, 0, 8), # misma columna (3, 2, 0), # misma zona (9, 0, 3), # (6, 0, 8), # (7, 3, 2), # (2, 3, 5), # (6, 3, 6), # (6, 8, 0), # (9, 8, 3), # (8, 8, 6) # misma zona ]) def test_Sudoku_9_poner_numeros_incorrectos(self, numero, fila, columna): result = self.sudoku9.poner_numero(numero, fila, columna) self.assertEqual( result, "No puede ingresar ese numero ahi" ) @parameterized.expand([ (4, 0, 2), (6, 0, 3), (8, 0, 5), (9, 0, 6), (1, 0, 7), (2, 0, 8), (7, 1, 1), (2, 1, 2), (1, 1, 3), (3, 1, 6), (4, 1, 7), (8, 1, 8), (1, 2, 0), (3, 2, 3), (4, 2, 4), (2, 2, 5), (5, 2, 6), (7, 2, 8), (5, 3, 1), (9, 3, 2), (7, 3, 3), (1, 3, 5), (4, 3, 6), (2, 3, 7), (2, 4, 1), (6, 4, 2), (5, 4, 4), (7, 4, 6), (9, 4, 7), (1, 5, 1), (3, 5, 2), (9, 5, 3), (4, 5, 5), (8, 5, 6), (5, 5, 7), (9, 6, 0), (1, 6, 2), (5, 6, 3), (3, 6, 4), (7, 6, 5), (4, 6, 8), (2, 7, 0), (8, 7, 1), (7, 7, 2), (6, 7, 6), (3, 7, 7), (3, 8, 0), (4, 8, 1), (5, 8, 2), (2, 8, 3), (6, 8, 5), ("x", 8, 2), ("x", 8, 3), ("x", 8, 5), ("x", 8, 6), (1, 8, 6), ]) def test_Sudoku_9_poner_valor_correcto(self, numero, fila, columna): result = self.sudoku9.poner_numero(numero, fila, columna) self.assertNotEqual( result, "No puede ingresar ese numero ahi" ) @parameterized.expand([ ("7", 0, 2), ("5", 1, 7), ("6", 2, 3), ("8", 3, 6), ("4", 4, 4), ("7", 5, 6), ("6", 6, 3), ("9", 7, 0), ("8", 8, 1), ]) def test_Sudoku_9_metodo_validar_Filas(self, numero, fila, columna): self.sudoku9.tablero[fila][columna] = numero self.assertFalse(self.sudoku9.validarFilas(self.sudoku9.tablero)) @parameterized.expand([ ("7", 0, 2), ("5", 1, 7), ("6", 2, 3), ("8", 3, 6), ("4", 4, 4), ("7", 5, 6), ("6", 6, 3), ("9", 7, 0), ("8", 8, 1), ("5", 8, 0), ("3", 8, 1), ("8", 7, 2), ("4", 0, 3), ("7", 6, 4), ("9", 0, 5), ("2", 0, 6), ("6", 7, 7), ("9", 0, 8), ("3", 2, 0), ("9", 0, 3), ("6", 0, 8), ("7", 3, 2), ("2", 3, 5), ("6", 3, 6), ("6", 8, 0), ("9", 8, 3), ("8", 8, 6), ]) def test_Sudoku_9_metodo_validar(self, numero, fila, columna): self.sudoku9.tablero[fila][columna] = numero self.assertFalse(self.sudoku9.validar()) def test_Sudoku_9_todavia_no_gana(self): self.assertFalse(self.sudoku9.gano()) def test_Sudoku_9_gano(self): sudoku = Sudoku([["5", "3", "4", "6", "7", "8", "9", "1", "2"], ["6", "7", "2", "1", "9", "5", "3", "4", "8"], ["1", "9", "8", "3", "4", "2", "5", "6", "7"], ["8", "5", "9", "7", "6", "1", "4", "2", "3"], ["4", "2", "6", "8", "5", "3", "7", "9", "1"], ["7", "1", "3", "9", "2", "4", "8", "5", "6"], ["9", "6", "1", "5", "3", "7", "2", "8", "4"], ["2", "8", "7", "4", "1", "9", "6", "3", "5"], ["3", "4", "5", "2", "8", "6", "1", "7", "9"]]) self.assertTrue(sudoku.gano()) @parameterized.expand([ (1, 0, 0), (1, 0, 2), (1, 0, 3), (1, 1, 1), (1, 2, 0), (1, 2, 1), (1, 2, 3), (1, 3, 1), (1, 0, 0), (1, 0, 2), (1, 0, 3), (1, 1, 1), (1, 2, 0), (1, 2, 1), (1, 2, 3), (1, 3, 1), (2, 0, 0), (2, 0, 2), (2, 0, 3), (2, 1, 1), (2, 2, 0), (2, 2, 1), (2, 2, 3), (2, 3, 1), (3, 0, 0), (3, 0, 2), (3, 0, 3), (3, 1, 1), (3, 2, 0), (3, 2, 1), (3, 2, 3), (3, 3, 1), (4, 0, 0), (4, 0, 2), (4, 0, 3), (4, 1, 1), (4, 2, 0), (4, 2, 1), (4, 2, 3), (4, 3, 1), ]) def test_Sudoku_4_poner_numeros_en_lugar_fijo(self, numero, fila, columna): result = self.sudoku4.poner_numero(numero, fila, columna) self.assertEqual( result, "No puede ingresar ese numero ahi" ) @parameterized.expand([ ("4", 0, 1), ("3", 0, 1), ("4", 1, 0), ("3", 1, 0), ("1", 3, 0), ("1", 1, 2), ("2", 3, 2), ("3", 0, 1), ("3", 1, 3), ("1", 2, 2), ("4", 3, 3), ("4", 3, 0), ("3", 1, 0), ("4", 0, 1), ("1", 0, 1), ("3", 3, 2), ("1", 3, 3), ("2", 1, 3) ]) def test_Sudoku_4_metodo_validar(self, numero, fila, columna): self.sudoku4.tablero[fila][columna] = numero self.assertFalse(self.sudoku4.validar()) def test_Sudoku_4_tablero_correcto(self): self.assertTrue(self.sudoku4.validar()) @parameterized.expand([ (4, 0, 1), (3, 0, 1), (4, 1, 0), (3, 1, 0), (1, 3, 0), (1, 1, 2), (2, 3, 2) ]) def test_Sudoku_4_poner_numeros_misma_zona(self, numero, fila, columna): result = self.sudoku4.poner_numero(numero, fila, columna) self.assertEqual(result, "No puede ingresar ese numero ahi") @parameterized.expand([ (3, 0, 1), (3, 1, 3), (1, 2, 2), (4, 3, 3) ]) def test_Sudoku_4_poner_numeros_misma_fila(self, numero, fila, columna): result = self.sudoku4.poner_numero(numero, fila, columna) self.assertEqual(result, "No puede ingresar ese numero ahi") @parameterized.expand([ (4, 3, 0), (3, 1, 0), (4, 0, 1), (1, 0, 1), (3, 3, 2), (1, 3, 3), (2, 1, 3) ]) def test_Sudoku_4_poner_numeros_misma_columna(self, numero, fila, columna): result = self.sudoku4.poner_numero(numero, fila, columna) self.assertEqual(result, "No puede ingresar ese numero ahi") @parameterized.expand([ (2, 0, 1), (4, 2, 2), (1, 1, 0), (2, 3, 0), (2, 1, 2), (4, 1, 3), (1, 3, 2), ("x", 1, 2), ("x", 1, 3), ("x", 3, 2), (3, 3, 3), ]) def test_Sudoku_4_poner_valor_correcto(self, numero, fila, columna): result = self.sudoku4.poner_numero(numero, fila, columna) self.assertNotEqual(result, "No puede ingresar ese numero ahi") def test_Sudoku_4_todavia_no_gana(self): self.assertFalse(self.sudoku4.gano()) def test_Sudoku_4_gano(self): sudoku = Sudoku([["4", "2", "3", "1"], ["1", "3", "2", "4"], ["3", "1", "4", "2"], ["2", "4", "1", "3"]]) self.assertTrue(sudoku.gano())
class Interfaz(): def pedir_tam(self): self.tam = 0 while self.tam != "9" and self.tam != "4": self.tam = input("Ingrese el tamaño del tablero (4/9) ") if self.tam != "9" and self.tam != "4": print("Ingrese 4 o 9 \n\n") def pedir_lvl(self): self.level = 0 while self.level != "1" and self.level != "2" and self.level != "3": self.level = input("Ingrese una dificultad (1, 2 o 3) ") if self.level != "1" and self.level != "2" and self.level != "3": print("Ingrese 1, 2 o 3 \n\n") def inicio(self): self.pedir_tam() self.pedir_lvl() self.tam = int(self.tam) self.lista = api(self.tam, self.level) self.game = Sudoku(self.lista) def ingresar(self, numero, x, y): try: if int(x) > self.tam or int(x) < 1: return False elif int(y) > self.tam or int(y) < 1: return False elif numero != "x": if int(numero) > 0 and int(numero) < self.tam + 1: return True else: return True except Exception: return False def pedirvalores(self): self.n = input("Ingrese un numero ") self.i = input("ingrese la fila ") self.j = input("Ingrese la columna ") if self.ingresar(self.n, self.i, self.j): return self.game.poner_numero(self.n, int(self.i) - 1, int(self.j) - 1) else: return "\nIngrese numeros validos" def play(self): self.inicio() print("") print(self.game.getTable()) while not self.game.gano(): print(self.pedirvalores()) print("\nFIN")
class Interfaz(): def ingresar_dimension(self): self.tamaño = 0 #Para ingresear la dimension del tablero while self.tamaño != "9" and self.tamaño != "4": self.tamaño = input("Ingrese el tamaño del tablero (4/9)\n") if self.tamaño != "9" and self.tamaño != "4": print( "EL TAMAÑO DEL TABLERO NO ES CORRECTO \nIngrese el tamaño del tablero nuevamente...\n" ) self.tamaño = int(self.tamaño) self.tablero = api(int(self.tamaño)) self.game = Sudoku(self.tablero) def ingresar_coordenadas( self, fila, columna, valor): #verifica que ingrese el valor de la fila, columna y valor if (fila > 0 and fila <= self.tamaño and columna > 0 and columna <= self.tamaño and valor > 0 and valor <= self.tamaño): return True else: return False def ingresa_valor(self, numero, x, y): try: if int(x) > self.tamaño: return False elif int(y) > self.tamaño: return False elif numero != "x": if int(numero) > 0 and int(numero) < self.tamaño + 1: return True return True except Exception: return False def pedir_valores(self): #Ingresa los valores el jugador self.numero = input("Ingrese un numero\n") self.fila = input("Ingrese Fila\n") self.columna = input("Ingrese Columna\n") print("") def jugar(self): #FUNCION PARA JUGAR print("\n\n ---BIENVENIDO AL SUDOKU --- \n\n") self.ingresar_dimension() print("") print(self.game.imprimir_tablero()) while not self.game.gano(): self.pedir_valores() if self.ingresa_valor(self.fila, self.columna, self.numero): self.game.ingresar_numero( int(self.fila) - 1, int(self.columna) - 1, self.numero) print(self.game.imprimir_tablero()) else: print("Numero incorrecto !!!\n") print("POR FAVOR, INGRESE UN VALOR CORRECTO!!!") if self.game.gano(): print("Usted ha ganado!!!")