-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that a rover can only traverse within the provided terrain bou…
…ndary limits The position is composed of the Terrain instead of the Rover. Appropriate changes are made accordingly. Additional misc changes added include: - Fix test description with regard to invalid Step - Add custom rubocop rules on cops to ignore - Fix rubocop related offenses
- Loading branch information
1 parent
2dfd9b6
commit 39c7573
Showing
12 changed files
with
250 additions
and
52 deletions.
There are no files selected for viewing
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,8 @@ | ||
Metrics/BlockLength: | ||
Enabled: false | ||
Style/Documentation: | ||
Enabled: false | ||
Metrics/MethodLength: | ||
Max: 25 # Default: 10 | ||
Naming/AccessorMethodName: | ||
Enabled: false |
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
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,8 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class RectangularPlateau | ||
def initialize(length, breadth) | ||
@length = length | ||
@breadth = breadth | ||
def initialize(lower_x_coordinate, lower_y_coordinate, upper_x_coordinate, upper_y_coordinate) | ||
@lower_x_coordinate = lower_x_coordinate | ||
@lower_y_coordinate = lower_y_coordinate | ||
@upper_x_coordinate = upper_x_coordinate | ||
@upper_y_coordinate = upper_y_coordinate | ||
end | ||
|
||
def upward_vertical_movement_permissible?(y_position) | ||
y_position >= lower_y_coordinate && | ||
y_position < upper_y_coordinate | ||
end | ||
|
||
def downward_vertical_movement_permissible?(y_position) | ||
y_position > lower_y_coordinate && | ||
y_position <= upper_y_coordinate | ||
end | ||
|
||
def forward_horizontal_movement_permissible?(x_position) | ||
x_position >= lower_x_coordinate && | ||
x_position < upper_x_coordinate | ||
end | ||
|
||
def backward_horizontal_movement_permissible?(x_position) | ||
x_position > lower_x_coordinate && | ||
x_position <= upper_x_coordinate | ||
end | ||
|
||
private | ||
|
||
attr_reader :lower_x_coordinate, :lower_y_coordinate, :upper_x_coordinate, :upper_y_coordinate | ||
end |
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
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
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
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
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,85 @@ | ||
# frozen_string_literal: true | ||
|
||
describe RectangularPlateau do | ||
let(:terrain) { RectangularPlateau.new(0, 0, 5, 5) } | ||
|
||
describe '#upward_vertical_movement_permissible?' do | ||
context 'when an entity wants to move vertically upward along the Y-axis' do | ||
context 'movement is within terrain boundary limits' do | ||
it 'returns true' do | ||
current_position = RoverPosition.new(1, 3, 'N', terrain) | ||
|
||
expect(terrain.upward_vertical_movement_permissible?(current_position.y_coordinate)).to be true | ||
end | ||
end | ||
|
||
context 'movement is outside terrain boundary limits' do | ||
it 'returns false' do | ||
current_position = RoverPosition.new(1, 5, 'N', terrain) | ||
|
||
expect(terrain.upward_vertical_movement_permissible?(current_position.y_coordinate)).to be false | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#downward_vertical_movement_permissible?' do | ||
context 'when an entity wants to move vertically downward along the Y-axis' do | ||
context 'movement is within terrain boundary limits' do | ||
it 'returns true' do | ||
current_position = RoverPosition.new(1, 3, 'S', terrain) | ||
|
||
expect(terrain.downward_vertical_movement_permissible?(current_position.y_coordinate)).to be true | ||
end | ||
end | ||
|
||
context 'movement is outside terrain boundary limits' do | ||
it 'returns false' do | ||
current_position = RoverPosition.new(1, 0, 'S', terrain) | ||
|
||
expect(terrain.downward_vertical_movement_permissible?(current_position.y_coordinate)).to be false | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#forward_horizontal_movement_permissible?' do | ||
context 'when an entity wants to move horizontally forward along the X-axis' do | ||
context 'movement is within terrain boundary limits' do | ||
it 'returns true' do | ||
current_position = RoverPosition.new(1, 3, 'E', terrain) | ||
|
||
expect(terrain.forward_horizontal_movement_permissible?(current_position.x_coordinate)).to be true | ||
end | ||
end | ||
|
||
context 'movement is outside terrain boundary limits' do | ||
it 'returns false' do | ||
current_position = RoverPosition.new(5, 3, 'E', terrain) | ||
|
||
expect(terrain.forward_horizontal_movement_permissible?(current_position.x_coordinate)).to be false | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#backward_horizontal_movement_permissible?' do | ||
context 'when an entity wants to move horizontally backward along the X-axis' do | ||
context 'movement is within terrain boundary limits' do | ||
it 'returns true' do | ||
current_position = RoverPosition.new(1, 3, 'W', terrain) | ||
|
||
expect(terrain.backward_horizontal_movement_permissible?(current_position.x_coordinate)).to be true | ||
end | ||
end | ||
|
||
context 'movement is outside terrain boundary limits' do | ||
it 'returns false' do | ||
current_position = RoverPosition.new(0, 5, 'W', terrain) | ||
|
||
expect(terrain.backward_horizontal_movement_permissible?(current_position.x_coordinate)).to be false | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.