MonkeyEngine 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,56 @@
1
+ require_relative 'spec_helpers'
2
+
3
+ require 'MonkeyEngine'
4
+ require 'MonkeyActions'
5
+ require 'MonkeyFactory'
6
+
7
+
8
+ describe 'Engine' do
9
+
10
+ before(:each) do
11
+ @engine = MonkeyEngine::Engine.instance
12
+ @monkey = MonkeyFactory::create :groucho
13
+ @monkey.extend(SpecHelpers::SetMonkeyAction)
14
+ end
15
+
16
+ context 'action_eval!' do
17
+ it 'should return action completed if the action is completed' do
18
+
19
+ action = MonkeyActionPause.new(@monkey, 10)
20
+ action.action_completed = false
21
+ action.action_time_of_completion = action.action_time
22
+
23
+ @monkey.set_action(action)
24
+
25
+ @engine.action_eval!(action).should == true
26
+ end
27
+
28
+ it 'should return action not completed if the action is not completed' do
29
+
30
+ action = MonkeyActionPause.new(@monkey, 60)
31
+ action.action_completed = false
32
+
33
+ @monkey.set_action(action)
34
+
35
+ @engine.action_eval!(action).should == false
36
+ end
37
+ end
38
+
39
+ context 'action_new' do
40
+ it 'should return a new action if a the current action is completed' do
41
+
42
+ action = MonkeyActionSleep.new(@monkey, 60*8)
43
+ action.action_completed = true
44
+
45
+ @monkey.set_action(action)
46
+
47
+ @engine.new_action(@monkey).is_a?(MonkeyActionSleep).should_not==true
48
+ end
49
+ end
50
+
51
+ context 'do_action' do
52
+ it 'should do something' do
53
+ skip 'todo'
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ require 'MonkeyKeyboardEnUs'
2
+
3
+ describe 'KeyboardChar' do
4
+
5
+ it 'should return the proper char that it represents' do
6
+
7
+ keyboard_char = KeyboardChar.new 'a'
8
+
9
+ keyboard_char.char.should == 'a'
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'MonkeyKeyboardEnUs'
2
+
3
+ describe 'KeyboardKey' do
4
+
5
+ it 'should should return correct properties' do
6
+
7
+ keyboard_key = KeyboardKey.new 'a', 'A', :left, 1
8
+
9
+ keyboard_key.keyboard_char.should == 'a'
10
+ keyboard_key.keyboard_shift_char.should == 'A'
11
+ keyboard_key.keyboard_key_section.should == :left
12
+ keyboard_key.keyboard_key_weight.should == 1
13
+
14
+ end
15
+ end
@@ -0,0 +1,86 @@
1
+ require 'Monkey'
2
+ require 'MonkeyActions'
3
+ require 'MonkeyFactory'
4
+ require 'MonkeyEngine'
5
+
6
+ require_relative 'support/shared_examples'
7
+
8
+ describe 'MonkeyActionEat' do
9
+ before(:all) do
10
+
11
+ @monkey = MonkeyFactory.create :eating_monkey1
12
+ @it = MonkeyActionEat.new @monkey, 30 # minutes
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?(MonkeyActionEat).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 == 30
40
+ end
41
+
42
+ it "@value should be is_a? Integer" do
43
+ @it.value.is_a?(Integer).should == true
44
+ end
45
+
46
+ # Weight
47
+ it '@weight should return the right weight' do
48
+ @it.weight.should == MonkeyActionEat::WEIGHT
49
+ end
50
+
51
+ # validate
52
+ it "should not raise an error if value is within acceptable range" do
53
+ monkey = MonkeyFactory.create(:eating_monkey2)
54
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
55
+ lambda { MonkeyActionEat.new(monkey, 40) }.should_not raise_error
56
+ end
57
+
58
+ it "should raise an error if value is the wrong type" do
59
+ monkey = MonkeyFactory.create(:eating_monkey3)
60
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
61
+ lambda { MonkeyActionEat.new(monkey, :wrong_type) }.should \
62
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
63
+ end
64
+
65
+ it "should raise an error if value is less than min acceptable range" do
66
+ monkey = MonkeyFactory.create(:eating_monkey4)
67
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
68
+ lambda { MonkeyActionEat.new(monkey, 29) }.should \
69
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
70
+ end
71
+
72
+ it "should raise an error if value is greater than max acceptable range" do
73
+ monkey = MonkeyFactory.create(:eating_monkey5)
74
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
75
+ lambda { MonkeyActionEat.new(monkey, 61) }.should \
76
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
77
+ end
78
+
79
+ it "should raise an error if value is nil" do
80
+ monkey = MonkeyFactory.create(:eating_monkey6)
81
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
82
+ lambda { MonkeyActionEat.new(monkey, nil) }.should \
83
+ raise_error MonkeyEngine::Exceptions::NilArgumentException
84
+ end
85
+
86
+ end
@@ -0,0 +1,91 @@
1
+ require 'Monkey'
2
+ require 'MonkeyActions'
3
+ require 'MonkeyFactory'
4
+ require 'MonkeyEngine'
5
+ require 'MonkeyManager'
6
+
7
+ require_relative 'support/shared_examples'
8
+
9
+ describe 'MonkeyActionPause' do
10
+ before(:all) do
11
+
12
+ @monkey = MonkeyFactory.create :pausing_monkey1
13
+ @it = MonkeyActionPause.new @monkey, 1 # 1 second
14
+
15
+ MonkeyEngine::MonkeyManager.instance.add(@monkey)
16
+
17
+ end
18
+
19
+ after(:all) do
20
+ # Kill all the threads.
21
+ MonkeyEngine::MonkeyManager.instance.kill_all!
22
+
23
+ # Give them a little bit to finish.
24
+ MonkeyEngine::MonkeyManager.instance.join_all(10)
25
+ end
26
+
27
+ it_should_behave_like 'MonkeyAction'
28
+
29
+ it '@it should be the correct type' do
30
+ @it.is_a?(MonkeyActionPause).should == true
31
+ end
32
+
33
+ # Monkey
34
+ it '@monkey be the same monkey' do
35
+ @it.monkey.should == @monkey
36
+ end
37
+
38
+ # Value
39
+ it '@value should return the right value' do
40
+ @it.value.should == 1
41
+ end
42
+
43
+ it "@value should be is_a? Integer" do
44
+ @it.value.is_a?(Integer).should == true
45
+ end
46
+
47
+ it "@value should >= 1" do
48
+ (@it.value >= 1).should == true
49
+ end
50
+
51
+ # Weight
52
+ it '@weight should return the right weight' do
53
+ @it.weight.should == MonkeyActionPause::WEIGHT
54
+ end
55
+
56
+ # validate
57
+ it "should not raise an error if value is within acceptable range" do
58
+ monkey = MonkeyFactory.create(:pausing_monkey2)
59
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
60
+ lambda { MonkeyActionPause.new(monkey, 5) }.should_not raise_error
61
+ end
62
+
63
+ it "should raise an error if value is the wrong type" do
64
+ monkey = MonkeyFactory.create(:pausing_monkey3)
65
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
66
+ lambda { MonkeyActionPause.new(monkey, :wrong_type) }.should \
67
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
68
+ end
69
+
70
+ it "should raise an error if value is less than min acceptable range" do
71
+ monkey = MonkeyFactory.create(:pausing_monkey4)
72
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
73
+ lambda { MonkeyActionPause.new(monkey, -1) }.should \
74
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
75
+ end
76
+
77
+ it "should raise an error if value is greater than max acceptable range" do
78
+ monkey = MonkeyFactory.create(:pausing_monkey5)
79
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
80
+ lambda { MonkeyActionPause.new(monkey, 61) }.should \
81
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
82
+ end
83
+
84
+ it "should raise an error if value is nil" do
85
+ monkey = MonkeyFactory.create(:pausing_monkey6)
86
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
87
+ lambda { MonkeyActionPause.new(monkey, nil) }.should \
88
+ raise_error MonkeyEngine::Exceptions::NilArgumentException
89
+ end
90
+
91
+ end
@@ -0,0 +1,90 @@
1
+ require 'Monkey'
2
+ require 'MonkeyActions'
3
+ require 'MonkeyFactory'
4
+ require 'MonkeyEngine'
5
+
6
+ require_relative 'support/shared_examples'
7
+
8
+ describe 'MonkeyActionSleep' do
9
+ before(:all) do
10
+
11
+ @monkey = MonkeyFactory.create :sleeping_monkey1
12
+ @it = MonkeyActionSleep.new @monkey, 60 * 8 # milliseconds
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?(MonkeyActionSleep).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 == 60 * 8
40
+ end
41
+
42
+ it "@value should be is_a? Integer" do
43
+ @it.value.is_a?(Integer).should == true
44
+ end
45
+
46
+ it "@value should equal 60 * 8" do
47
+ (@it.value == 60 * 8).should == true
48
+ end
49
+
50
+ # Weight
51
+ it '@weight should return the right weight' do
52
+ @it.weight.should == MonkeyActionSleep::WEIGHT
53
+ end
54
+
55
+ # validate
56
+ it "should not raise an error if value is within acceptable range" do
57
+ monkey = MonkeyFactory.create(:sleeping_monkey2)
58
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
59
+ lambda { MonkeyActionSleep.new(monkey, 60 * 8) }.should_not raise_error
60
+ end
61
+
62
+ it "should raise an error if value is the wrong type" do
63
+ monkey = MonkeyFactory.create(:sleeping_monkey3)
64
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
65
+ lambda { MonkeyActionSleep.new(monkey, :wrong_type) }.should \
66
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
67
+ end
68
+
69
+ it "should raise an error if value is less than min acceptable range" do
70
+ monkey = MonkeyFactory.create(:sleeping_monkey4)
71
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
72
+ lambda { MonkeyActionSleep.new(monkey, 60 * 5) }.should \
73
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
74
+ end
75
+
76
+ it "should raise an error if value is greater than max acceptable range" do
77
+ monkey = MonkeyFactory.create(:sleeping_monkey5)
78
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
79
+ lambda { MonkeyActionSleep.new(monkey, 60 * 9) }.should \
80
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
81
+ end
82
+
83
+ it "should raise an error if value is nil" do
84
+ monkey = MonkeyFactory.create(:sleeping_monkey6)
85
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
86
+ lambda { MonkeyActionSleep.new(monkey, nil) }.should \
87
+ raise_error MonkeyEngine::Exceptions::NilArgumentException
88
+ end
89
+
90
+ end
@@ -0,0 +1,94 @@
1
+ require 'Monkey'
2
+ require 'MonkeyActions'
3
+ require 'MonkeyFactory'
4
+ require 'MonkeyEngine'
5
+ require_relative '../lib/MonkeyKeyboard/keyboard_input'
6
+
7
+ require_relative 'support/shared_examples'
8
+
9
+ describe 'MonkeyActionType' do
10
+ before(:all) do
11
+
12
+ @monkey = MonkeyFactory::create :typing_monkey1
13
+
14
+ keyboard_input = KeyboardInput.new
15
+ keyboard_input.input = %w{a b c d e f .}
16
+
17
+ @it = MonkeyActionType.new @monkey, keyboard_input
18
+
19
+ MonkeyEngine::MonkeyManager.instance.add(@monkey)
20
+ end
21
+
22
+ after(:all) do
23
+ # Kill all the threads.
24
+ MonkeyEngine::MonkeyManager.instance.kill_all!
25
+
26
+ # Give them a little bit to finish.
27
+ MonkeyEngine::MonkeyManager.instance.join_all(10)
28
+ end
29
+
30
+ it_should_behave_like 'MonkeyAction'
31
+
32
+ it '@it should be the correct type' do
33
+ @it.is_a?(MonkeyActionType).should == true
34
+ end
35
+
36
+ # Monkey
37
+ it '@monkey be the same monkey' do
38
+ @it.monkey.should == @monkey
39
+ end
40
+
41
+ # Value
42
+ it '@value should return the right value' do
43
+ @it.value.should == %w{a b c d e f .}
44
+ end
45
+
46
+ it "@value should be is_a? Array" do
47
+ @it.value.is_a?(Array).should == true
48
+ end
49
+
50
+ it "@value should not be nil?" do
51
+ @it.value.nil?.should_not == true
52
+ end
53
+
54
+ # Weight
55
+ it '@weight should return the right weight' do
56
+ @it.weight.should == MonkeyActionType::WEIGHT
57
+ end
58
+
59
+ # validate
60
+ it "should not raise an error if value is valid" do
61
+ monkey = MonkeyFactory::create(:typing_monkey2)
62
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
63
+
64
+ keyboard_input = KeyboardInput.new
65
+ keyboard_input.input = %w{w o r d .}
66
+
67
+ lambda { MonkeyActionType.new(monkey, keyboard_input) }.should_not raise_error
68
+ end
69
+
70
+ it "should raise an error if value is the wrong type" do
71
+ monkey = MonkeyFactory::create(:typing_monkey3)
72
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
73
+ lambda { MonkeyActionType.new(monkey, :wrong_type) }.should \
74
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentTypeException
75
+ end
76
+
77
+ it "should raise an error if value is empty?" do
78
+ monkey = MonkeyFactory::create(:typing_monkey4)
79
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
80
+
81
+ keyboard_input = KeyboardInput.new
82
+ keyboard_input.input = %w{}
83
+
84
+ lambda { MonkeyActionType.new(monkey, keyboard_input) }.should \
85
+ raise_error MonkeyEngine::Exceptions::InvalidArgumentValueException
86
+ end
87
+
88
+ it "should raise an error if value is nil" do
89
+ monkey = MonkeyFactory::create(:typing_monkey5)
90
+ MonkeyEngine::MonkeyManager.instance.add(monkey)
91
+ lambda { MonkeyActionType.new(monkey, nil) }.should \
92
+ raise_error MonkeyEngine::Exceptions::NilArgumentException
93
+ end
94
+ end