Skip to content
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
9 changes: 5 additions & 4 deletions exercises/practice/queen-attack/.meta/example.factor
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
USING: accessors kernel locals math ;
IN: queen-attack

ERROR: row-not-on-board ;
ERROR: column-not-on-board ;

TUPLE: queen row column ;

:: <queen> ( row column -- queen )
row 0 < [ "row not positive" throw ] when
row 7 > [ "row not on board" throw ] when
column 0 < [ "column not positive" throw ] when
column 7 > [ "column not on board" throw ] when
row 0 < row 7 > or [ row-not-on-board ] when
column 0 < column 7 > or [ column-not-on-board ] when
row column queen boa ;

:: can-attack? ( queen1 queen2 -- ? )
Expand Down
5 changes: 3 additions & 2 deletions exercises/practice/queen-attack/.meta/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ function gen_test_case(case)
column = Int(pos["column"])
expected = case["expected"]
if expected isa AbstractDict
msg = expected["error"]
return """[ $(row) $(column) <queen> ]\n[ "$(escape_factor(msg))" = ] must-fail-with"""
pred = occursin("row", expected["error"]) ?
"row-not-on-board?" : "column-not-on-board?"
return """[ $(row) $(column) <queen> ]\n[ $(pred) ] must-fail-with"""
else
return """[ $(row) $(column) <queen> drop ] must-not-fail"""
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ STOP-HERE

"queen must have positive row" description
[ -2 2 <queen> ]
[ "row not positive" = ] must-fail-with
[ row-not-on-board? ] must-fail-with

"queen must have row on board" description
[ 8 4 <queen> ]
[ "row not on board" = ] must-fail-with
[ row-not-on-board? ] must-fail-with

"queen must have positive column" description
[ 2 -2 <queen> ]
[ "column not positive" = ] must-fail-with
[ column-not-on-board? ] must-fail-with

"queen must have column on board" description
[ 4 8 <queen> ]
[ "column not on board" = ] must-fail-with
[ column-not-on-board? ] must-fail-with

"cannot attack" description
{ f } [ 2 4 <queen> 6 6 <queen> can-attack? ] unit-test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
USING: kernel ;
IN: queen-attack

ERROR: row-not-on-board ;
ERROR: column-not-on-board ;

: <queen> ( row column -- queen )
"unimplemented" throw ;

Expand Down
Loading