Skip to content

Commit

Permalink
Oneline (#37)
Browse files Browse the repository at this point in the history
* adding one line reader

* fixing import error
  • Loading branch information
iheitlager authored Nov 21, 2023
1 parent 636eb9b commit b733b5e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.renderWhitespace": "all"
}
2 changes: 1 addition & 1 deletion simple_sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Example is take from:
# https://saturncloud.io/blog/python-sudoku-wave-function-collapse-algorithm-implementation/
#
# simply use: python simple_sudoky.py to run this program
# simply use: python simple_sudoku.py to run this program
#

iterations = 0
Expand Down
5 changes: 4 additions & 1 deletion src/sudoku/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def get_matrix(content):
"""

if isinstance(content, str): # split textblob into list of lines
content = content.splitlines()
if len(content) == 81 and '\n' not in content: # assume a single line
content = [content[i:i+9] for i in range(0,81,9)]
else: # assume textblob with newlines
content = content.splitlines()

lines = []
for line in content:
Expand Down
1 change: 0 additions & 1 deletion tests/test_printer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from contextlib import redirect_stdout
import io

import sudoku as ss
from sudoku.printer import display_grid

sudoku_grid = [
Expand Down
10 changes: 9 additions & 1 deletion tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
790000000
"""

example1_str = '.......92...1...4.9..24...78..7..15.65.9.1.78.74..8..63...95..1.8...6...79.......'

example2 = """# this is a **** level puzzle from parool 2023-09-19
.6....19.
..261...4
Expand Down Expand Up @@ -76,12 +78,18 @@ def test_example1_alt():
assert m == example1_list


def test_example1_str():
assert len(example1_str) == 81
m = reader.get_matrix(example1_str)
assert m == example1_list


def test_example2():
m = reader.get_matrix(example2)
assert m == example2_list


def test_reader():
def test_filereader():
# it is all relative from where pytest starts
m = reader.read_matrix("./data/example1.txt")
assert m == example1_list
Expand Down

0 comments on commit b733b5e

Please sign in to comment.