kangoroo_robot 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/kangoroo_robot +6 -0
- data/lib/kangoroo_robot/direction.rb +11 -0
- data/lib/kangoroo_robot/instruction.rb +13 -0
- data/lib/kangoroo_robot/instructions/left.rb +27 -0
- data/lib/kangoroo_robot/instructions/move.rb +21 -0
- data/lib/kangoroo_robot/instructions/place.rb +25 -0
- data/lib/kangoroo_robot/instructions/report.rb +19 -0
- data/lib/kangoroo_robot/instructions/right.rb +28 -0
- data/lib/kangoroo_robot/parser.rb +44 -0
- data/lib/kangoroo_robot/position.rb +40 -0
- data/lib/kangoroo_robot/robot.rb +61 -0
- data/lib/kangoroo_robot/table.rb +24 -0
- data/lib/kangoroo_robot/version.rb +1 -1
- data/spec/lib/direction_spec.rb +15 -0
- data/spec/lib/instruction_spec.rb +15 -0
- data/spec/lib/instructions/left_spec.rb +62 -0
- data/spec/lib/instructions/move_spec.rb +73 -0
- data/spec/lib/instructions/place_spec.rb +31 -0
- data/spec/lib/instructions/report_spec.rb +21 -0
- data/spec/lib/instructions/right_spec.rb +62 -0
- data/spec/lib/kangoroo_robot_spec.rb +9 -0
- data/spec/lib/parser_spec.rb +59 -0
- data/spec/lib/position_spec.rb +74 -0
- data/spec/lib/robot_spec.rb +43 -0
- data/spec/lib/table_spec.rb +25 -0
- data/spec/spec_helper.rb +97 -0
- metadata +40 -9
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.travis.yml +0 -3
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -1
- data/kangoroo_robot.gemspec +0 -28
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e446f745751fd301416bc9fafe29240c422a367b
         | 
| 4 | 
            +
              data.tar.gz: bedccb72bbb6a2d4a4ba23ad671136bf78e3d039
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2eae8f4ee40cec27e0dbe8e268cd06779ed89faad58d7816a2cdc129c3a364ec53dfc977e8a1e60bd0df33be280a162b24f4fecc09b413bfc766f50bb266da78
         | 
| 7 | 
            +
              data.tar.gz: 9d37de0c3173322516ee4feb0ab63f7aa1666b933e74273604384b6e0b65a171cf6375922f07965ca1680a3b3abf1997812b3b86dec91e484268a1bb78358107
         | 
    
        data/bin/kangoroo_robot
    ADDED
    
    
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Instruction::Left < Instruction 
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def initialize
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def rotate(direction)
         | 
| 8 | 
            +
                  case direction.cardinal_point
         | 
| 9 | 
            +
                    when "NORTH"
         | 
| 10 | 
            +
                      "WEST"
         | 
| 11 | 
            +
                    when "WEST"
         | 
| 12 | 
            +
                      "SOUTH"
         | 
| 13 | 
            +
                    when "SOUTH"
         | 
| 14 | 
            +
                      "EAST"
         | 
| 15 | 
            +
                    when "EAST"
         | 
| 16 | 
            +
                      "NORTH"
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def execute(position, direction, table)
         | 
| 21 | 
            +
                  return false if !position.settled
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  direction.cardinal_point = rotate(direction)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Instruction::Move < Instruction 
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def initialize
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def execute(position, direction, table)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  return false unless position.settled
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  next_position = position.next(direction)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  return false if is_off_limits?(next_position[:x], next_position[:y], table)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  position.set(next_position[:x], next_position[:y])
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  true
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Instruction::Place < Instruction 
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :x, :y, :cardinal_point
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize(x, y, cardinal_point)
         | 
| 7 | 
            +
                  @x = x.to_i
         | 
| 8 | 
            +
                  @y = y.to_i
         | 
| 9 | 
            +
                  @cardinal_point = cardinal_point
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def execute(position, direction, table)
         | 
| 13 | 
            +
                  if is_off_limits?(x, y, table)
         | 
| 14 | 
            +
                    puts "The limits of this table are #{table.xlimit}x#{table.ylimit}"
         | 
| 15 | 
            +
                    return false 
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  position.set(x,y)
         | 
| 19 | 
            +
                  direction.cardinal_point = cardinal_point
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  true
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Instruction::Report < Instruction 
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def initialize
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def execute(position, direction, table)
         | 
| 8 | 
            +
                  if !position.settled
         | 
| 9 | 
            +
                    puts "I am not on the map, PLACE me first"
         | 
| 10 | 
            +
                    return false
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  puts "#{position.x},#{position.y},#{direction.cardinal_point}"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  return true      
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Instruction::Right < Instruction 
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def initialize
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def rotate(direction)
         | 
| 8 | 
            +
                  case direction.cardinal_point
         | 
| 9 | 
            +
                    when "NORTH"
         | 
| 10 | 
            +
                      "EAST"
         | 
| 11 | 
            +
                    when "EAST"
         | 
| 12 | 
            +
                      "SOUTH"
         | 
| 13 | 
            +
                    when "SOUTH"
         | 
| 14 | 
            +
                      "WEST"
         | 
| 15 | 
            +
                    when "WEST"
         | 
| 16 | 
            +
                      "NORTH"
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def execute(position, direction, table)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  return false if !position.settled
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  direction.cardinal_point = rotate(direction)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Parser
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :regexp, :matches
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize
         | 
| 7 | 
            +
                  @regexp = %r{ ^(?<command>MOVE|LEFT|RIGHT|REPORT|
         | 
| 8 | 
            +
                                (PLACE\s+
         | 
| 9 | 
            +
                                (?<x>\d+),
         | 
| 10 | 
            +
                                (?<y>\d+),
         | 
| 11 | 
            +
                                (?<direction>NORTH|EAST|SOUTH|WEST)))$
         | 
| 12 | 
            +
                            }x
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  @matches = matches
         | 
| 15 | 
            +
                end  
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def validate(str)
         | 
| 18 | 
            +
                  if @matches = str.match(regexp)
         | 
| 19 | 
            +
                    true
         | 
| 20 | 
            +
                  else
         | 
| 21 | 
            +
                    puts "Sorry I didn't understand your command"
         | 
| 22 | 
            +
                    puts "Refer to the README for available commands"      
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    false
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def load_instruction
         | 
| 29 | 
            +
                  case @matches[:command]
         | 
| 30 | 
            +
                    when "MOVE"
         | 
| 31 | 
            +
                      Instruction::Move.new
         | 
| 32 | 
            +
                    when "LEFT"
         | 
| 33 | 
            +
                      Instruction::Left.new
         | 
| 34 | 
            +
                    when "RIGHT"
         | 
| 35 | 
            +
                      Instruction::Right.new
         | 
| 36 | 
            +
                    when "REPORT"
         | 
| 37 | 
            +
                      Instruction::Report.new
         | 
| 38 | 
            +
                    when /PLACE.*/
         | 
| 39 | 
            +
                      Instruction::Place.new(@matches[:x], @matches[:y], @matches[:direction])
         | 
| 40 | 
            +
                  end    
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Position
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_reader :x, :y
         | 
| 5 | 
            +
                attr_accessor :settled
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize
         | 
| 8 | 
            +
                  @settled = false
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def set(x, y)
         | 
| 12 | 
            +
                  @x, @y = x, y
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  @settled = true
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def now 
         | 
| 18 | 
            +
                  return false unless @settled
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  {x: x, y: y}
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                # Next position according to current direction
         | 
| 24 | 
            +
                def next(direction)
         | 
| 25 | 
            +
                  return false unless @settled
         | 
| 26 | 
            +
                  
         | 
| 27 | 
            +
                  case direction.cardinal_point
         | 
| 28 | 
            +
                    when "NORTH"     
         | 
| 29 | 
            +
                      {x: x,   y: y+1}
         | 
| 30 | 
            +
                    when "EAST"
         | 
| 31 | 
            +
                      {x: x+1, y: y}
         | 
| 32 | 
            +
                    when "SOUTH"
         | 
| 33 | 
            +
                      {x: x,   y: y-1}
         | 
| 34 | 
            +
                    when "WEST"
         | 
| 35 | 
            +
                      {x: x-1, y: y}
         | 
| 36 | 
            +
                  end           
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Robot
         | 
| 3 | 
            +
                attr_reader :table, :position, :direction, :parser
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize
         | 
| 6 | 
            +
                  @table      = Table.new(5,5)
         | 
| 7 | 
            +
                  @position   = Position.new
         | 
| 8 | 
            +
                  @direction  = Direction.new
         | 
| 9 | 
            +
                  
         | 
| 10 | 
            +
                  @parser     = Parser.new    
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  welcome
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def listen
         | 
| 16 | 
            +
                  ARGF.each do |line|
         | 
| 17 | 
            +
                    read line
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def read(str)
         | 
| 22 | 
            +
                  return unless @parser.validate(str)
         | 
| 23 | 
            +
                  
         | 
| 24 | 
            +
                  instruction = @parser.load_instruction()
         | 
| 25 | 
            +
                  instruction.execute(@position, @direction, @table)
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def welcome
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  puts %{
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                              | Kangaroo Robot |
         | 
| 33 | 
            +
                    | Herve Tatche's exercice for Lookahead |
         | 
| 34 | 
            +
                                     .
         | 
| 35 | 
            +
                                 /\ /l
         | 
| 36 | 
            +
                                ((.Y(!
         | 
| 37 | 
            +
                                 \ |/
         | 
| 38 | 
            +
                                 /  6~6,
         | 
| 39 | 
            +
                                 \ _    +-.
         | 
| 40 | 
            +
                                  \`-=--^-'
         | 
| 41 | 
            +
                                  _/  \ 
         | 
| 42 | 
            +
                                  (  .  Y
         | 
| 43 | 
            +
                                /"\ `--^--v--.
         | 
| 44 | 
            +
                               / _ `--"T~\/~\/
         | 
| 45 | 
            +
                              / " ~\.  !
         | 
| 46 | 
            +
                        _    Y      Y./'
         | 
| 47 | 
            +
                       Y^|   |      |~~7
         | 
| 48 | 
            +
                       | l   |     / ./'
         | 
| 49 | 
            +
                       | `L  | Y .^/~T
         | 
| 50 | 
            +
                       |  l  ! | |/| |
         | 
| 51 | 
            +
                       | .`\/' | Y | !   
         | 
| 52 | 
            +
                       l  "~   j l j_L______
         | 
| 53 | 
            +
                        \,____{ __"~ __ ,\_,\_
         | 
| 54 | 
            +
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module KangorooRobot
         | 
| 2 | 
            +
              class Table
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                attr_accessor :xlimit, :ylimit
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize(xlimit, ylimit)
         | 
| 7 | 
            +
                  @xlimit = xlimit
         | 
| 8 | 
            +
                  @ylimit = ylimit
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  is_valid?
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def is_valid?
         | 
| 14 | 
            +
                  if xlimit.is_a?(Integer) && ylimit.is_a?(Integer)
         | 
| 15 | 
            +
                    if xlimit > 0 && ylimit > 0
         | 
| 16 | 
            +
                      return true
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  # We stop execution if table is not valid
         | 
| 21 | 
            +
                  raise ArgumentError
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            require "direction"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Direction" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:direction) { Direction.new("EAST") }  
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                context "after initializing" do
         | 
| 9 | 
            +
                  it "receives a cardinal point" do
         | 
| 10 | 
            +
                    expect(direction.cardinal_point).to eq("EAST")
         | 
| 11 | 
            +
                  end    
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
               
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            require "instruction"
         | 
| 2 | 
            +
            require "table"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module KangorooRobot
         | 
| 5 | 
            +
              describe "Instruction" do
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                let(:instruction) { Instruction.new }
         | 
| 8 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it "detects off limits position" do
         | 
| 11 | 
            +
                  expect(instruction.is_off_limits?(10,20, table)).to be true
         | 
| 12 | 
            +
                end   
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| @@ -0,0 +1,62 @@ | |
| 1 | 
            +
            require "instructions/left"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Left" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 7 | 
            +
                let(:position) { Position.new }
         | 
| 8 | 
            +
                let(:direction) { Direction.new }
         | 
| 9 | 
            +
                let(:left) { Instruction::Left.new } 
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                describe "#execute" do
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  it "executes the instruction" do
         | 
| 14 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    place.execute(position, direction, table)
         | 
| 17 | 
            +
                    left.execute(position, direction, table)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    expect(direction.cardinal_point).to eq("WEST")
         | 
| 20 | 
            +
                  end  
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  it "does not executes the instruction if position is not settled" do
         | 
| 23 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    expect(left.execute(position, direction, table)).to be false
         | 
| 26 | 
            +
                  end 
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                describe "#rotate" do
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  it "rotates 90 degrees to left from NORTH" do
         | 
| 33 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 34 | 
            +
                    place.execute(position, direction, table)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    expect(left.rotate(direction)).to eq("WEST")
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  it "rotates 90 degrees to left from WEST" do
         | 
| 40 | 
            +
                    place = Instruction::Place.new(2,2,"WEST")
         | 
| 41 | 
            +
                    place.execute(position, direction, table)
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    expect(left.rotate(direction)).to eq("SOUTH")
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  it "rotates 90 degrees to left from SOUTH" do
         | 
| 47 | 
            +
                    place = Instruction::Place.new(2,2,"SOUTH")
         | 
| 48 | 
            +
                    place.execute(position, direction, table)
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    expect(left.rotate(direction)).to eq("EAST")
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  it "rotates 90 degrees to left from EAST" do
         | 
| 54 | 
            +
                    place = Instruction::Place.new(2,2,"EAST")
         | 
| 55 | 
            +
                    place.execute(position, direction, table)
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    expect(left.rotate(direction)).to eq("NORTH")
         | 
| 58 | 
            +
                  end        
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
            end
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            require "instructions/move"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Move" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 7 | 
            +
                let(:position) { Position.new }
         | 
| 8 | 
            +
                let(:direction) { Direction.new }
         | 
| 9 | 
            +
                let(:move) { Instruction::Move.new } 
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                context "when edge cases" do
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  it "does not execute instruction if robot will go off limits" do
         | 
| 14 | 
            +
                    place = Instruction::Place.new(5,5,"NORTH")
         | 
| 15 | 
            +
                    place.execute(position, direction, table)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    expect(move.execute(position, direction, table)).to be false
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  it "does not move if robot will go off limits" do
         | 
| 21 | 
            +
                    place = Instruction::Place.new(0,0,"SOUTH")
         | 
| 22 | 
            +
                    place.execute(position, direction, table)
         | 
| 23 | 
            +
                    move.execute(position, direction, table)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    expect(position.now).to eq({x: 0, y: 0})
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  it "does not execute instruction if robot is not placed" do
         | 
| 29 | 
            +
                    place = Instruction::Place.new(0,0,"NORTH")
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    expect(move.execute(position, direction, table)).to be false
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                context "when executing instruction" do
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  it "goes north" do
         | 
| 39 | 
            +
                    place = Instruction::Place.new(0,0,"NORTH")
         | 
| 40 | 
            +
                    place.execute(position, direction, table)
         | 
| 41 | 
            +
                    move.execute(position, direction, table)
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    expect(position.now).to eq({x: 0, y: 1})
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  it "goes east" do
         | 
| 47 | 
            +
                    place = Instruction::Place.new(0,0,"EAST")
         | 
| 48 | 
            +
                    place.execute(position, direction, table)
         | 
| 49 | 
            +
                    move.execute(position, direction, table)
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    expect(position.now).to eq({x: 1, y: 0})
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  it "goes south" do
         | 
| 55 | 
            +
                    place = Instruction::Place.new(1,3,"SOUTH")
         | 
| 56 | 
            +
                    place.execute(position, direction, table)
         | 
| 57 | 
            +
                    move.execute(position, direction, table)
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    expect(position.now).to eq({x: 1, y: 2})
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  it "goes west" do
         | 
| 63 | 
            +
                    place = Instruction::Place.new(1,3,"WEST")
         | 
| 64 | 
            +
                    place.execute(position, direction, table)
         | 
| 65 | 
            +
                    move.execute(position, direction, table)
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    expect(position.now).to eq({x: 0, y: 3})
         | 
| 68 | 
            +
                  end  
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            require "instructions/place"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Place" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 7 | 
            +
                let(:position) { Position.new }
         | 
| 8 | 
            +
                let(:direction) { Direction.new("EAST") }
         | 
| 9 | 
            +
                let(:place) { Instruction::Place.new(3,4,"EAST") }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                context "after initializing" do
         | 
| 12 | 
            +
                  it "has an x coordinate" do
         | 
| 13 | 
            +
                    expect(place.x).to eq(3)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                describe "#execute" do
         | 
| 18 | 
            +
                  it "executes the instruction" do
         | 
| 19 | 
            +
                    expect(place.execute(position, direction, table)).to be true
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  context "when position is off limits" do
         | 
| 23 | 
            +
                    it "does not execute the instruction" do
         | 
| 24 | 
            +
                      unvalid_placing = Instruction::Place.new(3,25,"EAST")
         | 
| 25 | 
            +
                      expect(unvalid_placing.execute(position, direction, table)).to be false
         | 
| 26 | 
            +
                    end
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require "instructions/report"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Report" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 7 | 
            +
                let(:position) { Position.new }
         | 
| 8 | 
            +
                let(:direction) { Direction.new("EAST") }
         | 
| 9 | 
            +
                let(:report) { Instruction::Report.new }  
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                describe "#execute" do
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                   context "when robot is not placed" do
         | 
| 14 | 
            +
                    it "ignores command" do
         | 
| 15 | 
            +
                      expect(report.execute(position, direction, table)).to be false
         | 
| 16 | 
            +
                    end           
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,62 @@ | |
| 1 | 
            +
            require "instructions/right"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Right" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:table) { Table.new(5,5) }
         | 
| 7 | 
            +
                let(:position) { Position.new }
         | 
| 8 | 
            +
                let(:direction) { Direction.new }
         | 
| 9 | 
            +
                let(:right) { Instruction::Right.new } 
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                describe "#execute" do
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  it "executes the instruction" do
         | 
| 14 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    place.execute(position, direction, table)
         | 
| 17 | 
            +
                    right.execute(position, direction, table)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    expect(direction.cardinal_point).to eq("EAST")
         | 
| 20 | 
            +
                  end  
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  it "does not executes the instruction if position is not settled" do
         | 
| 23 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    expect(right.execute(position, direction, table)).to be false
         | 
| 26 | 
            +
                  end 
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                describe "#rotate" do
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  it "rotates 90 degrees to right from NORTH" do
         | 
| 33 | 
            +
                    place = Instruction::Place.new(2,2,"NORTH")
         | 
| 34 | 
            +
                    place.execute(position, direction, table)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    expect(right.rotate(direction)).to eq("EAST")
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  it "rotates 90 degrees to right from EAST" do
         | 
| 40 | 
            +
                    place = Instruction::Place.new(2,2,"EAST")
         | 
| 41 | 
            +
                    place.execute(position, direction, table)
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    expect(right.rotate(direction)).to eq("SOUTH")
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  it "rotates 90 degrees to right from SOUTH" do
         | 
| 47 | 
            +
                    place = Instruction::Place.new(2,2,"SOUTH")
         | 
| 48 | 
            +
                    place.execute(position, direction, table)
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    expect(right.rotate(direction)).to eq("WEST")
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  it "rotates 90 degrees to right from WEST" do
         | 
| 54 | 
            +
                    place = Instruction::Place.new(2,2,"WEST")
         | 
| 55 | 
            +
                    place.execute(position, direction, table)
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    expect(right.rotate(direction)).to eq("NORTH")
         | 
| 58 | 
            +
                  end        
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
            end
         | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            require "parser"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Parser" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:parser) { Parser.new }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                context "after initializing" do
         | 
| 9 | 
            +
                  it "has a regular expression" do
         | 
| 10 | 
            +
                    expect(parser.regexp.is_a?(Regexp)).to be true
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  it "loads a PLACE command" do
         | 
| 14 | 
            +
                    parser.validate "PLACE 1,2,EAST"
         | 
| 15 | 
            +
                    instruction = parser.load_instruction
         | 
| 16 | 
            +
                    expect(instruction.is_a?(Instruction::Place)).to be true
         | 
| 17 | 
            +
                  end        
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                context "when validating" do 
         | 
| 21 | 
            +
                  it "does not validate a wrong command" do
         | 
| 22 | 
            +
                    instruction = parser.validate "🙈 🙉 🙊"
         | 
| 23 | 
            +
                    expect(instruction).to be false
         | 
| 24 | 
            +
                  end 
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  it "validates a PLACE command" do
         | 
| 27 | 
            +
                    valid = parser.validate "PLACE 1,2,EAST"
         | 
| 28 | 
            +
                    expect(valid).to be true
         | 
| 29 | 
            +
                  end        
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                context "when parsing" do
         | 
| 33 | 
            +
                  it "parses a MOVE instruction" do
         | 
| 34 | 
            +
                    parser.validate "MOVE"
         | 
| 35 | 
            +
                    instruction = parser.load_instruction
         | 
| 36 | 
            +
                    expect(instruction.is_a?(Instruction::Move)).to be true
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  it "parses a LEFT instruction" do
         | 
| 40 | 
            +
                    parser.validate "LEFT"
         | 
| 41 | 
            +
                    instruction = parser.load_instruction
         | 
| 42 | 
            +
                    expect(instruction.is_a?(Instruction::Left)).to be true
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  it "parses a RIGHT instruction" do
         | 
| 46 | 
            +
                    parser.validate "RIGHT"
         | 
| 47 | 
            +
                    instruction = parser.load_instruction
         | 
| 48 | 
            +
                    expect(instruction.is_a?(Instruction::Right)).to be true
         | 
| 49 | 
            +
                  end    
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  it "parses a REPORT instruction" do
         | 
| 52 | 
            +
                    parser.validate "REPORT"
         | 
| 53 | 
            +
                    instruction = parser.load_instruction
         | 
| 54 | 
            +
                    expect(instruction.is_a?(Instruction::Report)).to be true
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end  
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| @@ -0,0 +1,74 @@ | |
| 1 | 
            +
            require "position"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Position" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:position) { Position.new }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                context "when setting the position" do
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  it "has x coordinate" do
         | 
| 11 | 
            +
                    position.set(1,2)
         | 
| 12 | 
            +
                    expect(position.x).to eq(1)
         | 
| 13 | 
            +
                  end    
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  it "has y coordinate" do
         | 
| 16 | 
            +
                    position.set(1,2)
         | 
| 17 | 
            +
                    expect(position.y).to eq(2)
         | 
| 18 | 
            +
                  end   
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  it "is settled" do
         | 
| 21 | 
            +
                    position.set(1,2)
         | 
| 22 | 
            +
                    expect(position.settled).to be true
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  it "gives the current position" do
         | 
| 26 | 
            +
                    position.set(1,2)
         | 
| 27 | 
            +
                    expect(position.now).to eq({x: 1, y: 2})
         | 
| 28 | 
            +
                  end 
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                describe "#next" do
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  it "gives the next position before moving" do
         | 
| 35 | 
            +
                    table = Table.new(5,5)
         | 
| 36 | 
            +
                    direction = Direction.new
         | 
| 37 | 
            +
                    position = Position.new
         | 
| 38 | 
            +
                    place = Instruction::Place.new(0,0,"EAST")
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    place.execute(position, direction, table)
         | 
| 41 | 
            +
                    next_position = position.next(direction)
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                    expect(next_position).to eq({x: 1, y: 0})
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                  
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                describe "#now" do
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  it "gives the current position" do
         | 
| 51 | 
            +
                    table = Table.new(5,5)
         | 
| 52 | 
            +
                    direction = Direction.new
         | 
| 53 | 
            +
                    position = Position.new
         | 
| 54 | 
            +
                    place = Instruction::Place.new(0,0,"EAST")
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    place.execute(position, direction, table)
         | 
| 57 | 
            +
                    next_position = position.next(direction)
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    expect(next_position).to eq({x: 1, y: 0})
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                  
         | 
| 62 | 
            +
                  it "does not give position if robot is not placed" do
         | 
| 63 | 
            +
                    table = Table.new(5,5)
         | 
| 64 | 
            +
                    position = Position.new
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                    current_position = position.now
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    expect(current_position).to be false
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
                  
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
            end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            require "robot"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Robot" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                let(:robot) { Robot.new }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                context "after initializing" do
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  it "has a table" do
         | 
| 11 | 
            +
                    expect(robot.table.is_a?(Table)).to be true
         | 
| 12 | 
            +
                  end    
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  it "has a position" do
         | 
| 15 | 
            +
                    expect(robot.position.is_a?(Position)).to be true
         | 
| 16 | 
            +
                  end  
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  it "has a direction" do
         | 
| 19 | 
            +
                    expect(robot.direction.is_a?(Direction)).to be true
         | 
| 20 | 
            +
                  end 
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  it "has a parser" do
         | 
| 23 | 
            +
                    expect(robot.parser.is_a?(Parser)).to be true
         | 
| 24 | 
            +
                  end     
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                context "when listening the user input" do
         | 
| 29 | 
            +
                  it "reads the command and executes instruction" do
         | 
| 30 | 
            +
                    command = "PLACE 2,3,NORTH"
         | 
| 31 | 
            +
                    robot.read(command)
         | 
| 32 | 
            +
                    expect(robot.position.now).to eq({x:2, y:3})
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  it "does not execute unvalid commands" do
         | 
| 36 | 
            +
                    command = "PLA_CE 2,3,NORTH"
         | 
| 37 | 
            +
                    robot.read(command)
         | 
| 38 | 
            +
                    expect(robot.position.settled).to be false
         | 
| 39 | 
            +
                  end      
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            require "table"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module KangorooRobot
         | 
| 4 | 
            +
              describe "Table" do
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                context "after initializing" do
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  it "needs two arguments" do
         | 
| 9 | 
            +
                    expect{Table.new}.to raise_error(ArgumentError)
         | 
| 10 | 
            +
                  end    
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  it "needs a valid size" do
         | 
| 13 | 
            +
                    expect{Table.new("a", 1)}.to raise_error(ArgumentError)
         | 
| 14 | 
            +
                  end 
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                describe "#is_valid?" do
         | 
| 19 | 
            +
                  it "is false if table is unvalid" do
         | 
| 20 | 
            +
                    expect{Table.new("a", "b")}.to raise_error(ArgumentError)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,97 @@ | |
| 1 | 
            +
            # This file was generated by the `rspec --init` command. Conventionally, all
         | 
| 2 | 
            +
            # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
         | 
| 3 | 
            +
            # The generated `.rspec` file contains `--require spec_helper` which will cause
         | 
| 4 | 
            +
            # this file to always be loaded, without a need to explicitly require it in any
         | 
| 5 | 
            +
            # files.
         | 
| 6 | 
            +
            #
         | 
| 7 | 
            +
            # Given that it is always loaded, you are encouraged to keep this file as
         | 
| 8 | 
            +
            # light-weight as possible. Requiring heavyweight dependencies from this file
         | 
| 9 | 
            +
            # will add to the boot time of your test suite on EVERY test run, even for an
         | 
| 10 | 
            +
            # individual file that may not need all of that loaded. Instead, consider making
         | 
| 11 | 
            +
            # a separate helper file that requires the additional dependencies and performs
         | 
| 12 | 
            +
            # the additional setup, and require it from the spec files that actually need
         | 
| 13 | 
            +
            # it.
         | 
| 14 | 
            +
            #
         | 
| 15 | 
            +
            # The `.rspec` file also contains a few flags that are not defaults but that
         | 
| 16 | 
            +
            # users commonly want.
         | 
| 17 | 
            +
            #
         | 
| 18 | 
            +
            # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            $:<< File.join(File.dirname(__FILE__), '../lib/kangoroo_robot/')
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            RSpec.configure do |config|
         | 
| 23 | 
            +
              # rspec-expectations config goes here. You can use an alternate
         | 
| 24 | 
            +
              # assertion/expectation library such as wrong or the stdlib/minitest
         | 
| 25 | 
            +
              # assertions if you prefer.
         | 
| 26 | 
            +
              config.expect_with :rspec do |expectations|
         | 
| 27 | 
            +
                # This option will default to `true` in RSpec 4. It makes the `description`
         | 
| 28 | 
            +
                # and `failure_message` of custom matchers include text for helper methods
         | 
| 29 | 
            +
                # defined using `chain`, e.g.:
         | 
| 30 | 
            +
                #     be_bigger_than(2).and_smaller_than(4).description
         | 
| 31 | 
            +
                #     # => "be bigger than 2 and smaller than 4"
         | 
| 32 | 
            +
                # ...rather than:
         | 
| 33 | 
            +
                #     # => "be bigger than 2"
         | 
| 34 | 
            +
                expectations.include_chain_clauses_in_custom_matcher_descriptions = true
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              # rspec-mocks config goes here. You can use an alternate test double
         | 
| 38 | 
            +
              # library (such as bogus or mocha) by changing the `mock_with` option here.
         | 
| 39 | 
            +
              config.mock_with :rspec do |mocks|
         | 
| 40 | 
            +
                # Prevents you from mocking or stubbing a method that does not exist on
         | 
| 41 | 
            +
                # a real object. This is generally recommended, and will default to
         | 
| 42 | 
            +
                # `true` in RSpec 4.
         | 
| 43 | 
            +
                mocks.verify_partial_doubles = true
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              # Avoid printing 'put' messages in STDOUT when testing
         | 
| 47 | 
            +
              # config.before { allow($stdout).to receive(:puts) }
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            # The settings below are suggested to provide a good initial experience
         | 
| 50 | 
            +
            # with RSpec, but feel free to customize to your heart's content.
         | 
| 51 | 
            +
            =begin
         | 
| 52 | 
            +
              # These two settings work together to allow you to limit a spec run
         | 
| 53 | 
            +
              # to individual examples or groups you care about by tagging them with
         | 
| 54 | 
            +
              # `:focus` metadata. When nothing is tagged with `:focus`, all examples
         | 
| 55 | 
            +
              # get run.
         | 
| 56 | 
            +
              config.filter_run :focus
         | 
| 57 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              # Limits the available syntax to the non-monkey patched syntax that is
         | 
| 60 | 
            +
              # recommended. For more details, see:
         | 
| 61 | 
            +
              #   - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
         | 
| 62 | 
            +
              #   - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
         | 
| 63 | 
            +
              #   - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
         | 
| 64 | 
            +
              config.disable_monkey_patching!
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              # This setting enables warnings. It's recommended, but in some cases may
         | 
| 67 | 
            +
              # be too noisy due to issues in dependencies.
         | 
| 68 | 
            +
              config.warnings = true
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              # Many RSpec users commonly either run the entire suite or an individual
         | 
| 71 | 
            +
              # file, and it's useful to allow more verbose output when running an
         | 
| 72 | 
            +
              # individual spec file.
         | 
| 73 | 
            +
              if config.files_to_run.one?
         | 
| 74 | 
            +
                # Use the documentation formatter for detailed output,
         | 
| 75 | 
            +
                # unless a formatter has already been configured
         | 
| 76 | 
            +
                # (e.g. via a command-line flag).
         | 
| 77 | 
            +
                config.default_formatter = 'doc'
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              # Print the 10 slowest examples and example groups at the
         | 
| 81 | 
            +
              # end of the spec run, to help surface which specs are running
         | 
| 82 | 
            +
              # particularly slow.
         | 
| 83 | 
            +
              config.profile_examples = 10
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              # Run specs in random order to surface order dependencies. If you find an
         | 
| 86 | 
            +
              # order dependency and want to debug it, you can fix the order by providing
         | 
| 87 | 
            +
              # the seed, which is printed after each run.
         | 
| 88 | 
            +
              #     --seed 1234
         | 
| 89 | 
            +
              config.order = :random
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              # Seed global randomization in this process using the `--seed` CLI option.
         | 
| 92 | 
            +
              # Setting this allows you to use `--seed` to deterministically reproduce
         | 
| 93 | 
            +
              # test failures related to randomization by passing the same `--seed` value
         | 
| 94 | 
            +
              # as the one that triggered the failure.
         | 
| 95 | 
            +
              Kernel.srand config.seed
         | 
| 96 | 
            +
            =end
         | 
| 97 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kangoroo_robot
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Herve Tatche
         | 
| @@ -45,19 +45,37 @@ executables: [] | |
| 45 45 | 
             
            extensions: []
         | 
| 46 46 | 
             
            extra_rdoc_files: []
         | 
| 47 47 | 
             
            files:
         | 
| 48 | 
            -
            - ".gitignore"
         | 
| 49 | 
            -
            - ".rspec"
         | 
| 50 | 
            -
            - ".travis.yml"
         | 
| 51 48 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 52 | 
            -
            - Gemfile
         | 
| 53 | 
            -
            - LICENSE.txt
         | 
| 54 49 | 
             
            - README.md
         | 
| 55 | 
            -
            - Rakefile
         | 
| 56 50 | 
             
            - bin/console
         | 
| 51 | 
            +
            - bin/kangoroo_robot
         | 
| 57 52 | 
             
            - bin/setup
         | 
| 58 | 
            -
            - kangoroo_robot.gemspec
         | 
| 59 53 | 
             
            - lib/kangoroo_robot.rb
         | 
| 54 | 
            +
            - lib/kangoroo_robot/direction.rb
         | 
| 55 | 
            +
            - lib/kangoroo_robot/instruction.rb
         | 
| 56 | 
            +
            - lib/kangoroo_robot/instructions/left.rb
         | 
| 57 | 
            +
            - lib/kangoroo_robot/instructions/move.rb
         | 
| 58 | 
            +
            - lib/kangoroo_robot/instructions/place.rb
         | 
| 59 | 
            +
            - lib/kangoroo_robot/instructions/report.rb
         | 
| 60 | 
            +
            - lib/kangoroo_robot/instructions/right.rb
         | 
| 61 | 
            +
            - lib/kangoroo_robot/parser.rb
         | 
| 62 | 
            +
            - lib/kangoroo_robot/position.rb
         | 
| 63 | 
            +
            - lib/kangoroo_robot/robot.rb
         | 
| 64 | 
            +
            - lib/kangoroo_robot/table.rb
         | 
| 60 65 | 
             
            - lib/kangoroo_robot/version.rb
         | 
| 66 | 
            +
            - spec/lib/direction_spec.rb
         | 
| 67 | 
            +
            - spec/lib/instruction_spec.rb
         | 
| 68 | 
            +
            - spec/lib/instructions/left_spec.rb
         | 
| 69 | 
            +
            - spec/lib/instructions/move_spec.rb
         | 
| 70 | 
            +
            - spec/lib/instructions/place_spec.rb
         | 
| 71 | 
            +
            - spec/lib/instructions/report_spec.rb
         | 
| 72 | 
            +
            - spec/lib/instructions/right_spec.rb
         | 
| 73 | 
            +
            - spec/lib/kangoroo_robot_spec.rb
         | 
| 74 | 
            +
            - spec/lib/parser_spec.rb
         | 
| 75 | 
            +
            - spec/lib/position_spec.rb
         | 
| 76 | 
            +
            - spec/lib/robot_spec.rb
         | 
| 77 | 
            +
            - spec/lib/table_spec.rb
         | 
| 78 | 
            +
            - spec/spec_helper.rb
         | 
| 61 79 | 
             
            homepage: https://github.com/htatche/kangoroo_robot
         | 
| 62 80 | 
             
            licenses:
         | 
| 63 81 | 
             
            - MIT
         | 
| @@ -82,4 +100,17 @@ rubygems_version: 2.4.6 | |
| 82 100 | 
             
            signing_key: 
         | 
| 83 101 | 
             
            specification_version: 4
         | 
| 84 102 | 
             
            summary: Coding exercise for Lookahead
         | 
| 85 | 
            -
            test_files: | 
| 103 | 
            +
            test_files:
         | 
| 104 | 
            +
            - spec/lib/direction_spec.rb
         | 
| 105 | 
            +
            - spec/lib/instruction_spec.rb
         | 
| 106 | 
            +
            - spec/lib/instructions/left_spec.rb
         | 
| 107 | 
            +
            - spec/lib/instructions/move_spec.rb
         | 
| 108 | 
            +
            - spec/lib/instructions/place_spec.rb
         | 
| 109 | 
            +
            - spec/lib/instructions/report_spec.rb
         | 
| 110 | 
            +
            - spec/lib/instructions/right_spec.rb
         | 
| 111 | 
            +
            - spec/lib/kangoroo_robot_spec.rb
         | 
| 112 | 
            +
            - spec/lib/parser_spec.rb
         | 
| 113 | 
            +
            - spec/lib/position_spec.rb
         | 
| 114 | 
            +
            - spec/lib/robot_spec.rb
         | 
| 115 | 
            +
            - spec/lib/table_spec.rb
         | 
| 116 | 
            +
            - spec/spec_helper.rb
         | 
    
        data/.gitignore
    DELETED
    
    
    
        data/.rspec
    DELETED
    
    
    
        data/.travis.yml
    DELETED
    
    
    
        data/Gemfile
    DELETED
    
    
    
        data/LICENSE.txt
    DELETED
    
    | @@ -1,21 +0,0 @@ | |
| 1 | 
            -
            The MIT License (MIT)
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            Copyright (c) 2015 Herve Tatche
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            -
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            -
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            -
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            -
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            -
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            -
            all copies or substantial portions of the Software.
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            -
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            -
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            -
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            -
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            -
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            -
            THE SOFTWARE.
         | 
    
        data/Rakefile
    DELETED
    
    | @@ -1 +0,0 @@ | |
| 1 | 
            -
            require "bundler/gem_tasks"
         | 
    
        data/kangoroo_robot.gemspec
    DELETED
    
    | @@ -1,28 +0,0 @@ | |
| 1 | 
            -
            # coding: utf-8
         | 
| 2 | 
            -
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            -
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            -
            require 'kangoroo_robot/version'
         | 
| 5 | 
            -
             | 
| 6 | 
            -
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.name          = "kangoroo_robot"
         | 
| 8 | 
            -
              spec.version       = KangorooRobot::VERSION
         | 
| 9 | 
            -
              spec.authors       = ["Herve Tatche"]
         | 
| 10 | 
            -
              spec.email         = ["herve.tatche@gmail.com"]
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              spec.summary       = %q{Coding exercise for Lookahead}
         | 
| 13 | 
            -
              spec.description   = %q{Robot game controlled by giving him commands through the STDIN}
         | 
| 14 | 
            -
              spec.homepage      = "https://github.com/htatche/kangoroo_robot"
         | 
| 15 | 
            -
              spec.license       = "MIT"
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 18 | 
            -
              spec.bindir        = "exe"
         | 
| 19 | 
            -
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 20 | 
            -
              spec.require_paths = ["lib"]
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              # if spec.respond_to?(:metadata)
         | 
| 23 | 
            -
              #   spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
         | 
| 24 | 
            -
              # end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              spec.add_development_dependency "bundler", "~> 1.9"
         | 
| 27 | 
            -
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 28 | 
            -
            end
         |