robodog 0.0.1
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 +7 -0
- data/.gitignore +34 -0
- data/CONTRIBUTING.md +27 -0
- data/LICENSE +25 -0
- data/README.md +302 -0
- data/bin/robodog +5 -0
- data/data/fail_input_a.txt +5 -0
- data/data/valid_input_a.txt +5 -0
- data/lib/robo_dog.rb +1 -0
- data/lib/robo_dog/application.rb +37 -0
- data/lib/robo_dog/paddock.rb +31 -0
- data/lib/robo_dog/parser.rb +53 -0
- data/lib/robo_dog/pose.rb +97 -0
- data/lib/robo_dog/pose/orientation.rb +38 -0
- data/lib/robo_dog/robot.rb +88 -0
- data/lib/robo_dog/simulation.rb +60 -0
- data/robodog.gemspec +19 -0
- data/spec/application_spec.rb +24 -0
- data/spec/features/robo_dog_spec.rb +107 -0
- data/spec/orientation_spec.rb +37 -0
- data/spec/paddock_spec.rb +50 -0
- data/spec/parser_spec.rb +74 -0
- data/spec/pose_spec.rb +164 -0
- data/spec/robot_spec.rb +166 -0
- data/spec/simulation_spec.rb +131 -0
- metadata +92 -0
@@ -0,0 +1,131 @@
|
|
1
|
+
require_relative '../lib/robo_dog/simulation'
|
2
|
+
|
3
|
+
RSpec.describe RoboDog::Simulation do
|
4
|
+
describe 'the public interface' do
|
5
|
+
subject{ described_class.new }
|
6
|
+
it { is_expected.to respond_to :run, :report, :valid_coordinates? }
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:simulation) { described_class.new(robots: robots) }
|
10
|
+
|
11
|
+
describe '#run' do
|
12
|
+
let(:robots) do
|
13
|
+
_robots = [double, double]
|
14
|
+
_robots.each_with_index do |robot, i|
|
15
|
+
allow(robot).to receive(:add_coordinator)
|
16
|
+
allow(robot).to receive(:coordinates).and_return(i)
|
17
|
+
allow(robot).to receive(:execute).with(:all)
|
18
|
+
end
|
19
|
+
_robots
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with valid coordiantes for robots' do
|
23
|
+
it 'commands robots to add self as coordinator' do
|
24
|
+
robots.each_with_index do |robot, i|
|
25
|
+
expect(robot).to receive(:add_coordinator)
|
26
|
+
end
|
27
|
+
|
28
|
+
simulation.run
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'executes each robot' do
|
32
|
+
robots.each_with_index do |robot, i|
|
33
|
+
expect(robot).to receive(:execute).with(:all)
|
34
|
+
end
|
35
|
+
|
36
|
+
simulation.run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with robots placed on top of each other' do
|
41
|
+
let(:robots) do
|
42
|
+
_robots = [double, double]
|
43
|
+
_robots.each do |robot|
|
44
|
+
allow(robot).to receive(:coordinates).and_return(1)
|
45
|
+
end
|
46
|
+
_robots
|
47
|
+
end
|
48
|
+
it 'fails' do
|
49
|
+
expect { simulation.run }.to raise_exception RuntimeError
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#report' do
|
55
|
+
let(:robot_double) do
|
56
|
+
dbl = double
|
57
|
+
allow(dbl).to receive(:add_coordinator)
|
58
|
+
allow(dbl).to receive(:report).and_return('robot report')
|
59
|
+
dbl
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:robots) { [robot_double] }
|
63
|
+
|
64
|
+
subject { simulation.report }
|
65
|
+
|
66
|
+
it 'returns a hash' do
|
67
|
+
is_expected.to be_instance_of Hash
|
68
|
+
end
|
69
|
+
|
70
|
+
it "includes robot's reports" do
|
71
|
+
is_expected.to include robots: ['robot report']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#valid_coordinates?' do
|
76
|
+
|
77
|
+
let(:simulation) { described_class.new(robots: [robot], paddock: paddock) }
|
78
|
+
|
79
|
+
let(:paddock) { double }
|
80
|
+
let(:robot) do
|
81
|
+
dbl = double
|
82
|
+
allow(dbl).to receive(:add_coordinator)
|
83
|
+
dbl
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'without coordinates object' do
|
87
|
+
it 'fails' do
|
88
|
+
expect { simulation.valid_coordinates?(nil) }.to raise_exception RuntimeError
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'with coordinates object' do
|
93
|
+
|
94
|
+
context 'with invalid paddock coordinates' do
|
95
|
+
let (:paddock) do
|
96
|
+
dbl = double
|
97
|
+
allow(dbl).to receive(:valid_coordinates?).and_return(false)
|
98
|
+
dbl
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'fails' do
|
102
|
+
expect { simulation.valid_coordinates?('some coordinates') }.to raise_exception RuntimeError
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with valid paddock coordinate' do
|
107
|
+
let (:paddock) do
|
108
|
+
dbl = double
|
109
|
+
allow(dbl).to receive(:valid_coordinates?).and_return(true)
|
110
|
+
dbl
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with no other robot in coordinates' do
|
114
|
+
it 'returns truthy' do
|
115
|
+
allow(robot).to receive(:coordinates).and_return('some coordinate')
|
116
|
+
|
117
|
+
expect(simulation.valid_coordinates?('other coordinates')).to be_truthy
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'with other robot in coordinates' do
|
122
|
+
it 'fails' do
|
123
|
+
allow(robot).to receive(:coordinates).and_return('same coordinates')
|
124
|
+
|
125
|
+
expect { simulation.valid_coordinates?('same coordinates') }.to raise_exception RuntimeError
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: robodog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matias Anaya
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-23 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.1'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
description: Fredwina the Farmer's robotic sheep dog simulator, used for the shock
|
28
|
+
and awe showcase.
|
29
|
+
email:
|
30
|
+
- matiasanaya@gmail.com
|
31
|
+
executables:
|
32
|
+
- robodog
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- CONTRIBUTING.md
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- bin/robodog
|
41
|
+
- data/fail_input_a.txt
|
42
|
+
- data/valid_input_a.txt
|
43
|
+
- lib/robo_dog.rb
|
44
|
+
- lib/robo_dog/application.rb
|
45
|
+
- lib/robo_dog/paddock.rb
|
46
|
+
- lib/robo_dog/parser.rb
|
47
|
+
- lib/robo_dog/pose.rb
|
48
|
+
- lib/robo_dog/pose/orientation.rb
|
49
|
+
- lib/robo_dog/robot.rb
|
50
|
+
- lib/robo_dog/simulation.rb
|
51
|
+
- robodog.gemspec
|
52
|
+
- spec/application_spec.rb
|
53
|
+
- spec/features/robo_dog_spec.rb
|
54
|
+
- spec/orientation_spec.rb
|
55
|
+
- spec/paddock_spec.rb
|
56
|
+
- spec/parser_spec.rb
|
57
|
+
- spec/pose_spec.rb
|
58
|
+
- spec/robot_spec.rb
|
59
|
+
- spec/simulation_spec.rb
|
60
|
+
homepage: https://github.com/matiasanaya/robo-dog
|
61
|
+
licenses:
|
62
|
+
- UNLICENSE
|
63
|
+
metadata: {}
|
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.1'
|
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.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Fredwina the Farmer's robotic sheep dog simulator
|
84
|
+
test_files:
|
85
|
+
- spec/application_spec.rb
|
86
|
+
- spec/features/robo_dog_spec.rb
|
87
|
+
- spec/orientation_spec.rb
|
88
|
+
- spec/paddock_spec.rb
|
89
|
+
- spec/parser_spec.rb
|
90
|
+
- spec/pose_spec.rb
|
91
|
+
- spec/robot_spec.rb
|
92
|
+
- spec/simulation_spec.rb
|