Skip to content

Queen Attack: Replace tuple with ChessPosition#119

Merged
IanWhitney merged 1 commit intoexercism:masterfrom
IanWhitney:replace_queen_attack_tuple_with_position
Apr 30, 2016
Merged

Queen Attack: Replace tuple with ChessPosition#119
IanWhitney merged 1 commit intoexercism:masterfrom
IanWhitney:replace_queen_attack_tuple_with_position

Conversation

@IanWhitney
Copy link
Copy Markdown
Contributor

Fixes #118

Queen::new now expects a ChessPosition instead of a tuple. ChessPosition::new returns a Result, indicating if the position is valid or not.

I've added a few tests at the start to capture the behavior of ChessPosition. The tests of Queen have their API usage updated, and have been renamed for readability.

Comment thread exercises/queen-attack/example.rs Outdated
fn position(&self) -> &ChessPosition;
fn can_attack<T: ChessPiece>(&self, other: &T) -> bool;
}
//
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you mean for this comment to be here?

@petertseng
Copy link
Copy Markdown
Member

Yeah seems like a good way to address what's discussed in #118.

Tell me about the changing of the assert!(boolean_condition) to assert_eq!(true, boolean_condition) - Is it for clarity? For consistency with the false case? Or does the error message look better? Or something else?

let white_queen = Queen::new((2,2)).unwrap();
let black_queen = Queen::new((0,4)).unwrap();
assert!(white_queen.can_attack(&black_queen));
fn queens_on_the_same_diagonal_can_attack_one() {
Copy link
Copy Markdown
Member

@petertseng petertseng Apr 30, 2016

Choose a reason for hiding this comment

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

Hmm, while we are changing the test names, maybe we can take the opportunity to bikeshed. I could see these being upper_right, upper_left, etc. rather than just one, two, etc.

But I don't actually care (I recognise I'm bikeshedding), so you can pick whatever makes the most sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I couldn't think of a good name for them either.

@IanWhitney
Copy link
Copy Markdown
Contributor Author

assert vs assert_eq: probably a copy & paste error. Testing booleans should always use assert, I think. Hopefully Rust implements refute!, but I don't see an RFC for it. Perhaps I'll make one.

@petertseng
Copy link
Copy Markdown
Member

petertseng commented Apr 30, 2016

Okay I say 👍 with squash (I think you'll agree on the squash)

Would like to hear what others involved think, of course.

Fixes exercism#118

`Queen::new` now expects a `ChessPosition` instead of a tuple. `ChessPosition::new` returns a Result, indicating if the position is valid or not.

I've added a few tests at the start to capture the behavior of `ChessPosition`.  The tests of Queen have their API usage updated, and have been renamed for readability.
@IanWhitney IanWhitney force-pushed the replace_queen_attack_tuple_with_position branch from 10e349b to 275919a Compare April 30, 2016 12:40
@IanWhitney IanWhitney merged commit 2ce5739 into exercism:master Apr 30, 2016
@IanWhitney IanWhitney deleted the replace_queen_attack_tuple_with_position branch April 30, 2016 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants