Validates that the number of elements in the matrix matches the given size. >>> validate_matrix_content(['aaaa', 'aaaa', 'aaaa', 'aaaa'], 3) Traceback (most recent call last): ... ValueError: The matrix dont match with size. >>> validate_matrix_content(['aa%', 'aaa', 'a
(matrix: list[str], size: int)
| 62 | |
| 63 | |
| 64 | def validate_matrix_content(matrix: list[str], size: int) -> None: |
| 65 | """ |
| 66 | Validates that the number of elements in the matrix matches the given size. |
| 67 | |
| 68 | >>> validate_matrix_content(['aaaa', 'aaaa', 'aaaa', 'aaaa'], 3) |
| 69 | Traceback (most recent call last): |
| 70 | ... |
| 71 | ValueError: The matrix dont match with size. |
| 72 | >>> validate_matrix_content(['aa%', 'aaa', 'aaa'], 3) |
| 73 | Traceback (most recent call last): |
| 74 | ... |
| 75 | ValueError: Matrix rows can only contain letters and numbers. |
| 76 | >>> validate_matrix_content(['aaa', 'aaa', 'aaaa'], 3) |
| 77 | Traceback (most recent call last): |
| 78 | ... |
| 79 | ValueError: Each row in the matrix must have exactly 3 characters. |
| 80 | """ |
| 81 | print(matrix) |
| 82 | if len(matrix) != size: |
| 83 | raise ValueError("The matrix dont match with size.") |
| 84 | for row in matrix: |
| 85 | if len(row) != size: |
| 86 | msg = f"Each row in the matrix must have exactly {size} characters." |
| 87 | raise ValueError(msg) |
| 88 | if not all(char.isalnum() for char in row): |
| 89 | raise ValueError("Matrix rows can only contain letters and numbers.") |
| 90 | |
| 91 | |
| 92 | def validate_moves(moves: list[tuple[int, int]], size: int) -> None: |