-
Notifications
You must be signed in to change notification settings - Fork 525
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
Sync robot-simulator with problem-specifications #1829
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
exercises/practice/robot-simulator/.meta/test_template.tera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use {{ crate_name }}::*; | ||
|
||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | slugify | replace(from="-", to="_") }}() { | ||
let robot = Robot::new({{ test.input.position.x }}, {{ test.input.position.y }}, Direction::{{ test.input.direction | title }}); | ||
{%- if test.property == "create" %} | ||
{#- noop -#} | ||
{%- elif test.input.instructions == "R" %} | ||
let robot = robot.turn_right(); | ||
{%- elif test.input.instructions == "L" %} | ||
let robot = robot.turn_left(); | ||
{%- elif test.input.instructions == "A" %} | ||
let robot = robot.advance(); | ||
{%- else %} | ||
let robot = robot.instructions({{ test.input.instructions | json_encode() }}); | ||
{% endif -%} | ||
assert_eq!(robot.position(), ({{ test.expected.position.x }}, {{ test.expected.position.y }})); | ||
assert_eq!(robot.direction(), &Direction::{{ test.expected.direction | title }}); | ||
} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,64 @@ | ||
# This is an auto-generated file. Regular comments will be removed when this | ||
# file is regenerated. Regenerating will not touch any manually added keys, | ||
# so comments can be added in a "comment" key. | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[c557c16d-26c1-4e06-827c-f6602cd0785c] | ||
description = "Create robot -> at origin facing north" | ||
|
||
[bf0dffce-f11c-4cdb-8a5e-2c89d8a5a67d] | ||
description = "Create robot -> at negative position facing south" | ||
|
||
[8cbd0086-6392-4680-b9b9-73cf491e67e5] | ||
description = "Rotating clockwise -> changes north to east" | ||
|
||
[8abc87fc-eab2-4276-93b7-9c009e866ba1] | ||
description = "Rotating clockwise -> changes east to south" | ||
|
||
[3cfe1b85-bbf2-4bae-b54d-d73e7e93617a] | ||
description = "Rotating clockwise -> changes south to west" | ||
|
||
[5ea9fb99-3f2c-47bd-86f7-46b7d8c3c716] | ||
description = "Rotating clockwise -> changes west to north" | ||
|
||
[fa0c40f5-6ba3-443d-a4b3-58cbd6cb8d63] | ||
description = "Rotating counter-clockwise -> changes north to west" | ||
|
||
[da33d734-831f-445c-9907-d66d7d2a92e2] | ||
description = "Rotating counter-clockwise -> changes west to south" | ||
|
||
[bd1ca4b9-4548-45f4-b32e-900fc7c19389] | ||
description = "Rotating counter-clockwise -> changes south to east" | ||
|
||
[2de27b67-a25c-4b59-9883-bc03b1b55bba] | ||
description = "Rotating counter-clockwise -> changes east to north" | ||
|
||
[f0dc2388-cddc-4f83-9bed-bcf46b8fc7b8] | ||
description = "Moving forward one -> facing north increments Y" | ||
|
||
[2786cf80-5bbf-44b0-9503-a89a9c5789da] | ||
description = "Moving forward one -> facing south decrements Y" | ||
|
||
[84bf3c8c-241f-434d-883d-69817dbd6a48] | ||
description = "Moving forward one -> facing east increments X" | ||
|
||
[bb69c4a7-3bbf-4f64-b415-666fa72d7b04] | ||
description = "Moving forward one -> facing west decrements X" | ||
|
||
[e34ac672-4ed4-4be3-a0b8-d9af259cbaa1] | ||
description = "Follow series of instructions -> moving east and north from README" | ||
|
||
[f30e4955-4b47-4aa3-8b39-ae98cfbd515b] | ||
description = "Follow series of instructions -> moving west and north" | ||
|
||
[3e466bf6-20ab-4d79-8b51-264165182fca] | ||
description = "Follow series of instructions -> moving west and south" | ||
|
||
[41f0bb96-c617-4e6b-acff-a4b279d44514] | ||
description = "Follow series of instructions -> moving east and north" |
157 changes: 86 additions & 71 deletions
157
exercises/practice/robot-simulator/tests/robot-simulator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,160 @@ | ||
use robot_simulator::*; | ||
|
||
#[test] | ||
fn robots_are_created_with_position_and_direction() { | ||
fn at_origin_facing_north() { | ||
let robot = Robot::new(0, 0, Direction::North); | ||
assert_eq!((0, 0), robot.position()); | ||
assert_eq!(&Direction::North, robot.direction()); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::North); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn positions_can_be_negative() { | ||
fn at_negative_position_facing_south() { | ||
let robot = Robot::new(-1, -1, Direction::South); | ||
assert_eq!((-1, -1), robot.position()); | ||
assert_eq!(&Direction::South, robot.direction()); | ||
assert_eq!(robot.position(), (-1, -1)); | ||
assert_eq!(robot.direction(), &Direction::South); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_right_does_not_change_position() { | ||
let robot = Robot::new(0, 0, Direction::North).turn_right(); | ||
assert_eq!((0, 0), robot.position()); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_right_from_north_points_the_robot_east() { | ||
let robot = Robot::new(0, 0, Direction::North).turn_right(); | ||
assert_eq!(&Direction::East, robot.direction()); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_right_from_east_points_the_robot_south() { | ||
let robot = Robot::new(0, 0, Direction::East).turn_right(); | ||
assert_eq!(&Direction::South, robot.direction()); | ||
fn changes_north_to_east() { | ||
let robot = Robot::new(0, 0, Direction::North); | ||
let robot = robot.turn_right(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::East); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_right_from_south_points_the_robot_west() { | ||
let robot = Robot::new(0, 0, Direction::South).turn_right(); | ||
assert_eq!(&Direction::West, robot.direction()); | ||
fn changes_east_to_south() { | ||
let robot = Robot::new(0, 0, Direction::East); | ||
let robot = robot.turn_right(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::South); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_right_from_west_points_the_robot_north() { | ||
let robot = Robot::new(0, 0, Direction::West).turn_right(); | ||
assert_eq!(&Direction::North, robot.direction()); | ||
fn changes_south_to_west() { | ||
let robot = Robot::new(0, 0, Direction::South); | ||
let robot = robot.turn_right(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::West); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_left_does_not_change_position() { | ||
let robot = Robot::new(0, 0, Direction::North).turn_left(); | ||
assert_eq!((0, 0), robot.position()); | ||
fn changes_west_to_north() { | ||
let robot = Robot::new(0, 0, Direction::West); | ||
let robot = robot.turn_right(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::North); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_left_from_north_points_the_robot_west() { | ||
let robot = Robot::new(0, 0, Direction::North).turn_left(); | ||
assert_eq!(&Direction::West, robot.direction()); | ||
fn changes_north_to_west() { | ||
let robot = Robot::new(0, 0, Direction::North); | ||
let robot = robot.turn_left(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::West); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_left_from_west_points_the_robot_south() { | ||
let robot = Robot::new(0, 0, Direction::West).turn_left(); | ||
assert_eq!(&Direction::South, robot.direction()); | ||
fn changes_west_to_south() { | ||
let robot = Robot::new(0, 0, Direction::West); | ||
let robot = robot.turn_left(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::South); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_left_from_south_points_the_robot_east() { | ||
let robot = Robot::new(0, 0, Direction::South).turn_left(); | ||
assert_eq!(&Direction::East, robot.direction()); | ||
fn changes_south_to_east() { | ||
let robot = Robot::new(0, 0, Direction::South); | ||
let robot = robot.turn_left(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::East); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn turning_left_from_east_points_the_robot_north() { | ||
let robot = Robot::new(0, 0, Direction::East).turn_left(); | ||
assert_eq!(&Direction::North, robot.direction()); | ||
fn changes_east_to_north() { | ||
let robot = Robot::new(0, 0, Direction::East); | ||
let robot = robot.turn_left(); | ||
assert_eq!(robot.position(), (0, 0)); | ||
assert_eq!(robot.direction(), &Direction::North); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn advance_does_not_change_the_direction() { | ||
let robot = Robot::new(0, 0, Direction::North).advance(); | ||
assert_eq!(&Direction::North, robot.direction()); | ||
fn facing_north_increments_y() { | ||
let robot = Robot::new(0, 0, Direction::North); | ||
let robot = robot.advance(); | ||
assert_eq!(robot.position(), (0, 1)); | ||
assert_eq!(robot.direction(), &Direction::North); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn advance_increases_the_y_coordinate_by_one_when_facing_north() { | ||
let robot = Robot::new(0, 0, Direction::North).advance(); | ||
assert_eq!((0, 1), robot.position()); | ||
fn facing_south_decrements_y() { | ||
let robot = Robot::new(0, 0, Direction::South); | ||
let robot = robot.advance(); | ||
assert_eq!(robot.position(), (0, -1)); | ||
assert_eq!(robot.direction(), &Direction::South); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn advance_decreases_the_y_coordinate_by_one_when_facing_south() { | ||
let robot = Robot::new(0, 0, Direction::South).advance(); | ||
assert_eq!((0, -1), robot.position()); | ||
fn facing_east_increments_x() { | ||
let robot = Robot::new(0, 0, Direction::East); | ||
let robot = robot.advance(); | ||
assert_eq!(robot.position(), (1, 0)); | ||
assert_eq!(robot.direction(), &Direction::East); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn advance_increases_the_x_coordinate_by_one_when_facing_east() { | ||
let robot = Robot::new(0, 0, Direction::East).advance(); | ||
assert_eq!((1, 0), robot.position()); | ||
fn facing_west_decrements_x() { | ||
let robot = Robot::new(0, 0, Direction::West); | ||
let robot = robot.advance(); | ||
assert_eq!(robot.position(), (-1, 0)); | ||
assert_eq!(robot.direction(), &Direction::West); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn advance_decreases_the_x_coordinate_by_one_when_facing_west() { | ||
let robot = Robot::new(0, 0, Direction::West).advance(); | ||
assert_eq!((-1, 0), robot.position()); | ||
fn moving_east_and_north_from_readme() { | ||
let robot = Robot::new(7, 3, Direction::North); | ||
let robot = robot.instructions("RAALAL"); | ||
assert_eq!(robot.position(), (9, 4)); | ||
assert_eq!(robot.direction(), &Direction::West); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn follow_instructions_to_move_west_and_north() { | ||
let robot = Robot::new(0, 0, Direction::North).instructions("LAAARALA"); | ||
assert_eq!((-4, 1), robot.position()); | ||
assert_eq!(&Direction::West, robot.direction()); | ||
fn moving_west_and_north() { | ||
let robot = Robot::new(0, 0, Direction::North); | ||
let robot = robot.instructions("LAAARALA"); | ||
assert_eq!(robot.position(), (-4, 1)); | ||
assert_eq!(robot.direction(), &Direction::West); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn follow_instructions_to_move_west_and_south() { | ||
let robot = Robot::new(2, -7, Direction::East).instructions("RRAAAAALA"); | ||
assert_eq!((-3, -8), robot.position()); | ||
assert_eq!(&Direction::South, robot.direction()); | ||
fn moving_west_and_south() { | ||
let robot = Robot::new(2, -7, Direction::East); | ||
let robot = robot.instructions("RRAAAAALA"); | ||
assert_eq!(robot.position(), (-3, -8)); | ||
assert_eq!(robot.direction(), &Direction::South); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn follow_instructions_to_move_east_and_north() { | ||
let robot = Robot::new(8, 4, Direction::South).instructions("LAAARRRALLLL"); | ||
assert_eq!((11, 5), robot.position()); | ||
assert_eq!(&Direction::North, robot.direction()); | ||
fn moving_east_and_north() { | ||
let robot = Robot::new(8, 4, Direction::South); | ||
let robot = robot.instructions("LAAARRRALLLL"); | ||
assert_eq!(robot.position(), (11, 5)); | ||
assert_eq!(robot.direction(), &Direction::North); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this shadowing what you want? It might be slightly confusing to a student?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! changed it to
robot_start
androbot_end