File tree Expand file tree Collapse file tree
exercises/practice/queen-attack Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11USING: accessors kernel locals math ;
22IN: queen-attack
33
4+ ERROR: row-not-on-board ;
5+ ERROR: column-not-on-board ;
6+
47TUPLE: queen row column ;
58
69:: <queen> ( row column -- queen )
7- row 0 < [ "row not positive" throw ] when
8- row 7 > [ "row not on board" throw ] when
9- column 0 < [ "column not positive" throw ] when
10- column 7 > [ "column not on board" throw ] when
10+ row 0 < row 7 > or [ row-not-on-board ] when
11+ column 0 < column 7 > or [ column-not-on-board ] when
1112 row column queen boa ;
1213
1314:: can-attack? ( queen1 queen2 -- ? )
Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ function gen_test_case(case)
1010 column = Int (pos[" column" ])
1111 expected = case[" expected" ]
1212 if expected isa AbstractDict
13- msg = expected[" error" ]
14- return """ [ $(row) $(column) <queen> ]\n [ "$(escape_factor (msg)) " = ] must-fail-with"""
13+ pred = occursin (" row" , expected[" error" ]) ?
14+ " row-not-on-board?" : " column-not-on-board?"
15+ return """ [ $(row) $(column) <queen> ]\n [ $(pred) ] must-fail-with"""
1516 else
1617 return """ [ $(row) $(column) <queen> drop ] must-not-fail"""
1718 end
Original file line number Diff line number Diff line change @@ -8,19 +8,19 @@ STOP-HERE
88
99"queen must have positive row" description
1010[ -2 2 <queen> ]
11- [ " row not positive" = ] must-fail-with
11+ [ row- not-on-board? ] must-fail-with
1212
1313"queen must have row on board" description
1414[ 8 4 <queen> ]
15- [ " row not on board" = ] must-fail-with
15+ [ row- not-on- board? ] must-fail-with
1616
1717"queen must have positive column" description
1818[ 2 -2 <queen> ]
19- [ " column not positive" = ] must-fail-with
19+ [ column- not-on-board? ] must-fail-with
2020
2121"queen must have column on board" description
2222[ 4 8 <queen> ]
23- [ " column not on board" = ] must-fail-with
23+ [ column- not-on- board? ] must-fail-with
2424
2525"cannot attack" description
2626{ f } [ 2 4 <queen> 6 6 <queen> can-attack? ] unit-test
Original file line number Diff line number Diff line change 11USING: kernel ;
22IN: queen-attack
33
4+ ERROR: row-not-on-board ;
5+ ERROR: column-not-on-board ;
6+
47: <queen> ( row column -- queen )
58 "unimplemented" throw ;
69
You can’t perform that action at this time.
0 commit comments