maux_robot 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +104 -0
- data/bin/maux_robot +8 -0
- data/lib/maux_robot.rb +5 -0
- data/lib/maux_robot/cli.rb +61 -0
- data/lib/maux_robot/position.rb +49 -0
- data/lib/maux_robot/robot.rb +41 -0
- data/lib/maux_robot/table.rb +17 -0
- data/lib/maux_robot/version.rb +19 -0
- data/spec/maux_robot/cli_spec.rb +71 -0
- data/spec/maux_robot/position_spec.rb +144 -0
- data/spec/maux_robot/robot_spec.rb +97 -0
- data/spec/maux_robot/table_spec.rb +19 -0
- metadata +84 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'maux_robot'
|
4
|
+
|
5
|
+
describe MauxRobot::Robot do
|
6
|
+
subject(:robot) { described_class.new }
|
7
|
+
|
8
|
+
describe '#place' do
|
9
|
+
context 'given a valid place' do
|
10
|
+
it 'should have a position' do
|
11
|
+
robot.place(x: 0, y: 0, face: :north)
|
12
|
+
|
13
|
+
expect(robot.position).not_to be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'given an invalid place' do
|
18
|
+
it 'should not have a position' do
|
19
|
+
robot.place(x: 5, y: 0, face: :south)
|
20
|
+
|
21
|
+
expect(robot.position).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'given an invalid direction' do
|
26
|
+
it 'should not have a position' do
|
27
|
+
robot.place(x: 0, y: 2, face: :south_east)
|
28
|
+
|
29
|
+
expect(robot.position).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#left' do
|
35
|
+
context 'robot not placed' do
|
36
|
+
it 'should silently ignore' do
|
37
|
+
robot.place(x: 0, y: 2, face: :south_east)
|
38
|
+
robot.left
|
39
|
+
|
40
|
+
expect(robot.position).to be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'robot placed' do
|
45
|
+
it 'should rotate accordingly' do
|
46
|
+
robot.place(x: 1, y: 2, face: :south)
|
47
|
+
robot.left
|
48
|
+
|
49
|
+
expect(robot.position.face).to be(:east)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#right' do
|
55
|
+
context 'robot not placed' do
|
56
|
+
it 'should silently ignore' do
|
57
|
+
robot.place(x: 0, y: 2, face: :north_west)
|
58
|
+
robot.right
|
59
|
+
|
60
|
+
expect(robot.position).to be_nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'robot placed' do
|
65
|
+
it 'should rotate accordingly' do
|
66
|
+
robot.place(x: 3, y: 2, face: :north)
|
67
|
+
robot.right
|
68
|
+
|
69
|
+
expect(robot.position.face).to be(:east)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#move' do
|
75
|
+
context 'to a place on the table' do
|
76
|
+
it 'should update its position' do
|
77
|
+
robot.place(x: 3, y: 2, face: :north)
|
78
|
+
robot.move
|
79
|
+
|
80
|
+
expect(robot.position.x).to eq(3)
|
81
|
+
expect(robot.position.y).to eq(3)
|
82
|
+
expect(robot.position.face).to eq(:north)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'to outside the table' do
|
87
|
+
it 'should stay where it is' do
|
88
|
+
robot.place(x: 0, y: 0, face: :south)
|
89
|
+
robot.move
|
90
|
+
|
91
|
+
expect(robot.position.x).to eq(0)
|
92
|
+
expect(robot.position.y).to eq(0)
|
93
|
+
expect(robot.position.face).to eq(:south)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'maux_robot'
|
4
|
+
|
5
|
+
describe MauxRobot::Table do
|
6
|
+
subject(:table) { described_class.new(x: [-1, 2], y: [3, 6]) }
|
7
|
+
|
8
|
+
context '#contains?' do
|
9
|
+
it 'should contain a position inside boundaries' do
|
10
|
+
position = MauxRobot::Position.new(0, 4, :north)
|
11
|
+
expect(table.contains?(position)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not contain a position outside boundaries' do
|
15
|
+
position = MauxRobot::Position.new(3, 2, :east)
|
16
|
+
expect(table.contains?(position)).to be false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maux_robot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mauricio Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.6'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.6.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.6'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.6.0
|
33
|
+
description: " Maux version of a Toy Robot Simulator.\n"
|
34
|
+
email: maux_robot@mauriciovieira.net
|
35
|
+
executables:
|
36
|
+
- maux_robot
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
files:
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
- bin/maux_robot
|
45
|
+
- lib/maux_robot.rb
|
46
|
+
- lib/maux_robot/cli.rb
|
47
|
+
- lib/maux_robot/position.rb
|
48
|
+
- lib/maux_robot/robot.rb
|
49
|
+
- lib/maux_robot/table.rb
|
50
|
+
- lib/maux_robot/version.rb
|
51
|
+
- spec/maux_robot/cli_spec.rb
|
52
|
+
- spec/maux_robot/position_spec.rb
|
53
|
+
- spec/maux_robot/robot_spec.rb
|
54
|
+
- spec/maux_robot/table_spec.rb
|
55
|
+
homepage: https://github.com/mauriciovieira/maux_robot
|
56
|
+
licenses:
|
57
|
+
- GPL-3.0
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://rubocop.readthedocs.io/
|
60
|
+
changelog_uri: https://github.com/mauriciovieira/maux_robot/blob/master/CHANGELOG.md
|
61
|
+
source_code_uri: https://github.com/mauriciovieira/maux_robot/
|
62
|
+
documentation_uri: https://github.com/mauriciovieira/maux_robot/
|
63
|
+
bug_tracker_uri: https://github.com/mauriciovieira/maux_robot/issues
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.0.0
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.6.12
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Maux version of a Toy Robot Simulator.
|
84
|
+
test_files: []
|