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
28 changes: 14 additions & 14 deletions exercises/practice/queen-attack/test.fut
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
import "queen_attack"

-- Queen with a valid position
-- queen with a valid position
-- ==
-- entry: test_create
-- input { 2 2 }
-- auto output
-- output { true }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, something like

let create (row: i32) (column: i32): Queen =
  assert (row >= 0 && row <= 7 && column >= 0 && column <= 7) { row=column, column=row }

would pass the test as we were not requiring the test_create return value be true.


-- Queen must have positive row
-- queen must have positive row
-- ==
-- entry: test_create
-- input { -2 2 }
-- error: Error*

-- Queen must have row on board
-- queen must have row on board
-- ==
-- entry: test_create
-- input { 8 4 }
-- error: Error*

-- Queen must have positive column
-- queen must have positive column
-- ==
-- entry: test_create
-- input { 2 -2 }
-- error: Error*

-- Queen must have column on board
-- queen must have column on board
-- ==
-- entry: test_create
-- input { 4 8 }
-- error: Error*

-- Cannot attack
-- cannot attack
-- ==
-- entry: test_can_attack
-- input { 2 4 6 6 }
-- output { false }

-- Can attack on same row
-- can attack on same row
-- ==
-- entry: test_can_attack
-- input { 2 4 2 6 }
-- output { true }

-- Can attack on same column
-- can attack on same column
-- ==
-- entry: test_can_attack
-- input { 4 5 2 5 }
-- output { true }

-- Can attack on first diagonal
-- can attack on first diagonal
-- ==
-- entry: test_can_attack
-- input { 2 2 0 4 }
-- output { true }

-- Can attack on second diagonal
-- can attack on second diagonal
-- ==
-- entry: test_can_attack
-- input { 2 2 3 1 }
-- output { true }

-- Can attack on third diagonal
-- can attack on third diagonal
-- ==
-- entry: test_can_attack
-- input { 2 2 1 1 }
-- output { true }

-- Can attack on fourth diagonal
-- can attack on fourth diagonal
-- ==
-- entry: test_can_attack
-- input { 1 7 0 6 }
-- output { true }

-- Cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal
-- cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal
-- ==
-- entry: test_can_attack
-- input { 4 1 2 5 }
Expand Down
42 changes: 42 additions & 0 deletions generators/exercises/queen_attack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
MAIN = """\
entry test_create (row: i32) (column: i32): bool =
let queen = create row column
in queen.row == row && queen.column == column

entry test_can_attack (white_queen_row: i32) (white_queen_column: i32) (black_queen_row: i32) (black_queen_column: i32): bool =
let white_queen = create white_queen_row white_queen_column
let black_queen = create black_queen_row black_queen_column
in can_attack white_queen black_queen
"""


def serialize(queen):
row = queen["position"]["row"]
column = queen["position"]["column"]
return f"{row} {column}"


def gen_test_case(prop, description, inp, expected, f):
if prop == "create":
queen = serialize(inp["queen"])
f.write(f"-- {description}\n")
f.write("-- ==\n")
f.write(f"-- entry: test_{prop}\n")
f.write(f"-- input {{ {queen} }}\n")
if isinstance(expected, dict):
f.write("-- error: Error*\n\n")
else:
f.write("-- output { true }\n\n")
else:
expected = str(expected).lower()
white_queen = serialize(inp["white_queen"])
black_queen = serialize(inp["black_queen"])
f.write(f"-- {description}\n")
f.write("-- ==\n")
f.write(f"-- entry: test_{prop}\n")
f.write(f"-- input {{ {white_queen} {black_queen} }}\n")
f.write(f"-- output {{ {expected} }}\n\n")


def gen_main(f):
f.write(MAIN)