added testing, using pipes

This commit is contained in:
Stephen McQuay 2012-10-25 22:32:44 -07:00
parent 8505476cbb
commit 51571a83cf
3 changed files with 94 additions and 12 deletions

View File

@ -2,12 +2,5 @@ import sys
from maze import parse_maze, CS235Maze
m = parse_maze(sys.argv[1])
assert m[7][0][0] == 0
assert m[7][3][0] == 1
assert m[7][0][1] == 0
assert m[3][3][3] == 1
assert m[5][2][6] == 1
assert m[7][5][4] == 0
m = parse_maze(sys.stdin.read())
print CS235Maze(m)

View File

@ -30,12 +30,10 @@ def make_maze(size=8):
return CS235Maze(r, size)
def parse_maze(filename):
f = open(filename, 'r')
t = f.read()
def parse_maze(maze):
soilded = [[[int(i) for i in j.split()]
for j in k.split('\n')]
for k in t.split('\n\n') if k]
for k in maze.split('\n\n') if k]
cleaned = derp_transpose(soilded)
return cleaned

91
maze/test_parsing.py Normal file
View File

@ -0,0 +1,91 @@
import unittest
from maze import parse_maze
class MazeTests(unittest.TestCase):
def setUp(self):
s = """\
1 0 0 0 1 0 0 0
0 1 1 1 1 1 0 0
0 1 0 1 1 0 0 0
0 1 1 1 0 0 1 1
1 1 0 0 0 1 0 0
1 1 1 0 0 1 1 0
1 0 1 0 0 1 0 1
0 0 1 0 1 0 1 0
1 0 0 0 0 1 0 0
1 1 0 0 0 1 0 1
1 0 1 0 1 1 1 1
0 0 0 0 1 0 0 1
0 0 0 0 1 0 1 1
0 0 0 1 0 0 1 0
1 0 1 0 1 0 0 0
0 1 0 1 1 0 0 1
1 1 1 0 0 0 0 1
1 0 0 1 1 1 0 1
1 0 0 1 1 0 1 0
0 1 0 1 0 1 1 1
1 0 1 1 1 1 0 0
0 1 0 1 1 0 0 0
1 1 0 1 0 0 0 1
1 1 1 0 0 0 1 0
1 1 0 0 1 0 1 1
1 1 1 1 1 0 0 1
1 1 0 0 1 0 1 1
0 1 1 1 1 1 0 1
0 1 1 0 0 0 1 0
0 1 0 1 0 0 0 0
1 1 0 1 0 1 1 0
0 0 0 0 1 1 1 0
1 0 0 0 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