Skip to content

Commit

Permalink
Refactor: pushed a detail up towards the test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemalvarambhia committed Oct 31, 2023
1 parent df0a958 commit e5f9e9a
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions spec/moving_forwards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def self.mars_rover(map: Map.new(x_domain: (0..10), y_domain: (-9..9)), located_

context 'moving towards the north and south pole' do
it 'can move to the north pole of the planet' do
mars_rover = a_mars_rover(located_at: Location.new(coordinates: Coordinates.new(x: 0, y: 8), direction: 'N'))
mars_rover =
a_mars_rover(
map: Map.new(x_domain: (-18..18), y_domain: (-9..9)),
located_at: Location.new(coordinates: Coordinates.new(x: 0, y: 8), direction: 'N'))

mars_rover.execute(['f'])

Expand All @@ -132,31 +135,47 @@ def self.mars_rover(map: Map.new(x_domain: (0..10), y_domain: (-9..9)), located_
end

it 'faces south upon reaching the north pole' do
mars_rover = a_mars_rover(located_at: Location.new(coordinates: Coordinates.new(x: 0, y: 8), direction: 'N'))
mars_rover =
a_mars_rover(
map: Map.new(x_domain: (-18..18), y_domain: (-9..9)),
located_at: Location.new(coordinates: Coordinates.new(x: 0, y: 8), direction: 'N')
)

mars_rover.execute(['f'])

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 =
a_mars_rover(
map: Map.new(x_domain: (-18..18), y_domain: (-9..9)),
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 'faces north upon reaching the south pole' do
mars_rover = a_mars_rover(located_at: Location.new(coordinates: Coordinates.new(x: 0, y: -8), direction: 'S'))
mars_rover =
a_mars_rover(
map: Map.new(x_domain: (-18..18), y_domain: (-9..9)),
located_at: Location.new(coordinates: Coordinates.new(x: 0, y: -8), direction: 'S')
)

mars_rover.execute(['f'])

expect(mars_rover).to be_facing('N')
end

it 'can move to the south pole of the planet' do
mars_rover = a_mars_rover(located_at: Location.new(coordinates: Coordinates.new(x: 0, y: -8), direction: 'S'))
mars_rover =
a_mars_rover(
map: Map.new(x_domain: (-18..18), y_domain: (-9..9)),
located_at: Location.new(coordinates: Coordinates.new(x: 0, y: -8), direction: 'S')
)

mars_rover.execute(['f'])

Expand Down

0 comments on commit e5f9e9a

Please sign in to comment.