Skip to content

Commit

Permalink
We can move to the south pole from any longitude.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemalvarambhia committed Oct 30, 2023
1 parent f697b31 commit 1858d8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def next_location_backwards(location:)
end

def located_at_north_pole?(coordinates)
coordinates == Coordinates.new(x: 0, y: 9)
@x_domain.map { |x| Coordinates.new(x: x, y: 9) }.include?(coordinates)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/mars_rover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def execute(commands)
when 'f'
new_location = forwards(location)
if @map.located_at_north_pole? new_location.coordinates
Location.new(coordinates: Coordinates.new(x: 0 + 18, y: 8), direction: 'S')
Location.new(coordinates: Coordinates.new(x: new_location.coordinates.x + 18, y: 8), direction: 'S')
else
new_location
end
Expand Down
8 changes: 8 additions & 0 deletions spec/moving_forwards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def self.mars_rover(map: Map.new(x_domain: (0..10), y_domain: (0..10)), located_
expect(mars_rover).to be_facing('S')
end

it 'can move to the north pole from any longitude' do
mars_rover = a_mars_rover(located_at: Location.new(coordinates: Coordinates.new(x: 1, y: 8), direction: 'N'))

mars_rover.execute(['f'])

expect(mars_rover).to be_located_at(Coordinates.new(x: 19, y: 8))
end

it 'can move to the south pole of the planet'

it 'faces north upon reaching the south pole'
Expand Down

0 comments on commit 1858d8d

Please sign in to comment.