Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
midtermreview
Commits
7322ab26
Commit
7322ab26
authored
6 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Update test_miniproject.py
parent
f6edd540
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/0.MiniProject/test_miniproject.py
+45
-0
tests/0.MiniProject/test_miniproject.py
with
45 additions
and
0 deletions
+45
-0
tests/0.MiniProject/test_miniproject.py
View file @
7322ab26
from
collections
import
Counter
,
defaultdict
import
random
import
pytest
from
src.floodfill
import
*
NUM_ITERS
:
int
=
100000
@
pytest
.
mark
.
parametrize
(
'n, m'
,
[(
1
,
1
),
(
5
,
5
),
(
5
,
10
),
(
10
,
5
)])
def
test_generate_random_grid
(
n
:
int
,
m
:
int
):
random
.
seed
(
1000
)
d
:
defaultdict
[
tuple
[
int
,
int
],
Counter
[
str
]]
=
defaultdict
(
Counter
)
for
_
in
range
(
NUM_ITERS
):
grid
:
list
[
list
[
str
]]
=
generate_random_grid
(
n
,
m
)
assert
n
==
len
(
grid
)
for
i
in
range
(
n
):
assert
m
==
len
(
grid
[
i
])
for
i
in
range
(
n
):
for
j
in
range
(
m
):
d
[(
i
,
j
)][
grid
[
i
][
j
]]
+=
1
for
x
in
d
:
assert
pytest
.
approx
(
1
/
2
,
0.01
)
==
d
[
x
][
' '
]
/
NUM_ITERS
# type: ignore
assert
pytest
.
approx
(
1
/
2
,
0.01
)
==
d
[
x
][
'W'
]
/
NUM_ITERS
# type: ignore
@
pytest
.
mark
.
parametrize
(
'n, m'
,
[(
1
,
1
),
(
5
,
5
),
(
5
,
10
),
(
10
,
5
),
(
10
,
10
)])
def
test_all_coordinates
(
n
:
int
,
m
:
int
):
assert
set
([(
x
,
y
)
for
x
in
range
(
n
)
for
y
in
range
(
m
)])
==
set
(
all_coordinates
(
generate_random_grid
(
n
,
m
)))
def
test_find_random_empty
()
->
None
:
grid
:
list
[
list
[
str
]]
=
[[
' '
,
'X'
,
' '
,
' '
],
[
'B'
,
'B'
,
' '
,
'B'
]]
d
:
Counter
[
tuple
[
int
,
int
]]
=
Counter
()
for
_
in
range
(
NUM_ITERS
):
d
[
find_random_empty
(
grid
)]
+=
1
for
x
,
y
in
d
:
assert
grid
[
x
][
y
]
==
' '
assert
pytest
.
approx
(
# type: ignore
1
/
4
,
0.01
)
==
d
[(
x
,
y
)]
/
NUM_ITERS
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help