Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog3-coursework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ik1g19
prog3-coursework
Commits
0a67b288
Commit
0a67b288
authored
4 years ago
by
ik1g19
Browse files
Options
Downloads
Patches
Plain Diff
added challenge 2 test
parent
4598a6cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cw/test/Spec.hs
+64
-16
64 additions, 16 deletions
cw/test/Spec.hs
with
64 additions
and
16 deletions
cw/test/Spec.hs
+
64
−
16
View file @
0a67b288
import
Challenges
import
Challenges
import
Data.List
main
::
IO
()
main
::
IO
()
main
=
challenge1Test
main
=
challenge2Test
exGrid1'1
=
[
"HAGNIRTSH"
,
"SACAGETAK"
,
"GCSTACKEL"
,
"MGHKMILKI"
,
"EKNLETGCN"
,
"TNIRTLETE"
,
"IRAAHCLSR"
,
"MAMROSAGD"
,
"GIZKDDNRG"
]
exGrid1'1
=
[
"HAGNIRTSH"
,
"SACAGETAK"
,
"GCSTACKEL"
,
"MGHKMILKI"
,
"EKNLETGCN"
,
"TNIRTLETE"
,
"IRAAHCLSR"
,
"MAMROSAGD"
,
"GIZKDDNRG"
]
...
@@ -19,23 +21,69 @@ exGrid1'3 = ["TEST","ASBD","GDFI","FDGS"]
...
@@ -19,23 +21,69 @@ exGrid1'3 = ["TEST","ASBD","GDFI","FDGS"]
exWords1'3
=
[
"TEST"
]
exWords1'3
=
[
"TEST"
]
exAns1'3
=
[(
"TEST"
,
Just
((
0
,
0
),
Forward
))]
exAns1'3
=
[(
"TEST"
,
Just
((
0
,
0
),
Forward
))]
assert1
::
[(
String
,
Maybe
Placement
)]
->
[(
String
,
Maybe
Placement
)]
->
IO
()
assert1
result
correct
|
result
==
correct
=
do
putStrLn
(
"Testing:"
)
putStrLn
(
show
correct
)
printGrid
::
WordSearchGrid
->
IO
()
putStrLn
"Passed! Result:"
printGrid
[]
=
return
()
putStrLn
(
show
result
)
printGrid
(
w
:
ws
)
=
do
putStrLn
$
intersperse
' '
w
putStrLn
""
printGrid
ws
|
otherwise
=
do
putStrLn
(
"Testing:"
)
putStrLn
(
show
correct
)
pPrintList
::
Show
a
=>
[
a
]
->
IO
()
putStrLn
"Failed! Result:"
pPrintList
cs
=
do
putStr
"["
putStrLn
(
show
result
)
ppl
cs
putStrLn
""
where
ppl
(
x
:
[]
)
=
putStrLn
$
" "
++
show
x
++
"]
\n
"
ppl
(
x
:
y
:
[]
)
=
putStrLn
$
" "
++
show
x
++
","
++
show
y
++
"]
\n
"
ppl
(
x
:
y
:
z
:
[]
)
=
putStrLn
$
" "
++
show
x
++
","
++
show
y
++
","
++
show
z
++
"]
\n
"
ppl
(
x
:
y
:
z
:
xs
)
=
do
putStrLn
$
" "
++
show
x
++
","
++
show
y
++
","
++
show
z
++
","
ppl
$
xs
assert1
::
WordSearchGrid
->
[
(
String
,
Maybe
Placement
)
]
->
[
(
String
,
Maybe
Placement
)
]
->
IO
()
assert1
grid
result
correct
|
result
==
correct
=
do
putStrLn
"Testing Grid:
\n
"
printGrid
grid
putStrLn
"
\n
Expected Result:"
pPrintList
correct
putStrLn
"Passed! Result:"
pPrintList
result
|
otherwise
=
do
putStrLn
"Testing Grid:
\n
"
printGrid
grid
putStrLn
"
\n
Expected Result:"
pPrintList
correct
putStrLn
"Failed! Result:"
pPrintList
result
challenge1Test
::
IO
()
challenge1Test
::
IO
()
challenge1Test
=
do
putStrLn
"Challenge 1 Start Test"
challenge1Test
=
do
putStrLn
"Challenge 1 Start Test"
putStrLn
"========================================="
putStrLn
"========================================="
assert1
(
solveWordSearch
exWords1'3
exGrid1'3
)
exAns1'3
assert1
exGrid1'1
(
solveWordSearch
exWords1'1
exGrid1'1
)
exAns1'1
assert1
(
solveWordSearch
exWords1'1
exGrid1'1
)
exAns1'1
assert1
exGrid1'2
(
solveWordSearch
exWords1'2
exGrid1'2
)
exAns1'2
assert1
(
solveWordSearch
exWords1'2
exGrid1'2
)
exAns1'2
putStrLn
"========================================="
putStrLn
"Challenge 1 End Test"
assert2
::
WordSearchGrid
->
[
(
String
,
Maybe
Placement
)
]
->
IO
()
assert2
grid
answers
=
do
putStrLn
"Checking Grid Contains all Given Words:
\n
"
printGrid
grid
putStrLn
"
\n
Words in Grid:"
pPrintList
answers
putStrLn
areWordsPresent
where
areWordsPresent
=
if
foldl1
(
||
)
$
map
(
\
(
_
,
x
)
->
x
==
Nothing
)
answers
then
"Not all words present!"
else
"All words are present!"
createAndSolve
::
[
String
]
->
Double
->
IO
(
WordSearchGrid
,[
(
String
,
Maybe
Placement
)
])
createAndSolve
words
maxDensity
=
do
g
<-
createWordSearch
words
maxDensity
let
soln
=
solveWordSearch
words
g
return
(
g
,
soln
)
challenge2Test
::
IO
()
challenge2Test
=
do
putStrLn
"Challenge 2 Start Test"
putStrLn
"========================================="
(
g1
,
sol1
)
<-
createAndSolve
[
"WORD"
,
"EXAMPLE"
,
"SEARCH"
]
0.3
assert2
g1
sol1
putStrLn
"========================================="
putStrLn
"========================================="
putStrLn
"Challenge 1 End Test"
putStrLn
"Challenge 2 End Test"
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment