Skip to content

queen-attack: represent positions as objects #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
109 changes: 83 additions & 26 deletions exercises/queen-attack/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exercise": "queen-attack",
"version": "1.0.0",
"version": "2.0.0",
"comments": [
"Testing invalid positions will vary by language. The expected",
"value of -1 is there to indicate some sort of failure should",
Expand All @@ -18,39 +18,54 @@
"description": "queen with a valid position",
"property": "create",
"queen": {
"position": "(2,2)"
"position": {
"row": 2,
"column": 2
}
},
"expected": 0
Copy link
Member

Choose a reason for hiding this comment

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

a little awkward that these are 0/-1 instead of just true/false. Probably worth fixing later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now it's using 0/1 as false/true and -1 as error. It would probably be better to use the accepted "error" methodology, but that's probably worth its own pull request. Should one of us open an issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that a separate PR for this is a good idea.

},
{
"description": "queen must have positive rank",
"description": "queen must have positive row",
"property": "create",
"queen": {
"position": "(-2,2)"
"position": {
"row": -2,
"column": 2
}
},
"expected": -1
},
{
"description": "queen must have rank on board",
"description": "queen must have row on board",
"property": "create",
"queen": {
"position": "(8,4)"
"position": {
"row": 8,
"column": 4
}
},
"expected": -1
},
{
"description": "queen must have positive file",
"description": "queen must have positive column",
"property": "create",
"queen": {
"position": "(2,-2)"
"position": {
"row": 2,
"column": -2
}
},
"expected": -1
},
{
"description": "queen must have file on board",
"description": "queen must have column on board",
"property": "create",
"queen": {
"position": "(4,8)"
"position": {
"row": 4,
"column": 8
}
},
"expected": -1
}
Expand All @@ -63,76 +78,118 @@
"description": "can not attack",
"property": "canAttack",
"white_queen": {
"position": "(2,4)"
"position": {
"row": 2,
"column": 4
}
},
"black_queen": {
"position": "(6,6)"
"position": {
"row": 6,
"column": 6
}
},
"expected": false
},
{
"description": "can attack on same rank",
"description": "can attack on same row",
"property": "canAttack",
"white_queen": {
"position": "(2,4)"
"position": {
"row": 2,
"column": 4
}
},
"black_queen": {
"position": "(2,6)"
"position": {
"row": 2,
"column": 6
}
},
"expected": true
},
{
"description": "can attack on same file",
"description": "can attack on same column",
"property": "canAttack",
"white_queen": {
"position": "(4,5)"
"position": {
"row": 4,
"column": 5
}
},
"black_queen": {
"position": "(2,5)"
"position": {
"row": 2,
"column": 5
}
},
"expected": true
},
{
"description": "can attack on first diagonal",
"property": "canAttack",
"white_queen": {
"position": "(2,2)"
"position": {
"row": 2,
"column": 2
}
},
"black_queen": {
"position": "(0,4)"
"position": {
"row": 0,
"column": 4
}
},
"expected": true
},
{
"description": "can attack on second diagonal",
"property": "canAttack",
"white_queen": {
"position": "(2,2)"
"position": {
"row": 2,
"column": 2
}
},
"black_queen": {
"position": "(3,1)"
"position": {
"row": 3,
"column": 1
}
},
"expected": true
},
{
"description": "can attack on third diagonal",
"property": "canAttack",
"white_queen": {
"position": "(2,2)"
"position": {
"row": 2,
"column": 2
}
},
"black_queen": {
"position": "(1,1)"
"position": {
"row": 1,
"column": 1
}
},
"expected": true
},
{
"description": "can attack on fourth diagonal",
"property": "canAttack",
"white_queen": {
"position": "(2,2)"
"position": {
"row": 2,
"column": 2
}
},
"black_queen": {
"position": "(5,5)"
"position": {
"row": 5,
"column": 5
}
},
"expected": true
}
Expand Down