Skip to content
Permalink
Browse files

Added test to action_spec, handle_input_spec and position_spec

  • Loading branch information...
SelenaSmall committed Aug 28, 2017
1 parent e632750 commit a2e442a3c5d146ca8da42abe523d2f7943af0877
Showing with 66 additions and 11 deletions.
  1. +4 −4 README.md
  2. +42 −0 spec/action_spec.rb
  3. +13 −7 spec/handle_input_spec.rb
  4. +7 −0 spec/position_spec.rb
@@ -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
***

@@ -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

@@ -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

@@ -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

@@ -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')

@@ -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.
You can’t perform that action at this time.