zombie-chaser 0.0.2 → 0.0.3
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.
- data/bin/zombie-chaser +14 -0
- data/lib/human.rb +9 -0
- data/lib/interface.rb +29 -20
- data/lib/test_unit_handler.rb +2 -1
- data/lib/world.rb +7 -2
- data/lib/zombie_test_chaser.rb +1 -1
- data/test/test_zombie.rb +17 -4
- data/ui/ui.rb +12 -2
- data/zombie-chaser.gemspec +2 -2
- metadata +2 -2
data/bin/zombie-chaser
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
#!/usr/local/bin/ruby
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. ui])
|
4
5
|
require 'zombie_test_chaser'
|
6
|
+
require 'ui'
|
5
7
|
require 'optparse'
|
6
8
|
|
7
9
|
force = false
|
@@ -38,6 +40,18 @@ opts = OptionParser.new do |opts|
|
|
38
40
|
puts "Setting timeout at #{timeout} seconds."
|
39
41
|
end
|
40
42
|
|
43
|
+
opts.on("--width PIXELS", "Width of screen in pixels") do |width|
|
44
|
+
Window.width = Integer(width)
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("--height PIXELS", "Height of screen in pixels") do |height|
|
48
|
+
Window.height = Integer(height)
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("--console", "Use nethack-style text interface") do |opt|
|
52
|
+
World.interface_type = :console_interface
|
53
|
+
end
|
54
|
+
|
41
55
|
opts.on("-r", "--random-seed SEED", "Random seed number (under development)") do |seed|
|
42
56
|
srand(seed.to_i)
|
43
57
|
end
|
data/lib/human.rb
CHANGED
@@ -88,6 +88,11 @@ class Human < Actor
|
|
88
88
|
def get_eaten
|
89
89
|
@health = :dying unless dead?
|
90
90
|
end
|
91
|
+
|
92
|
+
def test_suite_size
|
93
|
+
@test_handler.test_suite_size
|
94
|
+
end
|
95
|
+
|
91
96
|
end
|
92
97
|
|
93
98
|
class MockHuman < Human
|
@@ -116,6 +121,10 @@ class MockHuman < Human
|
|
116
121
|
end
|
117
122
|
notify_world
|
118
123
|
end
|
124
|
+
|
125
|
+
def test_suite_size
|
126
|
+
@results.size
|
127
|
+
end
|
119
128
|
end
|
120
129
|
|
121
130
|
class MockZombieList
|
data/lib/interface.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
class Interface
|
2
2
|
attr_writer :human, :current_zombie
|
3
|
+
end
|
4
|
+
|
5
|
+
class ConsoleInterface < Interface
|
3
6
|
|
4
7
|
def initialize
|
5
8
|
@representations = []
|
@@ -8,47 +11,53 @@ class Interface
|
|
8
11
|
|
9
12
|
def current_representation
|
10
13
|
if @current_zombie.nil?
|
11
|
-
"." *
|
12
|
-
elsif
|
13
|
-
"." *
|
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
|
14
17
|
else
|
15
|
-
"." *
|
18
|
+
"." * zombie_position + @current_zombie.current_symbol
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def human_successful_step_count
|
20
|
-
@human.successful_step_count
|
21
|
-
end
|
22
|
-
|
23
22
|
def something_happened
|
24
23
|
@representations << current_representation
|
25
24
|
display_representation(@representations.last)
|
26
25
|
end
|
27
26
|
|
28
|
-
end
|
29
|
-
|
30
|
-
class NoInterface < Interface
|
31
|
-
attr_reader :representations
|
32
|
-
|
33
27
|
def display_representation(representation)
|
34
|
-
|
28
|
+
print "\r", representation
|
29
|
+
STDOUT.flush
|
30
|
+
sleep 0.2
|
35
31
|
end
|
36
32
|
|
37
33
|
def finish
|
38
|
-
|
34
|
+
puts
|
39
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
|
+
|
40
50
|
end
|
41
51
|
|
42
|
-
class
|
52
|
+
class NoInterface < ConsoleInterface
|
53
|
+
attr_reader :representations
|
43
54
|
|
44
55
|
def display_representation(representation)
|
45
|
-
|
46
|
-
STDOUT.flush
|
47
|
-
sleep 0.2
|
56
|
+
#Do nothing
|
48
57
|
end
|
49
58
|
|
50
59
|
def finish
|
51
|
-
|
60
|
+
#Do nothing
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
data/lib/test_unit_handler.rb
CHANGED
@@ -2,7 +2,7 @@ require "test/unit/collector/objectspace"
|
|
2
2
|
require "test/unit/ui/testrunnermediator"
|
3
3
|
|
4
4
|
class TestUnitHandler
|
5
|
-
attr_reader :results
|
5
|
+
attr_reader :results, :test_suite_size
|
6
6
|
|
7
7
|
def initialize(test_pattern, actor)
|
8
8
|
@actor = actor
|
@@ -14,6 +14,7 @@ class TestUnitHandler
|
|
14
14
|
obj_sp = Test::Unit::Collector::ObjectSpace.new
|
15
15
|
test_suite = Test::Unit::TestSuite.new("Mutation slayer test suite")
|
16
16
|
test_suite << obj_sp.collect
|
17
|
+
@test_suite_size = test_suite.size
|
17
18
|
@test_runner_mediator = Test::Unit::UI::TestRunnerMediator.new(test_suite)
|
18
19
|
@test_runner_mediator.add_listener(Test::Unit::TestResult::FAULT) {test_failed}
|
19
20
|
@test_runner_mediator.add_listener(Test::Unit::TestCase::FINISHED) {test_finished}
|
data/lib/world.rb
CHANGED
@@ -2,7 +2,12 @@ require "human"
|
|
2
2
|
require "interface"
|
3
3
|
|
4
4
|
class World
|
5
|
-
|
5
|
+
@interface_type = :gui_interface
|
6
|
+
|
7
|
+
def self.interface_type=(interface_type); @interface_type = interface_type end
|
8
|
+
def self.interface_type; @interface_type end
|
9
|
+
|
10
|
+
attr_reader :interface
|
6
11
|
|
7
12
|
def self.new_using_results(human_results, zombies_results)
|
8
13
|
world = new(:no_interface)
|
@@ -14,7 +19,7 @@ class World
|
|
14
19
|
end
|
15
20
|
|
16
21
|
def self.new_using_test_unit_handler(test_pattern)
|
17
|
-
world = new(
|
22
|
+
world = new(self.interface_type)
|
18
23
|
human = Human.new_using_test_unit_handler(test_pattern, world)
|
19
24
|
zombie_list = MockZombieList.new_using_results([], world) #Fixme
|
20
25
|
world.set_human(human)
|
data/lib/zombie_test_chaser.rb
CHANGED
data/test/test_zombie.rb
CHANGED
@@ -6,15 +6,15 @@ require "world"
|
|
6
6
|
module TestHumanHelper
|
7
7
|
def assert_that_representations_include(expected_representation, human_results, failure_message)
|
8
8
|
world = create_world(human_results)
|
9
|
-
|
10
|
-
assert
|
9
|
+
actual_representations = world.interface.representations
|
10
|
+
assert actual_representations.include?(expected_representation), failure_message + "Expected #{expected_representation}, got #{actual_representations.inspect}"
|
11
11
|
end
|
12
12
|
|
13
13
|
def assert_that_representations_include_these_representations(expected_representations, human_results, zombies_results, failure_message)
|
14
14
|
world = create_world(human_results, zombies_results)
|
15
|
-
|
15
|
+
actual_representations = world.interface.representations
|
16
16
|
expected_representations.each do |expected_representation|
|
17
|
-
assert
|
17
|
+
assert actual_representations.include?(expected_representation), failure_message + ": Expected #{expected_representation}, got #{actual_representations.inspect}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -93,3 +93,16 @@ class TestZombie < Test::Unit::TestCase
|
|
93
93
|
end
|
94
94
|
|
95
95
|
end
|
96
|
+
|
97
|
+
class TestConsoleInterface < Test::Unit::TestCase
|
98
|
+
include TestHumanHelper
|
99
|
+
|
100
|
+
def test_excessive_tests_dont_make_it_run_off_the_page
|
101
|
+
human_results = [:pass] * 500
|
102
|
+
zombies_results = [[:pass, :failure]]
|
103
|
+
expected_representations = ["Z" + "." * 77 + "@"] #Having 80 characters in a line doesn't work
|
104
|
+
failure_message = "Doesn't handle large number of tests properly"
|
105
|
+
assert_that_representations_include_these_representations(expected_representations, human_results, zombies_results, failure_message)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/ui/ui.rb
CHANGED
@@ -34,7 +34,9 @@ class Actor
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def x
|
37
|
-
|
37
|
+
max_position = Window.width - 10
|
38
|
+
left_offset = 10
|
39
|
+
left_offset + ((@successful_step_count * 10) * (max_position - left_offset) / [test_suite_size * 10 + 10, (max_position - left_offset)].max).round
|
38
40
|
end
|
39
41
|
|
40
42
|
def y
|
@@ -52,12 +54,20 @@ class Actor
|
|
52
54
|
end
|
53
55
|
|
54
56
|
class Window < Gosu::Window
|
57
|
+
@width = 400
|
58
|
+
@height = 300
|
59
|
+
|
60
|
+
def self.width=(width); @width = width end
|
61
|
+
def self.width; @width end
|
62
|
+
|
63
|
+
def self.height=(height); @height = height end
|
64
|
+
def self.height; @height end
|
55
65
|
|
56
66
|
attr_accessor :grid
|
57
67
|
attr_writer :human, :current_zombie
|
58
68
|
|
59
69
|
def initialize
|
60
|
-
super(
|
70
|
+
super(self.class.width, self.class.height, false)
|
61
71
|
|
62
72
|
self.caption = 'Zombie-chaser'
|
63
73
|
self.grid = 1
|
data/zombie-chaser.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zombie-chaser}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andrew Grimm", "Ryan Davis", "Eric Hodel", "Kevin Clark"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-13}
|
13
13
|
s.default_executable = %q{zombie-chaser}
|
14
14
|
s.description = %q{A zombie-themed graphic(al) user interface for mutation testing}
|
15
15
|
s.email = %q{andrew.j.grimm@gmail.com}
|
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Grimm
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-12-
|
15
|
+
date: 2009-12-13 00:00:00 +11:00
|
16
16
|
default_executable: zombie-chaser
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|