Skip to content

Commit

Permalink
Added test to action_spec, handle_input_spec and position_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
SelenaSmall committed Aug 28, 2017
1 parent e632750 commit a2e442a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ Test by running rspec http://rspec.info/
> $ bundle exec rspec
Expected terminal output:
> ... ... ... ... ... .Output: 1,2,NORTH
> ... ... ... ... ... ... ... ..Output: 1,2,NORTH
>
> ... ... ... ... ... ... .
> ... ... ... ... ... ... ..
>
> Finished in 0.01938 seconds (files took 0.23698 seconds to load)
> Finished in 0.02025 seconds (files took 0.2322 seconds to load)
>
> 35 examples, 0 failures
> 43 examples, 0 failures
***

Expand Down
42 changes: 42 additions & 0 deletions spec/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,34 @@
end

describe '#prev_option' do
it 'should return the last value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:prev_option, 'WEST')).to be_a String
expect(instance.send(:prev_option, 'WEST')).to eq 'SOUTH'
end

it 'should return the previous value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:prev_option, 'NORTH')).to be_a String
expect(instance.send(:prev_option, 'NORTH')).to eq 'WEST'
end

it 'should return the previous value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:prev_option, 'EAST')).to be_a String
expect(instance.send(:prev_option, 'EAST')).to eq 'NORTH'
end

it 'should return the previous value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:prev_option, 'SOUTH')).to be_a String
expect(instance.send(:prev_option, 'SOUTH')).to eq 'EAST'
end

it 'should return nil if the direction param is empty' do
instance = Action.new

Expand All @@ -64,13 +85,34 @@
end

describe '#next_option' do
it 'should return the next value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:next_option, 'WEST')).to be_a String
expect(instance.send(:next_option, 'WEST')).to eq 'NORTH'
end

it 'should return the next value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:next_option, 'NORTH')).to be_a String
expect(instance.send(:next_option, 'NORTH')).to eq 'EAST'
end

it 'should return the next value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:next_option, 'EAST')).to be_a String
expect(instance.send(:next_option, 'EAST')).to eq 'SOUTH'
end

it 'should return the first value in the OPTIONS array' do
instance = Action.new

expect(instance.send(:next_option, 'SOUTH')).to be_a String
expect(instance.send(:next_option, 'SOUTH')).to eq 'WEST'
end

it 'should return nil if the direction param is empty' do
instance = Action.new

Expand Down
20 changes: 13 additions & 7 deletions spec/handle_input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

describe HandleInput do
describe '#initialize' do
it 'should have a table attribute which is nil' do
instance = HandleInput.new(@robot, @table, @action)
it 'should have a robot attribute which is an instance of Robot' do
instance = HandleInput.new(Robot.new, Table.new, Action.new)

expect(instance.table).to be_nil
expect(instance.robot).to be_a Robot
end

it 'should have a action attribute which is nil' do
instance = HandleInput.new(@robot, @table, @action)
it 'should have a table attribute which is an instance of Table' do
instance = HandleInput.new(Robot.new, Table.new, Action.new)

expect(instance.action).to be_nil
expect(instance.table).to be_a Table
end

it 'should have an action attribute which is an instance of Action' do
instance = HandleInput.new(Robot.new, Table.new, Action.new)

expect(instance.action).to be_a Action
end
end

Expand Down Expand Up @@ -84,7 +90,7 @@
end

describe '#exec' do
it 'should return an instance of Position if position is a valid table position' do
it 'should return an instance of Position' do
instance = HandleInput.new(Robot.new, Table.new, Action.new)
position = Position.new(0, 0, 'NORTH')

Expand Down
7 changes: 7 additions & 0 deletions spec/position_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
expect(instance.y).to be >= 0
expect(instance.y).to be <= 4
end

it 'should have a f attribute which is a string' do
instance = Position.new(0, 0, 'NORTH')

expect(instance.f).to be_a String
expect(instance.f).to eq 'NORTH'
end
end
end

0 comments on commit a2e442a

Please sign in to comment.