zombie-chaser 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/History.txt +22 -0
  2. data/README.txt +57 -47
  3. data/Rakefile +26 -24
  4. data/bin/zombie-chaser +77 -79
  5. data/lib/{chaser.rb → zombie-chaser/chaser.rb} +392 -373
  6. data/lib/zombie-chaser/human.rb +312 -0
  7. data/{ui → lib/zombie-chaser}/icons/death.png +0 -0
  8. data/{ui → lib/zombie-chaser}/icons/robot.png +0 -0
  9. data/lib/zombie-chaser/interface.rb +153 -0
  10. data/{ui → lib/zombie-chaser}/sprites/robot-attacking.png +0 -0
  11. data/{ui → lib/zombie-chaser}/sprites/robot-dead.png +0 -0
  12. data/{ui → lib/zombie-chaser}/sprites/robot-dying.png +0 -0
  13. data/{ui → lib/zombie-chaser}/sprites/robot-idle.png +0 -0
  14. data/{ui → lib/zombie-chaser}/sprites/robot-moving.png +0 -0
  15. data/{ui → lib/zombie-chaser}/sprites/robot-turning.png +0 -0
  16. data/{ui → lib/zombie-chaser}/sprites/tank-attacking.png +0 -0
  17. data/{ui → lib/zombie-chaser}/sprites/tank-dead.png +0 -0
  18. data/{ui → lib/zombie-chaser}/sprites/tank-idle.png +0 -0
  19. data/{ui → lib/zombie-chaser}/sprites/tank-moving.png +0 -0
  20. data/{ui → lib/zombie-chaser}/sprites/tank-turning.png +0 -0
  21. data/{ui → lib/zombie-chaser}/sprites/witch-attacking.png +0 -0
  22. data/{ui → lib/zombie-chaser}/sprites/witch-dead.png +0 -0
  23. data/{ui → lib/zombie-chaser}/sprites/witch-idle.png +0 -0
  24. data/{ui → lib/zombie-chaser}/sprites/witch-moving.png +0 -0
  25. data/{ui → lib/zombie-chaser}/sprites/witch-turning.png +0 -0
  26. data/{ui → lib/zombie-chaser}/sprites/zombie-attacking.png +0 -0
  27. data/{ui → lib/zombie-chaser}/sprites/zombie-dead.png +0 -0
  28. data/{ui → lib/zombie-chaser}/sprites/zombie-dying.png +0 -0
  29. data/{ui → lib/zombie-chaser}/sprites/zombie-idle.png +0 -0
  30. data/{ui → lib/zombie-chaser}/sprites/zombie-moving.png +0 -0
  31. data/{ui → lib/zombie-chaser}/sprites/zombie-turning.png +0 -0
  32. data/lib/zombie-chaser/test_unit_handler.rb +78 -0
  33. data/{ui → lib/zombie-chaser}/tiles/grass.png +0 -0
  34. data/{ui → lib/zombie-chaser}/tiles/shrubbery.png +0 -0
  35. data/{ui → lib/zombie-chaser}/ui.rb +165 -127
  36. data/lib/{world.rb → zombie-chaser/world.rb} +105 -98
  37. data/lib/zombie-chaser/zombie_test_chaser.rb +139 -0
  38. data/test/fixtures/chased.rb +56 -56
  39. data/test/integration.rb +58 -0
  40. data/test/test_chaser.rb +150 -144
  41. data/test/test_unit.rb +2 -2
  42. data/test/test_zombie.rb +302 -108
  43. data/zombie-chaser.gemspec +88 -88
  44. metadata +40 -46
  45. data/lib/human.rb +0 -189
  46. data/lib/interface.rb +0 -86
  47. data/lib/test_unit_handler.rb +0 -43
  48. data/lib/zombie_test_chaser.rb +0 -133
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie-chaser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Grimm
@@ -12,19 +12,10 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-12-13 00:00:00 +11:00
15
+ date: 2010-04-11 00:00:00 +10:00
16
16
  default_executable: zombie-chaser
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: gosu
20
- type: :runtime
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: "0"
27
- version:
17
+ dependencies: []
18
+
28
19
  description: A zombie-themed graphic(al) user interface for mutation testing
29
20
  email: andrew.j.grimm@gmail.com
30
21
  executables:
@@ -34,46 +25,48 @@ extensions: []
34
25
  extra_rdoc_files:
35
26
  - README.txt
36
27
  files:
28
+ - History.txt
37
29
  - README.txt
38
30
  - Rakefile
39
31
  - bin/zombie-chaser
40
- - lib/chaser.rb
41
- - lib/human.rb
42
- - lib/interface.rb
43
- - lib/test_unit_handler.rb
44
- - lib/world.rb
45
- - lib/zombie_test_chaser.rb
32
+ - lib/zombie-chaser/chaser.rb
33
+ - lib/zombie-chaser/human.rb
34
+ - lib/zombie-chaser/icons/death.png
35
+ - lib/zombie-chaser/icons/robot.png
36
+ - lib/zombie-chaser/interface.rb
37
+ - lib/zombie-chaser/sprites/robot-attacking.png
38
+ - lib/zombie-chaser/sprites/robot-dead.png
39
+ - lib/zombie-chaser/sprites/robot-dying.png
40
+ - lib/zombie-chaser/sprites/robot-idle.png
41
+ - lib/zombie-chaser/sprites/robot-moving.png
42
+ - lib/zombie-chaser/sprites/robot-turning.png
43
+ - lib/zombie-chaser/sprites/tank-attacking.png
44
+ - lib/zombie-chaser/sprites/tank-dead.png
45
+ - lib/zombie-chaser/sprites/tank-idle.png
46
+ - lib/zombie-chaser/sprites/tank-moving.png
47
+ - lib/zombie-chaser/sprites/tank-turning.png
48
+ - lib/zombie-chaser/sprites/witch-attacking.png
49
+ - lib/zombie-chaser/sprites/witch-dead.png
50
+ - lib/zombie-chaser/sprites/witch-idle.png
51
+ - lib/zombie-chaser/sprites/witch-moving.png
52
+ - lib/zombie-chaser/sprites/witch-turning.png
53
+ - lib/zombie-chaser/sprites/zombie-attacking.png
54
+ - lib/zombie-chaser/sprites/zombie-dead.png
55
+ - lib/zombie-chaser/sprites/zombie-dying.png
56
+ - lib/zombie-chaser/sprites/zombie-idle.png
57
+ - lib/zombie-chaser/sprites/zombie-moving.png
58
+ - lib/zombie-chaser/sprites/zombie-turning.png
59
+ - lib/zombie-chaser/test_unit_handler.rb
60
+ - lib/zombie-chaser/tiles/grass.png
61
+ - lib/zombie-chaser/tiles/shrubbery.png
62
+ - lib/zombie-chaser/ui.rb
63
+ - lib/zombie-chaser/world.rb
64
+ - lib/zombie-chaser/zombie_test_chaser.rb
46
65
  - test/fixtures/chased.rb
66
+ - test/integration.rb
47
67
  - test/test_chaser.rb
48
68
  - test/test_unit.rb
49
69
  - test/test_zombie.rb
50
- - ui/icons/death.png
51
- - ui/icons/robot.png
52
- - ui/sprites/robot-attacking.png
53
- - ui/sprites/robot-dead.png
54
- - ui/sprites/robot-dying.png
55
- - ui/sprites/robot-idle.png
56
- - ui/sprites/robot-moving.png
57
- - ui/sprites/robot-turning.png
58
- - ui/sprites/tank-attacking.png
59
- - ui/sprites/tank-dead.png
60
- - ui/sprites/tank-idle.png
61
- - ui/sprites/tank-moving.png
62
- - ui/sprites/tank-turning.png
63
- - ui/sprites/witch-attacking.png
64
- - ui/sprites/witch-dead.png
65
- - ui/sprites/witch-idle.png
66
- - ui/sprites/witch-moving.png
67
- - ui/sprites/witch-turning.png
68
- - ui/sprites/zombie-attacking.png
69
- - ui/sprites/zombie-dead.png
70
- - ui/sprites/zombie-dying.png
71
- - ui/sprites/zombie-idle.png
72
- - ui/sprites/zombie-moving.png
73
- - ui/sprites/zombie-turning.png
74
- - ui/tiles/grass.png
75
- - ui/tiles/shrubbery.png
76
- - ui/ui.rb
77
70
  - zombie-chaser.gemspec
78
71
  has_rdoc: true
79
72
  homepage: http://andrewjgrimm.wordpress.com/2009/11/08/declare-war-on-everything-with-chaser/
@@ -105,6 +98,7 @@ specification_version: 3
105
98
  summary: Lightweight mutation testing ... with ZOMBIES!!!
106
99
  test_files:
107
100
  - test/fixtures/chased.rb
101
+ - test/integration.rb
108
102
  - test/test_chaser.rb
109
103
  - test/test_unit.rb
110
104
  - test/test_zombie.rb
data/lib/human.rb DELETED
@@ -1,189 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. ui])
2
-
3
- require "test_unit_handler"
4
- require "ui" #For actor superclass
5
-
6
- class Human < Actor
7
- private_class_method :new
8
- attr_reader :successful_step_count
9
-
10
- def self.new_using_test_unit_handler(test_pattern, world)
11
- new(test_pattern, world)
12
- end
13
-
14
- def initialize(test_pattern, world)
15
- @status = nil #Currently only used by zombie
16
- @world = world
17
- @successful_step_count = 0
18
- @health = :alive
19
- @test_handler = TestUnitHandler.new(test_pattern, self)
20
- end
21
-
22
- def run
23
- notify_world
24
- @test_handler.run
25
- end
26
-
27
- def current_symbol
28
- case @health
29
- when :alive
30
- "@"
31
- when :dying
32
- "*"
33
- when :dead
34
- "+"
35
- end
36
- end
37
-
38
- def actor_type
39
- 'robot'
40
- end
41
-
42
- def actor_state
43
- return "attacking" if @status == :attacking
44
- case @health
45
- when :alive
46
- "moving"
47
- when :dying
48
- "dying"
49
- when :dead
50
- "dead"
51
- end
52
- end
53
-
54
- def actor_direction
55
- 270.0
56
- end
57
-
58
- def notify_passing_step
59
- @successful_step_count += 1
60
- notify_world
61
- end
62
-
63
- def notify_failing_step
64
- @health = :dying
65
- notify_world
66
- end
67
-
68
- def dying?
69
- @health == :dying
70
- end
71
-
72
- def dead?
73
- @health == :dead
74
- end
75
-
76
- def finish_dying
77
- sleep 0.5
78
- raise "I'm not dead yet!" unless dying?
79
- @health = :dead
80
- notify_world
81
- sleep 0.5
82
- end
83
-
84
- def notify_world
85
- @world.something_happened
86
- end
87
-
88
- def get_eaten
89
- @health = :dying unless dead?
90
- end
91
-
92
- def test_suite_size
93
- @test_handler.test_suite_size
94
- end
95
-
96
- end
97
-
98
- class MockHuman < Human
99
- private_class_method :new
100
-
101
- def self.new_using_results(results, world)
102
- new(results, world)
103
- end
104
-
105
- def initialize(results, world)
106
- @world = world
107
- @results = results
108
- @successful_step_count = 0
109
- @health = :alive
110
- end
111
-
112
- def run
113
- until @successful_step_count == @results.size
114
- if @results[@successful_step_count] == :failure
115
- @health = :dying
116
- notify_world
117
- return
118
- end
119
- notify_world
120
- @successful_step_count += 1
121
- end
122
- notify_world
123
- end
124
-
125
- def test_suite_size
126
- @results.size
127
- end
128
- end
129
-
130
- class MockZombieList
131
-
132
- def self.new_using_results(zombies_results, world)
133
- zombies = zombies_results.map do |zombie_results|
134
- MockZombie.new_using_results(zombie_results, world)
135
- end
136
- new(zombies)
137
- end
138
-
139
- def initialize(zombies)
140
- @zombies = zombies
141
- @current_zombie_number = 0
142
- end
143
-
144
- def supply_next_zombie
145
- zombie = @zombies[@current_zombie_number]
146
- @current_zombie_number += 1
147
- zombie
148
- end
149
-
150
- def all_slain?
151
- @current_zombie_number == @zombies.length
152
- end
153
- end
154
-
155
- module ZombieInterface
156
- def current_symbol
157
- case @health
158
- when :alive
159
- "Z"
160
- when :dying
161
- "*"
162
- when :dead
163
- "+"
164
- end
165
- end
166
-
167
- def actor_type
168
- 'zombie'
169
- end
170
-
171
- def actor_direction
172
- 90.0
173
- end
174
-
175
- end
176
-
177
- class Zombie < Human
178
- include ZombieInterface
179
-
180
- def eat(human)
181
- @status = :attacking #Even if the human's dead, look for leftovers
182
- human.get_eaten
183
- end
184
- end
185
-
186
- class MockZombie < MockHuman #Fixme provide a proper hierarchy
187
- include ZombieInterface
188
-
189
- end
data/lib/interface.rb DELETED
@@ -1,86 +0,0 @@
1
- class Interface
2
- attr_writer :human, :current_zombie
3
- end
4
-
5
- class ConsoleInterface < Interface
6
-
7
- def initialize
8
- @representations = []
9
- @current_zombie = nil
10
- end
11
-
12
- def current_representation
13
- if @current_zombie.nil?
14
- "." * human_position + @human.current_symbol
15
- elsif human_position > zombie_position
16
- "." * zombie_position + @current_zombie.current_symbol + "." * (human_position - zombie_position - 1) + @human.current_symbol
17
- else
18
- "." * zombie_position + @current_zombie.current_symbol
19
- end
20
- end
21
-
22
- def something_happened
23
- @representations << current_representation
24
- display_representation(@representations.last)
25
- end
26
-
27
- def display_representation(representation)
28
- print "\r", representation
29
- STDOUT.flush
30
- sleep 0.2
31
- end
32
-
33
- def finish
34
- puts
35
- end
36
-
37
- def human_position
38
- adjust_for_screen_width(@human.successful_step_count)
39
- end
40
-
41
- def zombie_position
42
- adjust_for_screen_width(@current_zombie.successful_step_count)
43
- end
44
-
45
- def adjust_for_screen_width(step_count)
46
- max_position = 78.0
47
- (step_count * max_position / [@human.test_suite_size, max_position].max).round
48
- end
49
-
50
- end
51
-
52
- class NoInterface < ConsoleInterface
53
- attr_reader :representations
54
-
55
- def display_representation(representation)
56
- #Do nothing
57
- end
58
-
59
- def finish
60
- #Do nothing
61
- end
62
- end
63
-
64
- class GuiInterface < Interface
65
-
66
- def initialize
67
- @window = Window.new
68
- #Actor.window = @window #Fixme why can't this do the trick?
69
- Human.window = @window
70
- Zombie.window = @window
71
- @window_showing_thread = Thread.new {@window.show}
72
- end
73
-
74
- #Doesn't need to be used, as window updates 60 times a second anyway
75
- def something_happened
76
- end
77
-
78
- def human=(human)
79
- @window.human = human
80
- end
81
-
82
- def current_zombie=(current_zombie)
83
- @window.current_zombie = current_zombie
84
- end
85
-
86
- end
@@ -1,43 +0,0 @@
1
- require "test/unit/collector/objectspace"
2
- require "test/unit/ui/testrunnermediator"
3
-
4
- class TestUnitHandler
5
- attr_reader :results, :test_suite_size
6
-
7
- def initialize(test_pattern, actor)
8
- @actor = actor
9
- raise "Error: can't detect any files in test pattern \"#{test_pattern} (Don't forget to use forward slashes even in Windows)" if Dir.glob(test_pattern).empty?
10
- Dir.glob(test_pattern).each {|test| require test} #In heckle, this is separated out
11
- @finished = false
12
- @results = []
13
- @step_count = 0
14
- obj_sp = Test::Unit::Collector::ObjectSpace.new
15
- test_suite = Test::Unit::TestSuite.new("Mutation slayer test suite")
16
- test_suite << obj_sp.collect
17
- @test_suite_size = test_suite.size
18
- @test_runner_mediator = Test::Unit::UI::TestRunnerMediator.new(test_suite)
19
- @test_runner_mediator.add_listener(Test::Unit::TestResult::FAULT) {test_failed}
20
- @test_runner_mediator.add_listener(Test::Unit::TestCase::FINISHED) {test_finished}
21
-
22
- end
23
-
24
- def run
25
- catch(:stop_test_runner) do
26
- @test_runner_mediator.run_suite
27
- end
28
- end
29
-
30
- def test_failed
31
- @results << :failure
32
- @actor.notify_failing_step
33
- sleep 0.5
34
- throw :stop_test_runner
35
- end
36
-
37
- def test_finished
38
- sleep 0.1 #Hack to avoid it being too quick
39
- @results << :pass
40
- @actor.notify_passing_step
41
- end
42
-
43
- end
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "test/unit/collector/objectspace"
4
- require "test/unit/ui/testrunnermediator"
5
- require 'chaser'
6
-
7
- $: << 'lib' << 'test'
8
-
9
- # Make sure test/unit doesn't swallow our timeout
10
- begin
11
- Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS << Chaser::Timeout
12
- rescue NameError
13
- # ignore
14
- end
15
-
16
- class ZombieTestChaser < Chaser
17
-
18
- VERSION = '0.0.3'
19
-
20
- @@test_pattern = 'test/test_*.rb'
21
- @@tests_loaded = false
22
- @@world = nil
23
-
24
- def self.test_pattern=(value)
25
- @@test_pattern = value
26
- end
27
-
28
- def self.create_world
29
- @@tests_loaded = true
30
- @@world = World.new_using_test_unit_handler(@@test_pattern)
31
- end
32
-
33
- def self.world
34
- @@world
35
- end
36
-
37
- def self.current_class_names(exclude_list)
38
- result = []
39
- ObjectSpace.each_object(Class) do |klass|
40
- next if klass.to_s.include?("Class:0x")
41
- next unless klass.ancestors.all? {|ancestor| (ancestor.to_s.split(/::/) & exclude_list).empty?}
42
- result << klass.to_s
43
- end
44
- result
45
- end
46
-
47
- def self.validate(klass_name = nil, method_name = nil, force = false)
48
- pre_existing_class_names = self.current_class_names([]) unless klass_name
49
- create_world
50
-
51
- if klass_name
52
- klass = klass_name.to_class
53
- # Does the method exist?
54
- klass_methods = klass.singleton_methods(false).collect {|meth| "self.#{meth}"}
55
- if method_name
56
- if method_name =~ /self\./
57
- abort "Unknown method: #{klass_name}.#{method_name.gsub('self.', '')}" unless klass_methods.include? method_name
58
- else
59
- abort "Unknown method: #{klass_name}##{method_name}" unless klass.instance_methods(false).map{|sym| sym.to_s}.include? method_name
60
- end
61
- end
62
- end
63
-
64
- initial_time = Time.now
65
-
66
- chaser = self.new(klass_name)
67
-
68
- passed = chaser.human_survives?
69
-
70
- unless force or passed then
71
- abort "Initial run of tests failed... fix and run chaser again"
72
- end
73
-
74
- if self.guess_timeout? then
75
- running_time = Time.now - initial_time
76
- adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2).ceil
77
- self.timeout = adjusted_timeout
78
- end
79
-
80
- puts "Timeout set to #{adjusted_timeout} seconds."
81
-
82
- if passed then
83
- puts "Initial tests pass. Let's rumble."
84
- else
85
- puts "Initial tests failed but you forced things. Let's rumble."
86
- end
87
- puts
88
-
89
- counts = Hash.new(0)
90
-
91
- klass_names = klass_name ? Array(klass_name) : self.current_class_names(["Test"]) - pre_existing_class_names
92
- klass_names.each do |block_klass_name|
93
- block_klass = block_klass_name.to_class
94
-
95
- methods = method_name ? Array(method_name) : block_klass.instance_methods(false) + block_klass.singleton_methods(false).collect {|meth| "self.#{meth}"}
96
-
97
- methods.sort.each do |block_method_name|
98
- result = self.new(block_klass_name, block_method_name).validate
99
- counts[result] += 1
100
- end
101
- end
102
- all_good = counts[false] == 0
103
-
104
- puts "Chaser Results:"
105
- puts
106
- puts "Passed : %3d" % counts[true]
107
- puts "Failed : %3d" % counts[false]
108
- puts
109
-
110
- if all_good then
111
- puts "All chasing was thwarted! YAY!!!"
112
- else
113
- puts "Improve the tests and try again."
114
- end
115
-
116
- all_good
117
- end
118
-
119
- def human_survives?
120
- self.class.world.run_human
121
- end
122
-
123
- def zombie_survives?
124
- zombie = self.class.world.create_zombie_using_test_unit_handler
125
- self.class.world.run_zombie(zombie)
126
- end
127
-
128
- def initialize(klass_name=nil, method_name=nil)
129
- super
130
- self.class.create_world unless @@tests_loaded
131
- end
132
-
133
- end