Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader #31

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This code is currently supported for Python 3.

| Version | Supported |
| ------- | ------------------ |
| 3.11.x | :white_check_mark: |
| 3.11.x | :white_check_mark: |

## Reporting a Vulnerability

Expand Down
23 changes: 0 additions & 23 deletions data/atlantis.csv

This file was deleted.

10 changes: 10 additions & 0 deletions data/example1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# taken from a first example
.......92
...1...4.
9..24...7
8..7..15.
65.9.1.78
.74..8..6
3...95..1
.8...6...
79.......
10 changes: 10 additions & 0 deletions data/parool230919.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# this is a **** level puzzle from parool 2023-09-19
.6....19.
..261...4
7.1......
....7..1.
..6.83...
54..6...3
.8..27.39
...4...78
......4..
3 changes: 2 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# TODO(browne): fix these in the future
# C0103: invalid-name
# E1101: no-member
# E0231: missing whitespace after ','
# R0201, no-self-use
# R0204: redefined-variable-type
# R0902: too-many-instance-attributes
Expand All @@ -29,7 +30,7 @@
# W0613: unused-argument
# W0621: redefined-outer-name
# W0703: broad-except
disable=C0111,C0301,C0325,F0401,W0511,W0142,W0622,C0103,E1101,R0201,R0204,R0902,R0912,R0913,R0914,R0915,W0110,W0141,W0201,W0401,W0603,W0212,W0612,W0613,W0621,W0703
disable=C0111,C0301,C0325,F0401,W0511,W0142,W0622,C0103,E1101,E0231,R0201,R0204,R0902,R0912,R0913,R0914,R0915,W0110,W0141,W0201,W0401,W0603,W0212,W0612,W0613,W0621,W0703

[Basic]
# Variable names can be 1 to 31 characters long, with lowercase and underscores
Expand Down
7 changes: 4 additions & 3 deletions src/sudoku/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def get_matrix(content):

lines = []
for line in content:
new_line = line.strip() # Strip any leading or trailing whitespace
new_line = line.split("#")[0] # first remove comments starting with an #
new_line = new_line.strip() # Strip any leading or trailing whitespace
new_line = new_line.replace(".", "0") # dots are zero's
new_line = new_line.replace(",", "") # comma's are seperators
new_line = new_line.replace(" ", "") # spaces are seperators
new_line = new_line.replace(",", "") # comma's are separators
new_line = new_line.replace(" ", "") # spaces are separators
if new_line:
new_line = [int(x) for x in new_line]
lines.append(new_line)
Expand Down
45 changes: 42 additions & 3 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
790000000
"""

example2 = """# this is a **** level puzzle from parool 2023-09-19
.6....19.
..261...4
7.1......
....7..1.
..6.83...
54..6...3
.8..27.39
...4...78
......4..
"""

example1_list = [
[0,0,0,0,0,0,0,9,2],
[0,0,0,1,0,0,0,4,0],
Expand All @@ -39,12 +51,39 @@
[7,9,0,0,0,0,0,0,0]
]

def test_example():
example2_list = [
[0,6,0,0,0,0,1,9,0],
[0,0,2,6,1,0,0,0,4],
[7,0,1,0,0,0,0,0,0],
[0,0,0,0,7,0,0,1,0],
[0,0,6,0,8,3,0,0,0],
[5,4,0,0,6,0,0,0,3],
[0,8,0,0,2,7,0,3,9],
[0,0,0,4,0,0,0,7,8],
[0,0,0,0,0,0,4,0,0]
]


def test_example1():
m = reader.get_matrix(example1)
assert len(m) == 9
assert m[0] == [0,0,0,0,0,0,0,9,2]
assert m == example1_list

def test_example_alt():

def test_example1_alt():
m = reader.get_matrix(example1_alt)
assert m == example1_list
assert m == example1_list
Dismissed Show dismissed Hide dismissed


def test_example2():
m = reader.get_matrix(example2)
assert m == example2_list
Dismissed Show dismissed Hide dismissed


def test_reader():
# it is all relative from where pytest starts
m = reader.read_matrix("./data/example1.txt")
assert m == example1_list
Dismissed Show dismissed Hide dismissed
m = reader.read_matrix("./data/parool230919.txt")
assert m == example2_list
Dismissed Show dismissed Hide dismissed
Loading