MonkeyEngine 1.1.0 → 2.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 +5 -5
- data/.gitignore +19 -16
- data/.rspec +3 -0
- data/.rubocop.yml +192 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +10 -2
- data/Gemfile +3 -1
- data/Gemfile.lock +70 -0
- data/Rakefile +3 -2
- data/dictionaries/en-US.txt +466554 -0
- data/lib/Action/action.rb +5 -6
- data/lib/Monkey/monkey.rb +17 -13
- data/lib/Monkey.rb +3 -1
- data/lib/MonkeyAction/monkey_action.rb +3 -3
- data/lib/MonkeyAction/monkey_action_dead.rb +8 -8
- data/lib/MonkeyAction/monkey_action_eat.rb +6 -6
- data/lib/MonkeyAction/monkey_action_pause.rb +6 -7
- data/lib/MonkeyAction/monkey_action_sleep.rb +6 -6
- data/lib/MonkeyAction/monkey_action_type.rb +15 -12
- data/lib/MonkeyAction/monkey_action_wake.rb +8 -8
- data/lib/MonkeyAction/monkey_timed_action.rb +6 -6
- data/lib/MonkeyActions.rb +2 -0
- data/lib/MonkeyEngine/action_rules.rb +20 -18
- data/lib/MonkeyEngine/exceptions.rb +7 -7
- data/lib/MonkeyEngine/monkey_engine.rb +11 -14
- data/lib/MonkeyEngine/version.rb +3 -1
- data/lib/MonkeyEngine.rb +3 -1
- data/lib/MonkeyFactory/monkey_factory.rb +3 -4
- data/lib/MonkeyFactory.rb +3 -1
- data/lib/MonkeyKeyboard/keyboard_char.rb +3 -3
- data/lib/MonkeyKeyboard/keyboard_input.rb +4 -3
- data/lib/MonkeyKeyboard/keyboard_key.rb +12 -10
- data/lib/MonkeyKeyboard/keyboard_key_evaluator.rb +6 -8
- data/lib/MonkeyKeyboard/monkey_keyboard_en_us.rb +100 -80
- data/lib/MonkeyKeyboardEnUs.rb +3 -1
- data/lib/MonkeyManager/monkey_manager.rb +17 -15
- data/lib/MonkeyManager.rb +3 -1
- data/lib/MonkeyService/monkey_service.rb +8 -9
- data/lib/MonkeyService.rb +3 -1
- data/lib/tasks/engine.rb +63 -54
- data/monkeyengine.gemspec +26 -20
- data/spec/action_rules_spec.rb +17 -23
- data/spec/engine_spec.rb +15 -20
- data/spec/keyboard_char_spec.rb +4 -5
- data/spec/keyboard_key_spec.rb +8 -9
- data/spec/monkey_action_eat_spec.rb +17 -18
- data/spec/monkey_action_pause_spec.rb +19 -20
- data/spec/monkey_action_sleep_spec.rb +19 -20
- data/spec/monkey_action_type_spec.rb +25 -24
- data/spec/monkey_action_wake_spec.rb +10 -11
- data/spec/monkey_factory_spec.rb +7 -15
- data/spec/monkey_keyboard_en_us_spec.rb +10 -19
- data/spec/monkey_manager_spec.rb +3 -2
- data/spec/monkey_service_spec.rb +26 -29
- data/spec/monkey_spec.rb +3 -2
- data/spec/{spec_helpers.rb → spec_helper.rb} +7 -5
- data/spec/support/shared_examples.rb +16 -16
- metadata +69 -55
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/MonkeyEngine.iml +0 -133
- data/.idea/codeStyleSettings.xml +0 -13
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/runConfigurations/All_specs_in_test__MonkeyEngine.xml +0 -38
- data/.idea/runConfigurations/IRB_console.xml +0 -25
- data/.idea/runConfigurations/Start_Yard_Server.xml +0 -26
- data/.idea/runConfigurations/monkey_run.xml +0 -26
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -886
data/monkeyengine.gemspec
CHANGED
@@ -1,32 +1,38 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
|
5
|
+
lib = File.expand_path('lib', __dir__)
|
3
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
7
|
require 'MonkeyEngine/version'
|
5
8
|
|
6
9
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
10
|
+
spec.name = 'MonkeyEngine'
|
8
11
|
spec.version = MonkeyEngine::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
spec.authors = ['Gene M. Angelo, Jr.']
|
13
|
+
spec.email = ['public.gma@gmail.com']
|
14
|
+
spec.description = "Have some fun! MonkeyEngine is a gem that allows virtual monkeys " \
|
15
|
+
"to tap away on a virtual keyboard! Can any of them complete a sentence? " \
|
16
|
+
"write a book? The sky is the limit! Add your own AI! Publish the results! " \
|
17
|
+
"Go...BANANAS!"
|
18
|
+
spec.summary = 'The engine that drives my monkeys!'
|
19
|
+
spec.homepage = 'https://github.com/gangelo/monkeyengine'
|
20
|
+
spec.license = 'MIT'
|
21
|
+
spec.required_ruby_version = '>= 3.0.1'
|
15
22
|
|
16
|
-
spec.files = `git ls-files`.split(
|
23
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
25
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
|
21
|
-
spec.required_ruby_version = '~> 2.1'
|
26
|
+
spec.require_paths = ['lib']
|
22
27
|
|
23
|
-
spec.add_development_dependency 'bundler', '~>
|
24
|
-
spec.add_development_dependency '
|
25
|
-
spec.add_development_dependency '
|
26
|
-
spec.add_development_dependency '
|
28
|
+
spec.add_development_dependency 'bundler', '~> 2.3', '>= 2.3.20'
|
29
|
+
spec.add_development_dependency 'colorize', '~> 0.8.1'
|
30
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.9'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
|
27
32
|
spec.add_development_dependency 'redcarpet', '~> 2.3', '>= 2.3.0'
|
28
|
-
spec.add_development_dependency '
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
34
|
+
spec.add_development_dependency 'yard', '~> 0.9.28'
|
29
35
|
|
30
|
-
spec.add_runtime_dependency 'LittleWeasel', '~>
|
31
|
-
spec.add_runtime_dependency 'ProtectedConstructor', '~> 2.0', '>=2.0.
|
36
|
+
spec.add_runtime_dependency 'LittleWeasel', '~> 5.0', '>= 5.0.3'
|
37
|
+
spec.add_runtime_dependency 'ProtectedConstructor', '~> 2.0', '>= 2.0.3'
|
32
38
|
end
|
data/spec/action_rules_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'Monkey'
|
4
4
|
require 'MonkeyFactory'
|
@@ -8,52 +8,46 @@ require 'MonkeyActions'
|
|
8
8
|
require_relative '../lib/MonkeyKeyboard/keyboard_input'
|
9
9
|
|
10
10
|
describe 'ActionRules' do
|
11
|
-
|
12
|
-
before(:each) do
|
13
|
-
end
|
14
|
-
|
15
|
-
after(:all) do
|
16
|
-
end
|
17
|
-
|
18
11
|
context 'get_next_action' do
|
19
|
-
|
20
|
-
|
21
|
-
monkey = MonkeyFactory::create :groucho
|
12
|
+
it 'throws an exception if the action is not completed' do
|
13
|
+
monkey = MonkeyFactory.create :groucho
|
22
14
|
|
23
15
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
24
16
|
|
25
17
|
keyboard_input = KeyboardInput.new
|
26
|
-
keyboard_input.input = %w
|
18
|
+
keyboard_input.input = %w[H e l l o]
|
27
19
|
|
28
20
|
action = MonkeyActionType.new(monkey, keyboard_input)
|
29
21
|
action.action_completed = false
|
30
22
|
|
31
|
-
monkey.
|
23
|
+
monkey.force_action(action)
|
32
24
|
|
33
|
-
lambda {
|
25
|
+
lambda {
|
26
|
+
ActionRules.instance.get_next_action monkey
|
27
|
+
}.should raise_error MonkeyEngine::Exceptions::InvalidOperationException
|
34
28
|
end
|
35
29
|
|
36
|
-
it '
|
37
|
-
monkey = MonkeyFactory
|
30
|
+
it 'gets correct action if current action is nil?' do
|
31
|
+
monkey = MonkeyFactory.create :groucho
|
38
32
|
|
39
33
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
40
34
|
|
41
|
-
monkey.
|
35
|
+
monkey.force_action(nil)
|
42
36
|
|
43
|
-
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should
|
37
|
+
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should be true
|
44
38
|
end
|
45
39
|
|
46
|
-
it '
|
47
|
-
monkey = MonkeyFactory
|
40
|
+
it 'gets correct action if current action is MonkeyActionSleep' do
|
41
|
+
monkey = MonkeyFactory.create :groucho
|
48
42
|
|
49
43
|
monkey.extend(SpecHelpers::SetMonkeyAction)
|
50
44
|
|
51
45
|
action = MonkeyActionSleep.new(monkey, 6 * 60)
|
52
46
|
action.action_completed = true
|
53
47
|
|
54
|
-
monkey.
|
48
|
+
monkey.force_action(action)
|
55
49
|
|
56
|
-
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should
|
50
|
+
ActionRules.instance.get_next_action(monkey).is_a?(MonkeyActionWake).should be true
|
57
51
|
end
|
58
52
|
end
|
59
|
-
end
|
53
|
+
end
|
data/spec/engine_spec.rb
CHANGED
@@ -1,56 +1,51 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'MonkeyEngine'
|
4
4
|
require 'MonkeyActions'
|
5
5
|
require 'MonkeyFactory'
|
6
6
|
|
7
|
-
|
8
7
|
describe 'Engine' do
|
9
|
-
|
10
|
-
before(:each) do
|
8
|
+
before do
|
11
9
|
@engine = MonkeyEngine::Engine.instance
|
12
|
-
@monkey = MonkeyFactory
|
10
|
+
@monkey = MonkeyFactory.create :groucho
|
13
11
|
@monkey.extend(SpecHelpers::SetMonkeyAction)
|
14
12
|
end
|
15
13
|
|
16
14
|
context 'action_eval!' do
|
17
|
-
it '
|
18
|
-
|
15
|
+
it 'returns action completed if the action is completed' do
|
19
16
|
action = MonkeyActionPause.new(@monkey, 10)
|
20
17
|
action.action_completed = false
|
21
18
|
action.action_time_of_completion = action.action_time
|
22
19
|
|
23
|
-
@monkey.
|
20
|
+
@monkey.force_action(action)
|
24
21
|
|
25
|
-
@engine.action_eval!(action).should
|
22
|
+
@engine.action_eval!(action).should be true
|
26
23
|
end
|
27
24
|
|
28
|
-
it '
|
29
|
-
|
25
|
+
it 'returns action not completed if the action is not completed' do
|
30
26
|
action = MonkeyActionPause.new(@monkey, 60)
|
31
27
|
action.action_completed = false
|
32
28
|
|
33
|
-
@monkey.
|
29
|
+
@monkey.force_action(action)
|
34
30
|
|
35
|
-
@engine.action_eval!(action).should
|
31
|
+
@engine.action_eval!(action).should be false
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
39
35
|
context 'action_new' do
|
40
|
-
it '
|
41
|
-
|
42
|
-
action = MonkeyActionSleep.new(@monkey, 60*8)
|
36
|
+
it 'returns a new action if a the current action is completed' do
|
37
|
+
action = MonkeyActionSleep.new(@monkey, 60 * 8)
|
43
38
|
action.action_completed = true
|
44
39
|
|
45
|
-
@monkey.
|
40
|
+
@monkey.force_action(action)
|
46
41
|
|
47
|
-
@engine.new_action(@monkey).is_a?(MonkeyActionSleep).should_not==true
|
42
|
+
@engine.new_action(@monkey).is_a?(MonkeyActionSleep).should_not == true
|
48
43
|
end
|
49
44
|
end
|
50
45
|
|
51
46
|
context 'do_action' do
|
52
|
-
it '
|
47
|
+
it 'does something' do
|
53
48
|
skip 'todo'
|
54
49
|
end
|
55
50
|
end
|
56
|
-
end
|
51
|
+
end
|
data/spec/keyboard_char_spec.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'MonkeyKeyboardEnUs'
|
2
4
|
|
3
5
|
describe 'KeyboardChar' do
|
4
|
-
|
5
|
-
it 'should return the proper char that it represents' do
|
6
|
-
|
6
|
+
it 'returns the proper char that it represents' do
|
7
7
|
keyboard_char = KeyboardChar.new 'a'
|
8
8
|
|
9
9
|
keyboard_char.char.should == 'a'
|
10
|
-
|
11
10
|
end
|
12
|
-
end
|
11
|
+
end
|
data/spec/keyboard_key_spec.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'MonkeyKeyboardEnUs'
|
2
4
|
|
3
5
|
describe 'KeyboardKey' do
|
4
|
-
|
5
|
-
it 'should should return correct properties' do
|
6
|
-
|
6
|
+
it 'shoulds return correct properties' do
|
7
7
|
keyboard_key = KeyboardKey.new 'a', 'A', :left, 1
|
8
8
|
|
9
|
-
keyboard_key.keyboard_char.should
|
10
|
-
keyboard_key.keyboard_shift_char.should
|
11
|
-
keyboard_key.keyboard_key_section.should
|
12
|
-
keyboard_key.keyboard_key_weight.should
|
13
|
-
|
9
|
+
keyboard_key.keyboard_char.should eq 'a'
|
10
|
+
keyboard_key.keyboard_shift_char.should eq 'A'
|
11
|
+
keyboard_key.keyboard_key_section.should eq :left
|
12
|
+
keyboard_key.keyboard_key_weight.should eq 1
|
14
13
|
end
|
15
|
-
end
|
14
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'Monkey'
|
2
4
|
require 'MonkeyActions'
|
3
5
|
require 'MonkeyFactory'
|
@@ -7,12 +9,10 @@ require_relative 'support/shared_examples'
|
|
7
9
|
|
8
10
|
describe 'MonkeyActionEat' do
|
9
11
|
before(:all) do
|
10
|
-
|
11
12
|
@monkey = MonkeyFactory.create :eating_monkey1
|
12
13
|
@it = MonkeyActionEat.new @monkey, 30 # minutes
|
13
14
|
|
14
15
|
MonkeyEngine::MonkeyManager.instance.add(@monkey)
|
15
|
-
|
16
16
|
end
|
17
17
|
|
18
18
|
after(:all) do
|
@@ -23,10 +23,10 @@ describe 'MonkeyActionEat' do
|
|
23
23
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it_behaves_like 'MonkeyAction'
|
27
27
|
|
28
28
|
it '@it should be the correct type' do
|
29
|
-
@it.is_a?(MonkeyActionEat).should
|
29
|
+
@it.is_a?(MonkeyActionEat).should be true
|
30
30
|
end
|
31
31
|
|
32
32
|
# Monkey
|
@@ -39,8 +39,8 @@ describe 'MonkeyActionEat' do
|
|
39
39
|
@it.value.should == 30
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
@it.value.is_a?(Integer).should
|
42
|
+
it '@value should be is_a? Integer' do
|
43
|
+
@it.value.is_a?(Integer).should be true
|
44
44
|
end
|
45
45
|
|
46
46
|
# Weight
|
@@ -49,38 +49,37 @@ describe 'MonkeyActionEat' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# validate
|
52
|
-
it
|
52
|
+
it 'does not raise an error if value is within acceptable range' do
|
53
53
|
monkey = MonkeyFactory.create(:eating_monkey2)
|
54
54
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
55
|
-
|
55
|
+
-> { MonkeyActionEat.new(monkey, 40) }.should_not raise_error
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it 'raises an error if value is the wrong type' do
|
59
59
|
monkey = MonkeyFactory.create(:eating_monkey3)
|
60
60
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
61
|
-
|
61
|
+
-> { MonkeyActionEat.new(monkey, :wrong_type) }.should \
|
62
62
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it 'raises an error if value is less than min acceptable range' do
|
66
66
|
monkey = MonkeyFactory.create(:eating_monkey4)
|
67
67
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
68
|
-
|
68
|
+
-> { MonkeyActionEat.new(monkey, 29) }.should \
|
69
69
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it 'raises an error if value is greater than max acceptable range' do
|
73
73
|
monkey = MonkeyFactory.create(:eating_monkey5)
|
74
74
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
75
|
-
|
75
|
+
-> { MonkeyActionEat.new(monkey, 61) }.should \
|
76
76
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it 'raises an error if value is nil' do
|
80
80
|
monkey = MonkeyFactory.create(:eating_monkey6)
|
81
81
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
82
|
-
|
82
|
+
-> { MonkeyActionEat.new(monkey, nil) }.should \
|
83
83
|
raise_error MonkeyEngine::Exceptions::NilArgumentException
|
84
84
|
end
|
85
|
-
|
86
|
-
end
|
85
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'Monkey'
|
2
4
|
require 'MonkeyActions'
|
3
5
|
require 'MonkeyFactory'
|
@@ -8,12 +10,10 @@ require_relative 'support/shared_examples'
|
|
8
10
|
|
9
11
|
describe 'MonkeyActionPause' do
|
10
12
|
before(:all) do
|
11
|
-
|
12
13
|
@monkey = MonkeyFactory.create :pausing_monkey1
|
13
14
|
@it = MonkeyActionPause.new @monkey, 1 # 1 second
|
14
15
|
|
15
16
|
MonkeyEngine::MonkeyManager.instance.add(@monkey)
|
16
|
-
|
17
17
|
end
|
18
18
|
|
19
19
|
after(:all) do
|
@@ -24,10 +24,10 @@ describe 'MonkeyActionPause' do
|
|
24
24
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
it_behaves_like 'MonkeyAction'
|
28
28
|
|
29
29
|
it '@it should be the correct type' do
|
30
|
-
@it.is_a?(MonkeyActionPause).should
|
30
|
+
@it.is_a?(MonkeyActionPause).should be true
|
31
31
|
end
|
32
32
|
|
33
33
|
# Monkey
|
@@ -40,12 +40,12 @@ describe 'MonkeyActionPause' do
|
|
40
40
|
@it.value.should == 1
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
@it.value.is_a?(Integer).should
|
43
|
+
it '@value should be is_a? Integer' do
|
44
|
+
@it.value.is_a?(Integer).should be true
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
48
|
-
(@it.value >= 1).should
|
47
|
+
it '@value should >= 1' do
|
48
|
+
(@it.value >= 1).should be true
|
49
49
|
end
|
50
50
|
|
51
51
|
# Weight
|
@@ -54,38 +54,37 @@ describe 'MonkeyActionPause' do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# validate
|
57
|
-
it
|
57
|
+
it 'does not raise an error if value is within acceptable range' do
|
58
58
|
monkey = MonkeyFactory.create(:pausing_monkey2)
|
59
59
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
60
|
-
|
60
|
+
-> { MonkeyActionPause.new(monkey, 5) }.should_not raise_error
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'raises an error if value is the wrong type' do
|
64
64
|
monkey = MonkeyFactory.create(:pausing_monkey3)
|
65
65
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
66
|
-
|
66
|
+
-> { MonkeyActionPause.new(monkey, :wrong_type) }.should \
|
67
67
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'raises an error if value is less than min acceptable range' do
|
71
71
|
monkey = MonkeyFactory.create(:pausing_monkey4)
|
72
72
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
73
|
-
|
73
|
+
-> { MonkeyActionPause.new(monkey, -1) }.should \
|
74
74
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it 'raises an error if value is greater than max acceptable range' do
|
78
78
|
monkey = MonkeyFactory.create(:pausing_monkey5)
|
79
79
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
80
|
-
|
80
|
+
-> { MonkeyActionPause.new(monkey, 61) }.should \
|
81
81
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'raises an error if value is nil' do
|
85
85
|
monkey = MonkeyFactory.create(:pausing_monkey6)
|
86
86
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
87
|
-
|
87
|
+
-> { MonkeyActionPause.new(monkey, nil) }.should \
|
88
88
|
raise_error MonkeyEngine::Exceptions::NilArgumentException
|
89
89
|
end
|
90
|
-
|
91
|
-
end
|
90
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'Monkey'
|
2
4
|
require 'MonkeyActions'
|
3
5
|
require 'MonkeyFactory'
|
@@ -7,12 +9,10 @@ require_relative 'support/shared_examples'
|
|
7
9
|
|
8
10
|
describe 'MonkeyActionSleep' do
|
9
11
|
before(:all) do
|
10
|
-
|
11
12
|
@monkey = MonkeyFactory.create :sleeping_monkey1
|
12
13
|
@it = MonkeyActionSleep.new @monkey, 60 * 8 # milliseconds
|
13
14
|
|
14
15
|
MonkeyEngine::MonkeyManager.instance.add(@monkey)
|
15
|
-
|
16
16
|
end
|
17
17
|
|
18
18
|
after(:all) do
|
@@ -23,10 +23,10 @@ describe 'MonkeyActionSleep' do
|
|
23
23
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
it_behaves_like 'MonkeyAction'
|
27
27
|
|
28
28
|
it '@it should be the correct type' do
|
29
|
-
@it.is_a?(MonkeyActionSleep).should
|
29
|
+
@it.is_a?(MonkeyActionSleep).should be true
|
30
30
|
end
|
31
31
|
|
32
32
|
# Monkey
|
@@ -39,12 +39,12 @@ describe 'MonkeyActionSleep' do
|
|
39
39
|
@it.value.should == 60 * 8
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
43
|
-
@it.value.is_a?(Integer).should
|
42
|
+
it '@value should be is_a? Integer' do
|
43
|
+
@it.value.is_a?(Integer).should be true
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
(@it.value == 60 * 8).should
|
46
|
+
it '@value should equal 60 * 8' do
|
47
|
+
(@it.value == 60 * 8).should be true
|
48
48
|
end
|
49
49
|
|
50
50
|
# Weight
|
@@ -53,38 +53,37 @@ describe 'MonkeyActionSleep' do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# validate
|
56
|
-
it
|
56
|
+
it 'does not raise an error if value is within acceptable range' do
|
57
57
|
monkey = MonkeyFactory.create(:sleeping_monkey2)
|
58
58
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
59
|
-
|
59
|
+
-> { MonkeyActionSleep.new(monkey, 60 * 8) }.should_not raise_error
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it 'raises an error if value is the wrong type' do
|
63
63
|
monkey = MonkeyFactory.create(:sleeping_monkey3)
|
64
64
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
65
|
-
|
65
|
+
-> { MonkeyActionSleep.new(monkey, :wrong_type) }.should \
|
66
66
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it 'raises an error if value is less than min acceptable range' do
|
70
70
|
monkey = MonkeyFactory.create(:sleeping_monkey4)
|
71
71
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
72
|
-
|
72
|
+
-> { MonkeyActionSleep.new(monkey, 60 * 5) }.should \
|
73
73
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
76
|
+
it 'raises an error if value is greater than max acceptable range' do
|
77
77
|
monkey = MonkeyFactory.create(:sleeping_monkey5)
|
78
78
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
79
|
-
|
79
|
+
-> { MonkeyActionSleep.new(monkey, 60 * 9) }.should \
|
80
80
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it 'raises an error if value is nil' do
|
84
84
|
monkey = MonkeyFactory.create(:sleeping_monkey6)
|
85
85
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
86
|
-
|
86
|
+
-> { MonkeyActionSleep.new(monkey, nil) }.should \
|
87
87
|
raise_error MonkeyEngine::Exceptions::NilArgumentException
|
88
88
|
end
|
89
|
-
|
90
|
-
end
|
89
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'Monkey'
|
2
4
|
require 'MonkeyActions'
|
3
5
|
require 'MonkeyFactory'
|
@@ -8,11 +10,10 @@ require_relative 'support/shared_examples'
|
|
8
10
|
|
9
11
|
describe 'MonkeyActionType' do
|
10
12
|
before(:all) do
|
11
|
-
|
12
|
-
@monkey = MonkeyFactory::create :typing_monkey1
|
13
|
+
@monkey = MonkeyFactory.create :typing_monkey1
|
13
14
|
|
14
15
|
keyboard_input = KeyboardInput.new
|
15
|
-
keyboard_input.input = %w
|
16
|
+
keyboard_input.input = %w[a b c d e f .]
|
16
17
|
|
17
18
|
@it = MonkeyActionType.new @monkey, keyboard_input
|
18
19
|
|
@@ -27,10 +28,10 @@ describe 'MonkeyActionType' do
|
|
27
28
|
MonkeyEngine::MonkeyManager.instance.join_all(10)
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
+
it_behaves_like 'MonkeyAction'
|
31
32
|
|
32
33
|
it '@it should be the correct type' do
|
33
|
-
@it.is_a?(MonkeyActionType).should
|
34
|
+
@it.is_a?(MonkeyActionType).should be true
|
34
35
|
end
|
35
36
|
|
36
37
|
# Monkey
|
@@ -40,14 +41,14 @@ describe 'MonkeyActionType' do
|
|
40
41
|
|
41
42
|
# Value
|
42
43
|
it '@value should return the right value' do
|
43
|
-
@it.value.should == %w
|
44
|
+
@it.value.should == %w[a b c d e f .]
|
44
45
|
end
|
45
46
|
|
46
|
-
it
|
47
|
-
@it.value.is_a?(Array).should
|
47
|
+
it '@value should be is_a? Array' do
|
48
|
+
@it.value.is_a?(Array).should be true
|
48
49
|
end
|
49
50
|
|
50
|
-
it
|
51
|
+
it '@value should not be nil?' do
|
51
52
|
@it.value.nil?.should_not == true
|
52
53
|
end
|
53
54
|
|
@@ -57,38 +58,38 @@ describe 'MonkeyActionType' do
|
|
57
58
|
end
|
58
59
|
|
59
60
|
# validate
|
60
|
-
it
|
61
|
-
monkey = MonkeyFactory
|
61
|
+
it 'does not raise an error if value is valid' do
|
62
|
+
monkey = MonkeyFactory.create(:typing_monkey2)
|
62
63
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
63
64
|
|
64
65
|
keyboard_input = KeyboardInput.new
|
65
|
-
keyboard_input.input = %w
|
66
|
+
keyboard_input.input = %w[w o r d .]
|
66
67
|
|
67
|
-
|
68
|
+
-> { MonkeyActionType.new(monkey, keyboard_input) }.should_not raise_error
|
68
69
|
end
|
69
70
|
|
70
|
-
it
|
71
|
-
monkey = MonkeyFactory
|
71
|
+
it 'raises an error if value is the wrong type' do
|
72
|
+
monkey = MonkeyFactory.create(:typing_monkey3)
|
72
73
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
73
|
-
|
74
|
+
-> { MonkeyActionType.new(monkey, :wrong_type) }.should \
|
74
75
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
|
75
76
|
end
|
76
77
|
|
77
|
-
it
|
78
|
-
monkey = MonkeyFactory
|
78
|
+
it 'raises an error if value is empty?' do
|
79
|
+
monkey = MonkeyFactory.create(:typing_monkey4)
|
79
80
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
80
81
|
|
81
82
|
keyboard_input = KeyboardInput.new
|
82
|
-
keyboard_input.input = %w
|
83
|
+
keyboard_input.input = %w[]
|
83
84
|
|
84
|
-
|
85
|
+
-> { MonkeyActionType.new(monkey, keyboard_input) }.should \
|
85
86
|
raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
|
86
87
|
end
|
87
88
|
|
88
|
-
it
|
89
|
-
monkey = MonkeyFactory
|
89
|
+
it 'raises an error if value is nil' do
|
90
|
+
monkey = MonkeyFactory.create(:typing_monkey5)
|
90
91
|
MonkeyEngine::MonkeyManager.instance.add(monkey)
|
91
|
-
|
92
|
+
-> { MonkeyActionType.new(monkey, nil) }.should \
|
92
93
|
raise_error MonkeyEngine::Exceptions::NilArgumentException
|
93
94
|
end
|
94
|
-
end
|
95
|
+
end
|