maux_robot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 961e2b5489e001d3676b9a8f4360b212b62e677b
4
- data.tar.gz: '028a03a16e37befedecb9336b8d1a5f6c3cd78e1'
2
+ SHA256:
3
+ metadata.gz: 9c718637133d2a7b8dfb7d42fdcd754ce4eff6ec1fba93f7fe5ddaaa612d1cc1
4
+ data.tar.gz: 064f6ebc5ceefaa8dc44a2ff1f577178675cf362ffb77c3726c6e2ae6f62f1f1
5
5
  SHA512:
6
- metadata.gz: 1676475a44d162ae4038dc3862e380f81527caf621e3ea74e942ce3d431553476635373cffe05e9f4e468afea18ce5035e2c7d297bbfd3d57d645bf6fb1def11
7
- data.tar.gz: ff3e5c81d4c9d4d348b90d7e99e76e683fb14064c2bf4431203498b479de0e60a4d1c2da186a4e4b59f63590e2868c4c1d25e0a63d6bff37dd6abb5ebb591819
6
+ metadata.gz: 8cd5c5b6adfccdda316a95ac5f88cefbef598239ed2e981c47f10a70b63a0133af84b70b1effafa04dc0643efafa22bb183d8779d43630310e6068a6a854c370
7
+ data.tar.gz: 51e46cca8fc6e0239ae9c286611fc11e4589959d5338fac2317107fd2703e3112c201ca63e50bdda96aade74e1c2d71a78c02ff7d93f83b40009d9c41c4bed29
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/mauriciovieira/maux_robot.svg?branch=master)](https://travis-ci.org/mauriciovieira/maux_robot)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/b45a7baf1130fb9aa8f6/maintainability)](https://codeclimate.com/github/mauriciovieira/maux_robot/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/b45a7baf1130fb9aa8f6/test_coverage)](https://codeclimate.com/github/mauriciovieira/maux_robot/test_coverage)
2
4
 
3
5
  # maux_robot
4
6
 
@@ -105,4 +107,4 @@ The Toy Robot Challenge was originally formulated by [Jon Eaves](https://twitter
105
107
  **Mauricio Vieira (mauriciovieira)**
106
108
  + <http://mauriciovieira.net>
107
109
  + <https://twitter.com/mauriciovieira>
108
- + <https://github.com/mauriciovieira>
110
+ + <https://github.com/mauriciovieira>
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.unshift("#{__dir__}/../lib")
4
5
 
@@ -1,12 +1,14 @@
1
- require 'maux_robot/version'
2
- require 'maux_robot/cli'
3
- require 'maux_robot/formatter'
4
- require 'maux_robot/formatter/csv'
5
- require 'maux_robot/formatter/json'
6
- require 'maux_robot/parser'
7
- require 'maux_robot/position'
8
- require 'maux_robot/table'
9
- require 'maux_robot/robot'
1
+ # frozen_string_literal: true
2
+
3
+ require "maux_robot/version"
4
+ require "maux_robot/cli"
5
+ require "maux_robot/formatter"
6
+ require "maux_robot/formatter/csv"
7
+ require "maux_robot/formatter/json"
8
+ require "maux_robot/parser"
9
+ require "maux_robot/position"
10
+ require "maux_robot/table"
11
+ require "maux_robot/robot"
10
12
 
11
13
  module MauxRobot
12
- end
14
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MauxRobot
4
-
5
4
  # The CLI is a class responsible of handling command line interface
6
5
  class CLI
7
6
  attr_reader :robot
@@ -30,11 +29,11 @@ module MauxRobot
30
29
  end
31
30
 
32
31
  def execute(command)
33
- if command.has_key?(:arguments)
32
+ if command.key?(:arguments)
34
33
  @robot.send(command[:order], command[:arguments])
35
34
  else
36
35
  @robot.send(command[:order])
37
36
  end
38
37
  end
39
38
  end
40
- end
39
+ end
@@ -1,5 +1,6 @@
1
- module MauxRobot
1
+ # frozen_string_literal: true
2
2
 
3
+ module MauxRobot
3
4
  module Formatter
4
5
  def self.from(format_type)
5
6
  case format_type
@@ -10,4 +11,4 @@ module MauxRobot
10
11
  end
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MauxRobot::Formatter
4
-
5
- class Csv
6
- def generate(position)
7
- "#{position.x},#{position.y},#{position.face.upcase.to_s}"
3
+ module MauxRobot
4
+ module Formatter
5
+ class Csv
6
+ def generate(position)
7
+ "#{position.x},#{position.y},#{position.face.upcase}"
8
+ end
8
9
  end
9
10
  end
10
- end
11
+ end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
3
+ require "json"
4
4
 
5
- module MauxRobot::Formatter
6
-
7
- class Json
8
- def generate(position)
9
- JSON.generate({x: position.x, y: position.y, face: position.face.upcase.to_s})
5
+ module MauxRobot
6
+ module Formatter
7
+ class Json
8
+ def generate(position)
9
+ JSON.generate(
10
+ x: position.x,
11
+ y: position.y,
12
+ face: position.face.upcase.to_s
13
+ )
14
+ end
10
15
  end
11
16
  end
12
- end
17
+ end
@@ -1,26 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MauxRobot
4
-
5
4
  class Parser
6
5
  ALLOWED_ORDERS = %i[left right move place report verbose].freeze
7
6
 
8
7
  def parse(line_input)
9
- clean_input = line_input.strip.squeeze(' ').split(' ')
8
+ clean_input = line_input.strip.squeeze(" ").split(" ")
10
9
  order = sanitize_order(clean_input.shift)
11
10
  return unless order
12
11
 
13
- command = { order: order }
12
+ command = {order: order}
14
13
 
15
14
  if clean_input.any?
16
- arguments = sanitize_arguments(order, clean_input.join(''))
15
+ arguments = sanitize_arguments(order, clean_input.join(""))
17
16
  command[:arguments] = arguments
18
17
  end
19
18
 
20
19
  command
21
20
  end
22
21
 
23
-
24
22
  private
25
23
 
26
24
  def sanitize_order(input_string)
@@ -31,14 +29,11 @@ module MauxRobot
31
29
  def sanitize_arguments(order, arguments)
32
30
  case order
33
31
  when :place
34
- arguments = arguments.delete(' ').split(',')
35
- { x: arguments[0], y: arguments[1], face: arguments[2] }
32
+ arguments = arguments.delete(" ").split(",")
33
+ {x: arguments[0], y: arguments[1], face: arguments[2]}
36
34
  when :report
37
- { format_type: arguments.downcase.to_sym }
35
+ {format_type: arguments.downcase.to_sym}
38
36
  end
39
37
  end
40
38
  end
41
39
  end
42
-
43
-
44
-
@@ -1,22 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'maux_robot'
3
+ require "maux_robot"
4
4
 
5
5
  module MauxRobot
6
-
7
6
  # This class represents the Robot position on the table
8
7
  class Position
9
8
  attr_reader :x, :y, :face
10
9
 
11
- POSSIBLE_DIRECTIONS = [:north, :west, :south, :east]
10
+ POSSIBLE_DIRECTIONS = %i[north west south east].freeze
12
11
  POSSIBLE_MOVEMENTS = {
13
- north: { x: 0, y: 1 },
14
- west: { x: -1, y: 0 },
15
- south: { x: 0, y: -1 },
16
- east: { x: 1, y: 0 },
17
- }
12
+ north: {x: 0, y: 1},
13
+ west: {x: -1, y: 0},
14
+ south: {x: 0, y: -1},
15
+ east: {x: 1, y: 0}
16
+ }.freeze
18
17
 
19
- def initialize(x, y, face)
18
+ def initialize(x, y, face) # rubocop:disable Naming/UncommunicativeMethodParamName
20
19
  @x = x.to_i
21
20
  @y = y.to_i
22
21
  @face = face&.downcase&.to_sym || :invalid
@@ -28,13 +27,15 @@ module MauxRobot
28
27
 
29
28
  def left
30
29
  return self unless valid_direction?
31
- next_direction_index = ( POSSIBLE_DIRECTIONS.index(@face) + 1 ) % 4
30
+
31
+ next_direction_index = (POSSIBLE_DIRECTIONS.index(@face) + 1) % 4
32
32
  @face = POSSIBLE_DIRECTIONS[next_direction_index]
33
33
  end
34
34
 
35
35
  def right
36
36
  return self unless valid_direction?
37
- next_direction_index = ( POSSIBLE_DIRECTIONS.index(@face) - 1 )
37
+
38
+ next_direction_index = (POSSIBLE_DIRECTIONS.index(@face) - 1)
38
39
  @face = POSSIBLE_DIRECTIONS[next_direction_index]
39
40
  end
40
41
 
@@ -46,7 +47,7 @@ module MauxRobot
46
47
  Position.new(x, y, @face)
47
48
  end
48
49
 
49
- def report(format_type=:csv)
50
+ def report(format_type = :csv)
50
51
  formatter = MauxRobot::Formatter.from(format_type)
51
52
  puts formatter.generate(self)
52
53
  end
@@ -61,4 +62,4 @@ module MauxRobot
61
62
  super(nil, nil, nil)
62
63
  end
63
64
  end
64
- end
65
+ end
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
3
+ require "forwardable"
4
4
 
5
5
  module MauxRobot
6
-
7
6
  class RobotError < StandardError; end
8
7
 
9
8
  # Error to notify that the robot was not placed yet
10
9
  class RobotNotPlacedYet < RobotError
11
10
  def initialize
12
- super('The robot was not placed yet!')
11
+ super("The robot was not placed yet!")
13
12
  end
14
13
  end
15
14
 
@@ -24,18 +23,19 @@ module MauxRobot
24
23
  class Robot
25
24
  attr_reader :position, :talkative
26
25
 
27
- def initialize(table=MauxRobot::Table.new)
26
+ def initialize(table = MauxRobot::Table.new)
28
27
  @table = table
29
28
  @position = MauxRobot::NullPosition.new
30
29
  @talkative = false
31
30
  end
32
31
 
33
- def place(x:, y:, face:)
32
+ def place(x:, y:, face:) # rubocop:disable Naming/UncommunicativeMethodParamName
34
33
  position = MauxRobot::Position.new(x, y, face)
35
34
 
36
35
  ok_to_go?(position) do
37
36
  @position = position
38
37
  end
38
+ @position
39
39
  end
40
40
 
41
41
  def move
@@ -45,6 +45,8 @@ module MauxRobot
45
45
  ok_to_go?(next_position) do
46
46
  @position = next_position
47
47
  end
48
+
49
+ @position
48
50
  end
49
51
  end
50
52
 
@@ -68,26 +70,22 @@ module MauxRobot
68
70
 
69
71
  def verbose
70
72
  @talkative = !@talkative
71
- is_not = @talkative ? 'is' : 'is not'
73
+ is_not = @talkative ? "is" : "is not"
72
74
  puts "Robot #{is_not} talkative now."
73
75
  end
74
76
 
75
77
  private
76
78
 
77
79
  def ok_to_go?(position)
78
- if @table.contains?(position)
79
- yield
80
- else
81
- raise NotOkToGo.new(position)
82
- end
80
+ raise NotOkToGo, position unless @table.contains?(position)
81
+
82
+ yield
83
83
  end
84
84
 
85
85
  def robot_placed?
86
- unless @position.class == MauxRobot::NullPosition
87
- yield
88
- else
89
- raise RobotNotPlacedYet
90
- end
86
+ raise RobotNotPlacedYet if @position.class == MauxRobot::NullPosition
87
+
88
+ yield
91
89
  end
92
90
  end
93
- end
91
+ end
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MauxRobot
4
-
5
4
  # This class represents a table according to simulation rules
6
5
  class Table
7
- def initialize(x: [0, 4], y: [0, 4])
6
+ def initialize(x: [0, 4], y: [0, 4]) # rubocop:disable Naming/UncommunicativeMethodParamName
8
7
  @x = x
9
8
  @y = y
10
9
  end
@@ -3,14 +3,14 @@
3
3
  module MauxRobot
4
4
  # This module holds the MauxRobot version information.
5
5
  module Version
6
- STRING = '0.1.0'.freeze
6
+ STRING = "0.2.0"
7
7
 
8
- MSG = '%s (using Parser %s, running on %s %s %s)'.freeze
8
+ MSG = "%s (using Parser %s, running on %s %s %s)"
9
9
 
10
10
  def self.version(debug = false)
11
11
  if debug
12
12
  format(MSG, STRING, Parser::VERSION,
13
- RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM)
13
+ RUBY_ENGINE, RUBY_VERSION, RUBY_PLATFORM)
14
14
  else
15
15
  STRING
16
16
  end
@@ -1,21 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'maux_robot'
3
+ require "maux_robot"
4
4
 
5
5
  describe MauxRobot::CLI do
6
+ subject(:cli) { described_class.new }
6
7
 
7
- describe '#execute' do
8
- context 'parsed input without arguments' do
9
- it 'should send proper message to robot' do
10
- expect(subject.robot).to receive(:move)
11
- subject.execute(order: :move)
8
+ describe "#execute" do
9
+ let(:position) { MauxRobot::Position.new(0, 2, :east) }
10
+
11
+ context "when input is parsed without arguments" do
12
+ it "sends proper message to robot" do
13
+ allow(cli.robot).to receive(:move).and_return(position)
14
+ expect(cli.execute(order: :move)).to eq(position)
12
15
  end
13
16
  end
14
17
 
15
- context 'parsed place command with arguments' do
16
- it 'should send proper message to robot' do
17
- expect(subject.robot).to receive(:place).with(x: '0', y: '2', face: 'EAST')
18
- subject.execute(order: :place, arguments: { x: '0', y: '2', face: 'EAST' })
18
+ context "when place is parsed command with arguments" do
19
+ it "sends proper message to robot" do
20
+ expect(cli.execute(order: :place, arguments: {x: "0", y: "2", face: "EAST"})).to eq(position)
19
21
  end
20
22
  end
21
23
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe MauxRobot::Formatter::Csv do
4
- let (:position) {MauxRobot::Position.new(1,2,:west)}
4
+ let(:position) { MauxRobot::Position.new(1, 2, :west) }
5
+
6
+ describe "#generate" do
7
+ subject(:csv_formatter) { described_class.new }
5
8
 
6
- context '#generate' do
7
9
  it "Formats a position as CSV" do
8
- expect(subject.generate(position)).to eq('1,2,WEST')
10
+ expect(csv_formatter.generate(position)).to eq("1,2,WEST")
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe MauxRobot::Formatter::Json do
4
- let (:position) {MauxRobot::Position.new(1,2,:west)}
4
+ let(:position) { MauxRobot::Position.new(1, 2, :west) }
5
+
6
+ describe "#generate" do
7
+ subject(:json_formatter) { described_class.new }
5
8
 
6
- context '#generate' do
7
9
  it "Formats a position as JSON" do
8
- expect(subject.generate(position)).to eq('{"x":1,"y":2,"face":"WEST"}')
10
+ expect(json_formatter.generate(position)).to eq('{"x":1,"y":2,"face":"WEST"}')
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -1,21 +1,23 @@
1
- # frozen_string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe MauxRobot::Formatter do
4
- context "#from" do
4
+ subject(:formatter) { described_class }
5
+
6
+ describe "#from" do
5
7
  describe "valid format_types" do
6
8
  it "returns csv formatter" do
7
- expect(subject.from(:csv).class).to eq(MauxRobot::Formatter::Csv)
9
+ expect(formatter.from(:csv).class).to eq(MauxRobot::Formatter::Csv)
8
10
  end
9
11
 
10
- it 'returns json formatter' do
11
- expect(subject.from(:json).class).to eq(MauxRobot::Formatter::Json)
12
+ it "returns json formatter" do
13
+ expect(formatter.from(:json).class).to eq(MauxRobot::Formatter::Json)
12
14
  end
13
15
  end
14
16
 
15
- describe 'invalid format_types' do
16
- it 'defaults to csv formatter' do
17
- expect(subject.from(:anything).class).to eq(MauxRobot::Formatter::Csv)
17
+ describe "invalid format_types" do
18
+ it "defaults to csv formatter" do
19
+ expect(formatter.from(:anything).class).to eq(MauxRobot::Formatter::Csv)
18
20
  end
19
21
  end
20
22
  end
21
- end
23
+ end
@@ -1,67 +1,73 @@
1
- # frozen_string_literal: true
1
+ # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Metrics/BlockLength
3
4
  describe MauxRobot::Parser do
4
- describe '#parse' do
5
- context 'valid orders' do
6
- it '#report' do
7
- expect(subject.parse('REPORT')).to eq(order: :report)
5
+ subject(:parser) { described_class.new }
6
+
7
+ describe "#parse" do
8
+ context "with valid orders" do
9
+ it "#report" do
10
+ expect(parser.parse("REPORT")).to eq(order: :report)
8
11
  end
9
12
 
10
- it '#report csv' do
11
- expect(subject.parse('REPORT CSV')).to eq(order: :report, arguments: { format_type: :csv })
13
+ it "#report csv" do
14
+ expect(parser.parse("REPORT CSV")).to eq(order: :report, arguments: {format_type: :csv})
12
15
  end
13
16
 
14
- it '#report json' do
15
- expect(subject.parse('REPORT JSON')).to eq(order: :report, arguments: { format_type: :json })
17
+ it "#report json" do
18
+ expect(parser.parse("REPORT JSON")).to eq(order: :report, arguments: {format_type: :json})
16
19
  end
17
20
 
18
- it '#move' do
19
- expect(subject.parse('MOVE')).to eq(order: :move)
21
+ it "#move" do
22
+ expect(parser.parse("MOVE")).to eq(order: :move)
20
23
  end
21
24
 
22
- it '#left' do
23
- expect(subject.parse('LEFT')).to eq(order: :left)
25
+ it "#left" do
26
+ expect(parser.parse("LEFT")).to eq(order: :left)
24
27
  end
25
28
 
26
- it '#right' do
27
- expect(subject.parse('RIGHT')).to eq(order: :right)
29
+ it "#right" do
30
+ expect(parser.parse("RIGHT")).to eq(order: :right)
28
31
  end
29
32
 
30
- it '#verbose' do
31
- expect(subject.parse('VERBOSE')).to eq(order: :verbose)
33
+ it "#verbose" do
34
+ expect(parser.parse("VERBOSE")).to eq(order: :verbose)
32
35
  end
33
36
 
34
- it '#place' do
35
- expect(subject.parse('PLACE 0,3,WEST')).to eq(order: :place, arguments: { x: '0', y: '3', face: 'WEST' })
37
+ it "#place" do
38
+ expect(parser.parse("PLACE 0,3,WEST")).to eq(order: :place, arguments: {x: "0", y: "3", face: "WEST"})
36
39
  end
37
40
  end
38
41
 
39
- context 'orders with spaces and downcase' do
40
- it '#report' do
41
- expect(subject.parse(' repoRT')).to eq(order: :report)
42
+ context "with orders with spaces and downcase" do
43
+ it "#report" do
44
+ expect(parser.parse(" repoRT")).to eq(order: :report)
42
45
  end
43
46
 
44
- it '#move' do
45
- expect(subject.parse('move ')).to eq(order: :move)
47
+ it "#move" do
48
+ expect(parser.parse("move ")).to eq(order: :move)
46
49
  end
47
50
 
48
- it '#left' do
49
- expect(subject.parse(' LefT ')).to eq(order: :left)
51
+ it "#left" do
52
+ expect(parser.parse(" LefT ")).to eq(order: :left)
50
53
  end
51
54
 
52
- it '#right' do
53
- expect(subject.parse(' rigHt')).to eq(order: :right)
55
+ it "#right" do
56
+ expect(parser.parse(" rigHt")).to eq(order: :right)
54
57
  end
55
58
 
56
- it '#place' do
57
- expect(subject.parse('PLACE 2 , 1 , NOrth')).to eq(order: :place, arguments: { x: '2', y: '1', face: 'NOrth' })
59
+ it "#place" do
60
+ expect(parser.parse("PLACE 2 , 1 , NOrth")).to eq(
61
+ order: :place, arguments: {x: "2", y: "1", face: "NOrth"}
62
+ )
58
63
  end
59
64
  end
60
65
 
61
- context 'invalid orders' do
62
- it 'ignores anything else' do
63
- expect(subject.parse('blablabla balbla')).to be_nil
66
+ context "with invalid orders" do
67
+ it "ignores anything else" do
68
+ expect(parser.parse("blablabla balbla")).to be_nil
64
69
  end
65
70
  end
66
71
  end
67
- end
72
+ end
73
+ # rubocop:enable Metrics/BlockLength
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Metrics/BlockLength:
3
4
  describe MauxRobot::Position do
4
- describe '#initialize' do
5
- context 'given text input' do
6
- it 'should normalize arguments' do
7
- position = MauxRobot::Position.new('0', '1', 'SOUTH')
5
+ describe "#initialize" do
6
+ context "when text input is given" do
7
+ it "normalizes arguments" do
8
+ position = described_class.new("0", "1", "SOUTH")
8
9
 
9
10
  expect(position.x).to eq(0)
10
11
  expect(position.y).to eq(1)
@@ -13,29 +14,29 @@ describe MauxRobot::Position do
13
14
  end
14
15
  end
15
16
 
16
- describe '#valid_direction?' do
17
- context 'given a possible diretion' do
18
- it 'should be valid' do
19
- position = MauxRobot::Position.new(5, 0, :south)
17
+ describe "#valid_direction?" do
18
+ context "when a possible diretion is given" do
19
+ it "is valid" do
20
+ position = described_class.new(5, 0, :south)
20
21
 
21
22
  expect(position.valid_direction?).to eq(true)
22
23
  end
23
24
  end
24
25
 
25
- context 'given a not possible direction' do
26
- it 'should not be valid ' do
27
- position = MauxRobot::Position.new(1, 1, :south_west)
26
+ context "when a not possible direction is given" do
27
+ it "is not valid " do
28
+ position = described_class.new(1, 1, :south_west)
28
29
 
29
30
  expect(position.valid_direction?).to eq(false)
30
31
  end
31
32
  end
32
33
  end
33
34
 
34
- describe 'rotation' do
35
- let(:position) { MauxRobot::Position.new(2, 2, :north) }
35
+ describe "rotation" do
36
+ let(:position) { described_class.new(2, 2, :north) }
36
37
 
37
- context '#left' do
38
- it 'should rotate counter-clockwise' do
38
+ describe "#left" do
39
+ it "rotates counter-clockwise" do
39
40
  position.left
40
41
  expect(position.face).to eq(:west)
41
42
 
@@ -50,8 +51,8 @@ describe MauxRobot::Position do
50
51
  end
51
52
  end
52
53
 
53
- context '#right' do
54
- it 'should rotate clockwise' do
54
+ describe "#right" do
55
+ it "rotates clockwise" do
55
56
  position.right
56
57
  expect(position.face).to eq(:east)
57
58
 
@@ -67,11 +68,11 @@ describe MauxRobot::Position do
67
68
  end
68
69
  end
69
70
 
70
- describe '#forward_position' do
71
- context 'facing north' do
72
- let(:position) { MauxRobot::Position.new(5, 0, :north) }
71
+ describe "#forward_position" do # rubocop:disable Metrics/BlockLength
72
+ context "when facing north" do
73
+ let(:position) { described_class.new(5, 0, :north) }
73
74
 
74
- it 'should return a new position 1 step upwards' do
75
+ it "returns a new position 1 step upwards" do
75
76
  new_position = position.forward_position
76
77
  expect(position.x).to eq(5)
77
78
  expect(position.y).to eq(0)
@@ -80,10 +81,10 @@ describe MauxRobot::Position do
80
81
  end
81
82
  end
82
83
 
83
- context 'facing west' do
84
- let(:position) { MauxRobot::Position.new(2, 1, :west) }
84
+ context "when facing west" do
85
+ let(:position) { described_class.new(2, 1, :west) }
85
86
 
86
- it 'should return a new position 1 step leftwards' do
87
+ it "returns a new position 1 step leftwards" do
87
88
  new_position = position.forward_position
88
89
  expect(position.x).to eq(2)
89
90
  expect(position.y).to eq(1)
@@ -92,10 +93,10 @@ describe MauxRobot::Position do
92
93
  end
93
94
  end
94
95
 
95
- context 'facing south' do
96
- let(:position) { MauxRobot::Position.new(1, 3, :south) }
96
+ context "when facing south" do
97
+ let(:position) { described_class.new(1, 3, :south) }
97
98
 
98
- it 'should return a new position 1 step downwards' do
99
+ it "returns a new position 1 step downwards" do
99
100
  new_position = position.forward_position
100
101
  expect(position.x).to eq(1)
101
102
  expect(position.y).to eq(3)
@@ -104,10 +105,10 @@ describe MauxRobot::Position do
104
105
  end
105
106
  end
106
107
 
107
- context 'facing east' do
108
- let(:position) { MauxRobot::Position.new(2, 0, :east) }
108
+ context "when facing east" do
109
+ let(:position) { described_class.new(2, 0, :east) }
109
110
 
110
- it 'should return a new position 1 step rightwards' do
111
+ it "returns a new position 1 step rightwards" do
111
112
  new_position = position.forward_position
112
113
  expect(position.x).to eq(2)
113
114
  expect(position.y).to eq(0)
@@ -117,27 +118,30 @@ describe MauxRobot::Position do
117
118
  end
118
119
  end
119
120
 
120
- describe '#report' do
121
- context 'if x, y and face are defined' do
122
- let(:position) { MauxRobot::Position.new(5, 0, :north) }
121
+ describe "#report" do
122
+ context "when x, y and face are defined" do
123
+ let(:position) { described_class.new(5, 0, :north) }
123
124
 
124
- it 'prints X,Y,FACE' do
125
+ it "prints X,Y,FACE" do
125
126
  expect { position.report }.to output("5,0,NORTH\n").to_stdout
126
127
  end
127
128
  end
128
129
 
129
- context 'if only face is defined' do
130
- let(:position) { MauxRobot::Position.new(nil, nil, 'SOUTH') }
131
- it 'prints 0,0,FACE' do
130
+ context "when only face is defined" do
131
+ let(:position) { described_class.new(nil, nil, "SOUTH") }
132
+
133
+ it "prints 0,0,FACE" do
132
134
  expect { position.report }.to output("0,0,SOUTH\n").to_stdout
133
135
  end
134
136
  end
135
137
 
136
- context 'if face is not defined' do
137
- let(:position) { MauxRobot::Position.new(5, 0, nil) }
138
- it 'prints X,Y,INVALID' do
138
+ context "when face is not defined" do
139
+ let(:position) { described_class.new(5, 0, nil) }
140
+
141
+ it "prints X,Y,INVALID" do
139
142
  expect { position.report }.to output("5,0,INVALID\n").to_stdout
140
143
  end
141
144
  end
142
145
  end
143
146
  end
147
+ # rubocop:enable Metrics/BlockLength:
@@ -1,41 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe MauxRobot::Robot do
3
+ describe MauxRobot::Robot do # rubocop:disable Metrics/BlockLength
4
4
  subject(:robot) { described_class.new }
5
+
5
6
  let(:null_position) { MauxRobot::NullPosition.new }
6
7
 
7
- describe '#place' do
8
- context 'given a valid place' do
9
- it 'should have a position' do
8
+ describe "#place" do
9
+ context "when given a valid place" do
10
+ it "has a position" do
10
11
  robot.place(x: 0, y: 0, face: :north)
11
12
 
12
13
  expect(robot.position).not_to eq null_position
13
14
  end
14
15
  end
15
16
 
16
- context 'given an invalid place' do
17
- it 'should raise NotOkToGo error' do
17
+ context "when given an invalid place" do
18
+ it "raises NotOkToGo error" do
18
19
  expect { robot.place(x: 5, y: 0, face: :south) }.to raise_error MauxRobot::NotOkToGo
19
20
  end
20
21
  end
21
22
 
22
- context 'given an invalid direction' do
23
- it 'should raise NotOkToGo error' do
23
+ context "when given an invalid direction" do
24
+ it "raises NotOkToGo error" do
24
25
  expect { robot.place(x: 0, y: 2, face: :south_east) }.to raise_error MauxRobot::NotOkToGo
25
26
  end
26
27
  end
27
28
  end
28
29
 
29
- describe '#left' do
30
- context 'robot not placed' do
31
- it 'should raise RobotNotPlacedYet error' do
30
+ describe "#left" do
31
+ context "when robot is not placed" do
32
+ it "raises RobotNotPlacedYet error" do
32
33
  expect { robot.left }.to raise_error MauxRobot::RobotNotPlacedYet
33
34
  expect(robot.position).to eq null_position
34
35
  end
35
36
  end
36
37
 
37
- context 'robot placed' do
38
- it 'should rotate accordingly' do
38
+ context "when robot is placed" do
39
+ it "rotates accordingly" do
39
40
  robot.place(x: 1, y: 2, face: :south)
40
41
  robot.left
41
42
 
@@ -44,17 +45,17 @@ describe MauxRobot::Robot do
44
45
  end
45
46
  end
46
47
 
47
- describe '#right' do
48
- context 'robot not placed' do
49
- it 'should raise RobotNotPlacedYet error' do
48
+ describe "#right" do
49
+ context "when robot is not placed" do
50
+ it "raises RobotNotPlacedYet error" do
50
51
  expect { robot.right }.to raise_error MauxRobot::RobotNotPlacedYet
51
52
 
52
53
  expect(robot.position).to eq null_position
53
54
  end
54
55
  end
55
56
 
56
- context 'robot placed' do
57
- it 'should rotate accordingly' do
57
+ context "with robot placed" do
58
+ it "rotates accordingly" do
58
59
  robot.place(x: 3, y: 2, face: :north)
59
60
  robot.right
60
61
 
@@ -63,16 +64,16 @@ describe MauxRobot::Robot do
63
64
  end
64
65
  end
65
66
 
66
- describe '#move' do
67
- context 'robot not placed' do
68
- it 'should raise RobotNotPlacedYet error' do
67
+ describe "#move" do
68
+ context "with robot not placed" do
69
+ it "raises RobotNotPlacedYet error" do
69
70
  expect { robot.right }.to raise_error MauxRobot::RobotNotPlacedYet
70
71
  expect(robot.position).to eq null_position
71
72
  end
72
73
  end
73
74
 
74
- context 'to a place on the table' do
75
- it 'should update its position' do
75
+ context "when placing on the table" do
76
+ it "updates its position" do
76
77
  robot.place(x: 3, y: 2, face: :north)
77
78
  robot.move
78
79
 
@@ -82,8 +83,8 @@ describe MauxRobot::Robot do
82
83
  end
83
84
  end
84
85
 
85
- context 'to outside the table' do
86
- it 'should stay where it is' do
86
+ context "when outside the table" do
87
+ it "stays where it is" do
87
88
  robot.place(x: 0, y: 0, face: :south)
88
89
 
89
90
  expect { robot.move }.to raise_error MauxRobot::NotOkToGo
@@ -3,13 +3,13 @@
3
3
  describe MauxRobot::Table do
4
4
  subject(:table) { described_class.new(x: [-1, 2], y: [3, 6]) }
5
5
 
6
- context '#contains?' do
7
- it 'should contain a position inside boundaries' do
6
+ describe "#contains?" do
7
+ it "contains a position inside boundaries" do
8
8
  position = MauxRobot::Position.new(0, 4, :north)
9
9
  expect(table.contains?(position)).to be true
10
10
  end
11
11
 
12
- it 'should not contain a position outside boundaries' do
12
+ it "does not contain a position outside boundaries" do
13
13
  position = MauxRobot::Position.new(3, 2, :east)
14
14
  expect(table.contains?(position)).to be false
15
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift("#{__dir__}/../lib")
2
4
 
3
- require 'maux_robot'
5
+ require "maux_robot"
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maux_robot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-28 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: standard
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.6'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 3.6.0
19
+ version: 0.4.7
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '3.6'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 3.6.0
26
+ version: 0.4.7
33
27
  description: " Maux version of a Toy Robot Simulator.\n"
34
28
  email: maux_robot@mauriciovieira.net
35
29
  executables:
@@ -78,15 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
72
  requirements:
79
73
  - - ">="
80
74
  - !ruby/object:Gem::Version
81
- version: 2.0.0
75
+ version: 2.6.0
82
76
  required_rubygems_version: !ruby/object:Gem::Requirement
83
77
  requirements:
84
78
  - - ">="
85
79
  - !ruby/object:Gem::Version
86
80
  version: '0'
87
81
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.6.12
82
+ rubygems_version: 3.0.3
90
83
  signing_key:
91
84
  specification_version: 4
92
85
  summary: Maux version of a Toy Robot Simulator.