MonkeyEngine 1.0.0

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.idea/.name +1 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/MonkeyEngine.iml +133 -0
  6. data/.idea/codeStyleSettings.xml +13 -0
  7. data/.idea/encodings.xml +5 -0
  8. data/.idea/misc.xml +5 -0
  9. data/.idea/modules.xml +9 -0
  10. data/.idea/runConfigurations/All_specs_in_test__MonkeyEngine.xml +38 -0
  11. data/.idea/runConfigurations/IRB_console.xml +25 -0
  12. data/.idea/runConfigurations/Start_Yard_Server.xml +26 -0
  13. data/.idea/runConfigurations/monkey_run.xml +26 -0
  14. data/.idea/scopes/scope_settings.xml +5 -0
  15. data/.idea/vcs.xml +7 -0
  16. data/.idea/workspace.xml +886 -0
  17. data/.ruby-version +1 -0
  18. data/Gemfile +4 -0
  19. data/LICENSE.txt +22 -0
  20. data/README.md +29 -0
  21. data/Rakefile +3 -0
  22. data/lib/Action/action.rb +29 -0
  23. data/lib/Monkey.rb +1 -0
  24. data/lib/Monkey/monkey.rb +108 -0
  25. data/lib/MonkeyAction/monkey_action.rb +14 -0
  26. data/lib/MonkeyAction/monkey_action_dead.rb +26 -0
  27. data/lib/MonkeyAction/monkey_action_eat.rb +31 -0
  28. data/lib/MonkeyAction/monkey_action_pause.rb +32 -0
  29. data/lib/MonkeyAction/monkey_action_sleep.rb +31 -0
  30. data/lib/MonkeyAction/monkey_action_type.rb +40 -0
  31. data/lib/MonkeyAction/monkey_action_wake.rb +26 -0
  32. data/lib/MonkeyAction/monkey_timed_action.rb +27 -0
  33. data/lib/MonkeyActions.rb +6 -0
  34. data/lib/MonkeyEngine.rb +1 -0
  35. data/lib/MonkeyEngine/action_rules.rb +111 -0
  36. data/lib/MonkeyEngine/exceptions.rb +21 -0
  37. data/lib/MonkeyEngine/monkey_engine.rb +53 -0
  38. data/lib/MonkeyEngine/version.rb +3 -0
  39. data/lib/MonkeyFactory.rb +1 -0
  40. data/lib/MonkeyFactory/monkey_factory.rb +14 -0
  41. data/lib/MonkeyKeyboard/keyboard_char.rb +10 -0
  42. data/lib/MonkeyKeyboard/keyboard_input.rb +14 -0
  43. data/lib/MonkeyKeyboard/keyboard_key.rb +26 -0
  44. data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +25 -0
  45. data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +137 -0
  46. data/lib/MonkeyKeyboardEnUs.rb +1 -0
  47. data/lib/MonkeyManager.rb +1 -0
  48. data/lib/MonkeyManager/monkey_manager.rb +162 -0
  49. data/lib/MonkeyService.rb +1 -0
  50. data/lib/MonkeyService/monkey_service.rb +137 -0
  51. data/lib/tasks/engine.rb +91 -0
  52. data/monkeyengine.gemspec +32 -0
  53. data/spec/action_rules_spec.rb +59 -0
  54. data/spec/engine_spec.rb +56 -0
  55. data/spec/keyboard_char_spec.rb +12 -0
  56. data/spec/keyboard_key_spec.rb +15 -0
  57. data/spec/monkey_action_eat_spec.rb +86 -0
  58. data/spec/monkey_action_pause_spec.rb +91 -0
  59. data/spec/monkey_action_sleep_spec.rb +90 -0
  60. data/spec/monkey_action_type_spec.rb +94 -0
  61. data/spec/monkey_action_wake_spec.rb +58 -0
  62. data/spec/monkey_factory_spec.rb +23 -0
  63. data/spec/monkey_keyboard_en_us_spec.rb +42 -0
  64. data/spec/monkey_manager_spec.rb +8 -0
  65. data/spec/monkey_service_spec.rb +96 -0
  66. data/spec/monkey_spec.rb +8 -0
  67. data/spec/spec_helpers.rb +20 -0
  68. data/spec/support/shared_examples.rb +41 -0
  69. metadata +258 -0
@@ -0,0 +1,58 @@
1
+ require 'Monkey'
2
+ require 'MonkeyActions'
3
+ require 'MonkeyFactory'
4
+ require 'MonkeyEngine'
5
+
6
+ require_relative 'support/shared_examples'
7
+
8
+ describe 'MonkeyActionWake' do
9
+ before(:all) do
10
+
11
+ @monkey = MonkeyFactory.create :waking_monkey1
12
+ @it = MonkeyActionWake.new @monkey
13
+
14
+ MonkeyEngine::MonkeyManager.instance.add(@monkey)
15
+
16
+ end
17
+
18
+ after(:all) do
19
+ # Kill all the threads.
20
+ MonkeyEngine::MonkeyManager.instance.kill_all!
21
+
22
+ # Give them a little bit to finish.
23
+ MonkeyEngine::MonkeyManager.instance.join_all(10)
24
+ end
25
+
26
+ it_should_behave_like 'MonkeyAction'
27
+
28
+ it '@it should be the correct type' do
29
+ @it.is_a?(MonkeyActionWake).should == true
30
+ end
31
+
32
+ # Monkey
33
+ it '@monkey should be the same monkey' do
34
+ @it.monkey.should == @monkey
35
+ end
36
+
37
+ # Value
38
+ it '@value should return the right value' do
39
+ @it.value.should == true
40
+ end
41
+
42
+ it "@value should be is_a? TrueClass" do
43
+ @it.value.is_a?(TrueClass).should == true
44
+ end
45
+
46
+ # Weight
47
+ it '@weight should return the right weight' do
48
+ @it.weight.should == MonkeyActionWake::WEIGHT
49
+ end
50
+
51
+ # validate
52
+ it "should not raise an error if value is within acceptable range" do
53
+ monkey = MonkeyFactory.create(:waking_monkey2)
54
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
55
+ lambda { MonkeyActionWake.new(monkey) }.should_not raise_error
56
+ end
57
+
58
+ end
@@ -0,0 +1,23 @@
1
+ require 'MonkeyFactory'
2
+
3
+ describe 'MonkeyFactory' do
4
+
5
+ before(:all) do
6
+ end
7
+
8
+ after(:all) do
9
+ end
10
+
11
+ context 'create' do
12
+
13
+ it 'should instantiate an object from the factory' do
14
+ monkey = MonkeyFactory::create(:harpo)
15
+ monkey.nil?.should == false
16
+ monkey.is_a?(Monkey).should == true
17
+ end
18
+
19
+ it 'should not instantiate an object without using the factory' do
20
+ lambda { Monkey.new :groucho }.should raise_error NoMethodError
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'MonkeyKeyboardEnUs'
2
+
3
+ describe 'MonkeyKeyboardEnUs' do
4
+
5
+ before (:all) do
6
+ @it = MonkeyEngine::MonkeyKeyboardEnUs.instance
7
+ end
8
+
9
+ context 'keys' do
10
+ end
11
+
12
+ context 'left_keys' do
13
+
14
+ it 'should have the correct amount of keyboard entries on the left side of the keyboard' do
15
+
16
+ key_count = 0
17
+
18
+ @it.keys.each { |key|
19
+ key_count += key.keyboard_key_weight if key.keyboard_key_section == :left
20
+ }
21
+
22
+ @it.left_keys.count.should == key_count
23
+ end
24
+
25
+ end
26
+
27
+ context 'right_keys' do
28
+
29
+ it 'should have the correct amount of keyboard entries on the right side of the keyboard' do
30
+
31
+ key_count = 0
32
+
33
+ @it.keys.each { |key|
34
+ key_count += key.keyboard_key_weight if key.keyboard_key_section == :right
35
+ }
36
+
37
+ @it.right_keys.count.should == key_count
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,8 @@
1
+
2
+ describe 'MonkeyManager' do
3
+ before { skip 'todo' }
4
+
5
+ it 'should do something' do
6
+ skip 'todo'
7
+ end
8
+ end
@@ -0,0 +1,96 @@
1
+ require 'MonkeyService'
2
+ require 'MonkeyFactory'
3
+ require 'MonkeyEngine'
4
+
5
+ describe 'MonkeyService' do
6
+
7
+ before(:all) do
8
+ @it = MonkeyEngine::MonkeyService.instance
9
+
10
+ # Register us before we do anything, so we can be notified of everything.
11
+ @it.add_observer self
12
+
13
+ @it.add(MonkeyFactory::create :groucho)
14
+ @it.add(MonkeyFactory::create :harpo)
15
+ @it.add(MonkeyFactory::create :chico)
16
+ end
17
+
18
+ after(:all) do
19
+ # Kill all the threads.
20
+ @it.kill_all!
21
+
22
+ # Give them a little bit to finish.
23
+ @it.join_all(10)
24
+ end
25
+
26
+ def update(time, action, param)
27
+ puts "Time: [#{time}], Action: [#{action}], Param: [#{param}]"
28
+ end
29
+
30
+ context 'initialization' do
31
+
32
+ it 'it should have 3 monkeys' do
33
+ @it.count.should == 3
34
+ end
35
+
36
+ it 'should have monkey harpo' do
37
+ @it.exists?(:harpo).should == true
38
+ end
39
+
40
+ it 'should have monkey groucho' do
41
+ @it.exists?(:groucho).should == true
42
+ end
43
+
44
+ it 'should have monkey chico' do
45
+ @it.exists?(:chico).should == true
46
+ end
47
+
48
+ end
49
+
50
+ context 'methods' do
51
+
52
+ it "'get' should raise an exception if invalid argument type is sent" do
53
+ lambda { @it.get(999) }.should raise_exception MonkeyEngine::Exceptions::InvalidArgumentTypeException
54
+ end
55
+
56
+ it "'add' should raise an exception if adding a non-unique object" do
57
+ lambda { @it.add(MonkeyFactory::create :chico) }.should raise_exception MonkeyEngine::Exceptions::UniqueObjectException
58
+ end
59
+
60
+ it "'any_alive?' should return objects that are alive" do
61
+ @it.any_alive?.should == true
62
+ end
63
+
64
+ end
65
+
66
+ context 'clean up' do
67
+
68
+ it 'no monkeys should be alive if killed by the service' do
69
+ # Kill all the threads.
70
+ @it.kill_all!
71
+
72
+ # Give them a little bit to finish.
73
+ @it.join_all(10)
74
+
75
+ @it.any_alive?.should == false
76
+ end
77
+
78
+ it 'kill_all! should return all monkeys killed' do
79
+ monkey_service = MonkeyEngine::MonkeyService.instance
80
+
81
+ monkey_service.add(MonkeyFactory::create :a)
82
+ monkey_service.add(MonkeyFactory::create :b)
83
+ monkey_service.add(MonkeyFactory::create :c)
84
+
85
+ monkeys = monkey_service.get_all
86
+
87
+ killed_monkeys = monkey_service.kill_all!
88
+
89
+ monkey_service.join_all(10)
90
+
91
+ (monkeys == killed_monkeys).should == true
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,8 @@
1
+
2
+ describe 'Monkey' do
3
+ before { skip 'todo' }
4
+
5
+ it 'should do something' do
6
+ skip 'todo'
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ module SpecHelpers
2
+ require 'minitest/autorun'
3
+
4
+ module SetMonkeyAction
5
+ def set_action(action)
6
+ @action = action
7
+ end
8
+ end
9
+ end
10
+
11
+ # Use :should in stead of :expect
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :should
15
+ end
16
+ config.mock_with :rspec do |c|
17
+ c.syntax = :should
18
+ end
19
+ #config.raise_errors_for_deprecations!
20
+ end
@@ -0,0 +1,41 @@
1
+ # Shared for monkey action.
2
+ shared_examples_for "MonkeyAction" do
3
+ it "should have read access to monkey" do
4
+ @it.respond_to?(:monkey).should == true
5
+ end
6
+
7
+ it "should not have write access to monkey" do
8
+ @it.respond_to?(:monkey=).should_not == true
9
+ end
10
+
11
+ it_should_behave_like "Action"
12
+ end
13
+
14
+ # Action
15
+ shared_examples_for "Action" do
16
+
17
+ it "should respond_to? :value" do
18
+ # "Value: #{@it.value}"
19
+ @it.respond_to?(:value).should == true
20
+ end
21
+
22
+ it "should respond_to? :weight" do
23
+ # "Weight: #{@it.weight}"
24
+ @it.respond_to?(:weight).should == true
25
+ end
26
+
27
+ # value
28
+ it "@value should not be nil?" do
29
+ @it.value.nil?.should_not == true
30
+ end
31
+
32
+ # weight
33
+ it "@weight should not be nil?" do
34
+ @it.weight.nil?.should_not == true
35
+ end
36
+
37
+ it "@weight should be is_a? Float" do
38
+ @it.weight.is_a?(Float).should == true
39
+ end
40
+ end
41
+
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MonkeyEngine
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gene M. Angelo, Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: yard
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 0.8.6.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '='
73
+ - !ruby/object:Gem::Version
74
+ version: 0.8.6.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: redcarpet
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.3.0
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.3.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: pry
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: LittleWeasel
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: ProtectedConstructor
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.0'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.0.0
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '2.0'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.0.0
143
+ description: MonkeyEngine - FUN!
144
+ email:
145
+ - public.gma@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".gitignore"
151
+ - ".idea/.name"
152
+ - ".idea/.rakeTasks"
153
+ - ".idea/MonkeyEngine.iml"
154
+ - ".idea/codeStyleSettings.xml"
155
+ - ".idea/encodings.xml"
156
+ - ".idea/misc.xml"
157
+ - ".idea/modules.xml"
158
+ - ".idea/runConfigurations/All_specs_in_test__MonkeyEngine.xml"
159
+ - ".idea/runConfigurations/IRB_console.xml"
160
+ - ".idea/runConfigurations/Start_Yard_Server.xml"
161
+ - ".idea/runConfigurations/monkey_run.xml"
162
+ - ".idea/scopes/scope_settings.xml"
163
+ - ".idea/vcs.xml"
164
+ - ".idea/workspace.xml"
165
+ - ".ruby-version"
166
+ - Gemfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - lib/Action/action.rb
171
+ - lib/Monkey.rb
172
+ - lib/Monkey/monkey.rb
173
+ - lib/MonkeyAction/monkey_action.rb
174
+ - lib/MonkeyAction/monkey_action_dead.rb
175
+ - lib/MonkeyAction/monkey_action_eat.rb
176
+ - lib/MonkeyAction/monkey_action_pause.rb
177
+ - lib/MonkeyAction/monkey_action_sleep.rb
178
+ - lib/MonkeyAction/monkey_action_type.rb
179
+ - lib/MonkeyAction/monkey_action_wake.rb
180
+ - lib/MonkeyAction/monkey_timed_action.rb
181
+ - lib/MonkeyActions.rb
182
+ - lib/MonkeyEngine.rb
183
+ - lib/MonkeyEngine/action_rules.rb
184
+ - lib/MonkeyEngine/exceptions.rb
185
+ - lib/MonkeyEngine/monkey_engine.rb
186
+ - lib/MonkeyEngine/version.rb
187
+ - lib/MonkeyFactory.rb
188
+ - lib/MonkeyFactory/monkey_factory.rb
189
+ - lib/MonkeyKeyboard/keyboard_char.rb
190
+ - lib/MonkeyKeyboard/keyboard_input.rb
191
+ - lib/MonkeyKeyboard/keyboard_key.rb
192
+ - lib/MonkeyKeyboard/keyboard_key_evaluator.rb
193
+ - lib/MonkeyKeyboard/monkey_keyboard_en_us.rb
194
+ - lib/MonkeyKeyboardEnUs.rb
195
+ - lib/MonkeyManager.rb
196
+ - lib/MonkeyManager/monkey_manager.rb
197
+ - lib/MonkeyService.rb
198
+ - lib/MonkeyService/monkey_service.rb
199
+ - lib/tasks/engine.rb
200
+ - monkeyengine.gemspec
201
+ - spec/action_rules_spec.rb
202
+ - spec/engine_spec.rb
203
+ - spec/keyboard_char_spec.rb
204
+ - spec/keyboard_key_spec.rb
205
+ - spec/monkey_action_eat_spec.rb
206
+ - spec/monkey_action_pause_spec.rb
207
+ - spec/monkey_action_sleep_spec.rb
208
+ - spec/monkey_action_type_spec.rb
209
+ - spec/monkey_action_wake_spec.rb
210
+ - spec/monkey_factory_spec.rb
211
+ - spec/monkey_keyboard_en_us_spec.rb
212
+ - spec/monkey_manager_spec.rb
213
+ - spec/monkey_service_spec.rb
214
+ - spec/monkey_spec.rb
215
+ - spec/spec_helpers.rb
216
+ - spec/support/shared_examples.rb
217
+ homepage: http://www.geneangelo.com
218
+ licenses:
219
+ - MIT
220
+ metadata: {}
221
+ post_install_message:
222
+ rdoc_options: []
223
+ require_paths:
224
+ - lib
225
+ required_ruby_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '2.1'
230
+ required_rubygems_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: '0'
235
+ requirements: []
236
+ rubyforge_project:
237
+ rubygems_version: 2.2.0
238
+ signing_key:
239
+ specification_version: 4
240
+ summary: The engine that drives my monkeys!
241
+ test_files:
242
+ - spec/action_rules_spec.rb
243
+ - spec/engine_spec.rb
244
+ - spec/keyboard_char_spec.rb
245
+ - spec/keyboard_key_spec.rb
246
+ - spec/monkey_action_eat_spec.rb
247
+ - spec/monkey_action_pause_spec.rb
248
+ - spec/monkey_action_sleep_spec.rb
249
+ - spec/monkey_action_type_spec.rb
250
+ - spec/monkey_action_wake_spec.rb
251
+ - spec/monkey_factory_spec.rb
252
+ - spec/monkey_keyboard_en_us_spec.rb
253
+ - spec/monkey_manager_spec.rb
254
+ - spec/monkey_service_spec.rb
255
+ - spec/monkey_spec.rb
256
+ - spec/spec_helpers.rb
257
+ - spec/support/shared_examples.rb
258
+ has_rdoc: