Permalink
Browse files

added rcov, deleted old test code moved relevant ones into specs

  • Loading branch information...
1 parent 9ff4695 commit e6f83007cfdb5f629aeaca385f63017e6eed4e2d @bgoodspeed committed Nov 5, 2010
View
@@ -51,7 +51,21 @@ Spec::Rake::SpecTask.new do |t|
t.libs << Dir["lib"]
end
+require 'rake'
+require 'spec/rake/verify_rcov'
+require 'spec/rake/spectask'
+
+desc "Run all examples with RCov"
+Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
+ t.spec_files = FileList['spec/**/*.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', 'spec', '--exclude', '/var/lib']
+end
+RCov::VerifyTask.new(:verify_rcov => 'examples_with_rcov') do |t|
+ t.threshold = 100.0
+ t.index_html = 'coverage/index.html'
+end
require 'cucumber'
require 'cucumber/rake/task'
@@ -53,7 +53,6 @@ def y_offset_for_world(wy)
def blit_to(palette, target)
0.upto(@y-1) do |yi|
0.upto(@x-1) do |xi|
-
datum = palette[data_at(xi,yi)]
datum.blit(target, [xi*@xsize, yi*@ysize])
end
@@ -84,18 +83,6 @@ def blit_foreground(palette, screen, px, py)
end
- def blit_with_pallette(palette, target, wmx, wmy)
- vdata = viewport_data_for(x_offset_for_world(wmx), y_offset_for_world(wmy), 4,3)
-
- 0.upto(3) do |yi|
- 0.upto(4) do |xi|
- palette[vdata[yi*@x+xi]].blit(target, [xi*160, yi*160])
- end
- end
-
- end
-
-
def to_json(*a)
{
'json_class' => self.class.name,
@@ -1,11 +1,13 @@
clean=Remove any temporary products.
clobber=Remove any generated file.
+clobber_examples_with_rcov=Remove rcov products for examples_with_rcov
clobber_package=Remove package products
clobber_rdoc=Remove rdoc products
default=
doc=
doc/rdoc=
doc/rdoc/index.html=
+examples_with_rcov=Run all examples with RCov
feature=Run Cucumber features
features=Run Cucumber features
gem=Build the gem file dopewars-0.0.1.gem
@@ -20,3 +22,4 @@ repackage=Force a rebuild of the package files
rerdoc=Force a rebuild of the RDOC files
spec=Run specs
test=Run tests
+verify_rcov=Verify that rcov coverage is at least 100.0%
@@ -0,0 +1,28 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+require 'spec/rspec_helper'
+
+describe EventManager do
+ include DomainMocks
+ before(:each) do
+ @game = mock_game
+ @event_manager = EventManager.new
+ end
+
+ def expect_hook_swap(game, off_hooks, on_hooks)
+ off_hooks.each {|h| game.should_receive(:remove_hook).with(h) }
+ on_hooks.each {|h| game.should_receive(:append_hook).with(h) }
+ end
+
+ it "turns event hooks on" do
+ expect_hook_swap(@game, [:x, :y], [:alpha, :beta])
+ @event_manager.swap_event_sets(@game, true, [:alpha, :beta], [:x, :y])
+ end
+
+ it "turns event hooks off" do
+ expect_hook_swap(@game, [:alpha, :beta], [:x, :y])
+ @event_manager.swap_event_sets(@game, false, [:alpha, :beta], [:x, :y])
+ end
+end
+
@@ -0,0 +1,136 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+require 'spec/rspec_helper'
+
+class FakeBlittable
+ def initialize(key)
+ @key = key
+ end
+
+ def blit(dest, offsets, py=nil, xi=nil, yi=nil)
+ dest << @key
+ end
+
+end
+
+class FakeTarget
+ attr_reader :blitted
+ def initialize(width=1, height=1)
+ @blitted = []
+ @width = width
+ @height = height
+ end
+ def <<(other)
+ @blitted << other
+ end
+ def w
+ @width
+ end
+ def h
+ @height
+ end
+end
+
+class FakePallette
+ def [](key)
+ FakeBlittable.new(key.upcase)
+ end
+end
+
+describe TopoMap do
+ before(:each) do
+ @topo = TopoMap.new(2,3, 200, 300, ['a', 'b','c','d','e','f'])
+ end
+
+ it "test_data_at" do
+ @topo.data_at(0,0).should == 'a'
+ @topo.data_at(1,0).should == 'b'
+ @topo.data_at(1,1).should == 'd'
+ @topo.data_at(1,2).should == 'f'
+ @topo.data_at(0,2).should == 'e'
+ end
+
+ it "test_viewport_data" do
+ @topo.viewport_data_for(0,0,1,1).should == ['a']
+ @topo.viewport_data_for(0,0,1,2).should == ['a', 'c']
+ @topo.viewport_data_for(0,0,2,1).should == ['a', 'b']
+ @topo.viewport_data_for(0,0,2,2).should == ['a', 'b', 'c', 'd']
+ @topo.viewport_data_for(1,0,1,1).should == ['b']
+ @topo.viewport_data_for(1,0,1,2).should == ['b', 'd']
+ end
+
+ it "test_can_calculate_offsets_from_world_coords" do
+ @topo.x_offset_for_world(0).should == 0
+ @topo.x_offset_for_world(99).should == 0
+ @topo.x_offset_for_world(101).should == 1
+
+ @topo.y_offset_for_world(0).should == 0
+ @topo.y_offset_for_world(99).should == 0
+ @topo.y_offset_for_world(101).should == 1
+ @topo.y_offset_for_world(199).should == 1
+ @topo.y_offset_for_world(201).should == 2
+
+ end
+
+ def mock_blittable
+ m = mock("blittable")
+ m.stub!(:blit)
+ m
+ end
+
+ def fake_pallette
+ FakePallette.new
+ end
+
+ def fake_target(w=1, h=1)
+ FakeTarget.new(w,h)
+ end
+
+ it "can blit to a pallette" do
+ t = fake_target
+ @topo.blit_to(fake_pallette, t)
+ t.blitted.should == ["A", "B","C", "D", "E", "F"]
+ end
+
+ it "can blit to the foreground - one by one" do
+ t = fake_target
+ @topo.blit_foreground(fake_pallette, t, 0, 0)
+ t.blitted.should == ["A"]
+ end
+ it "can blit to the foreground - wide" do
+ t = fake_target(200,1)
+ @topo.blit_foreground(fake_pallette, t, 0, 0)
+ t.blitted.should == ["A", "B"]
+ end
+ it "can blit to the foreground - tall" do
+ t = fake_target(1,200)
+ @topo.blit_foreground(fake_pallette, t, 0, 0)
+ t.blitted.should == ["A", "C"]
+ end
+ it "can blit to the foreground - large" do
+ t = fake_target(200,200)
+ @topo.blit_foreground(fake_pallette, t, 0, 0)
+ t.blitted.should == ["A", "B", "C", "D"]
+ end
+
+ it "test_can_update_on_the_fly" do
+ @topo.update(0,0,'X')
+ @topo.data_at(0,0).should == 'X'
+ end
+
+ it "test_can_calculate_boundaries_from_tile_coords" do
+ @topo.left_side(0).should == 0
+ @topo.left_side(1).should == 100
+ @topo.right_side(0).should == 100
+ @topo.right_side(1).should == 200
+ @topo.top_side(0).should == 0
+ @topo.top_side(1).should == 100
+ @topo.bottom_side(0).should == 100
+ @topo.bottom_side(1).should == 200
+
+
+ end
+
+end
+
View
@@ -1,41 +0,0 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'all_drugs'
-
-class AllDrugsTest < Test::Unit::TestCase
- def test_can_get_list_of_all_known_drugs
- assert_equal(AllDrugs.drugs.size, 15)
- end
-
- def test_can_get_all_rare_drugs
- drugs = AllDrugs.rare_drugs
- assert_equal(drugs.size, 2)
- drugs.each {|drug| assert_equal(:rare, drug.rarity)}
-
- end
-
- def test_can_get_all_common_drugs
- drugs = AllDrugs.common_drugs
- assert_equal(drugs.size, 13)
- drugs.each {|drug| assert_equal(:common, drug.rarity)}
-
- end
-
- def test_drug_for_symbol
- drug = AllDrugs.for_name(:acid)
-
- assert_equal("Acid", drug.name)
- end
-
- def test_can_obtain_n_drugs_given_k
- assert_equal(AllDrugs.with([:acid, :weed], 3).size, 3)
- assert_equal(AllDrugs.with([:acid, :weed], 2).size, 2)
- assert_equal(AllDrugs.with([:acid, :weed], 1).size, 2)
-
- end
-
-end
View
@@ -1,39 +0,0 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'city'
-require 'drug'
-
-class CityTest < Test::Unit::TestCase
- def test_city_has_name_and_price_factor
- @city = City.new("Halifax", 0.5)
- assert_equal("Halifax", @city.name)
- assert_equal(0.5, @city.price_factor)
- end
-
- def test_city_influences_prices
- @full_price = City.new("Full Price", 1)
- @half_price = City.new("Half Price", 0.5)
- @twice_price = City.new("Twice Price", 2)
-
- @one_dollar_drug = Drug.new("Dollar", 1)
- @one_hundred_dollar_drug = Drug.new("100 Dollars", 100)
-
- assert_equal(1, @full_price.price_for(@one_dollar_drug))
- assert_equal(100, @full_price.price_for(@one_hundred_dollar_drug))
- assert_equal(0.5, @half_price.price_for(@one_dollar_drug))
- assert_equal(50, @half_price.price_for(@one_hundred_dollar_drug))
- assert_equal(2, @twice_price.price_for(@one_dollar_drug))
- assert_equal(200, @twice_price.price_for(@one_hundred_dollar_drug))
-
- end
-
- def test_city_has_list_of_default_drugs
- @city = City.new("Place", 1, [:acid, :weed])
- assert_equal(2, @city.core_drugs.size)
- end
-
-end
View
@@ -1,25 +0,0 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'drug'
-
-class DrugTest < Test::Unit::TestCase
- def test_has_name_base_price_and_rarity
- @drug = Drug.new("Acid", 400)
-
- assert_equal("Acid", @drug.name)
- assert_equal(400, @drug.base_price)
- assert_equal(:common, @drug.rarity)
- end
-
- def test_rare_drugs_are_rare
- @drug = RareDrug.new("Fighter Pilot Shit", 3400)
-
- assert_equal(:rare, @drug.rarity)
- assert(@drug.rare?, "Failure message.")
- end
-
-end
View
@@ -1,32 +0,0 @@
-# To change this template, choose Tools | Templates
-# and open the template in the editor.
-
-$:.unshift File.join(File.dirname(__FILE__),'..','lib')
-
-require 'test/unit'
-require 'font_loader'
-
-class FontLoaderTest < Test::Unit::TestCase
- include FontLoader
-
- def test_knows_default_font_path
- assert font_path.end_with?("fonts")
- end
-
- def test_throws_an_exception_for_missing_fonts
- begin
- load_font("gibberish")
- flunk "should have blown up"
- rescue MissingResourceError => e
- assert_equal e.class, MissingResourceError
- end
- end
-
- def test_returns_ttf_object_for_valid_font
- load_font("FreeSans.ttf")
- end
-
- def test_can_be_used_as_module
-
- end
-end
Oops, something went wrong.

0 comments on commit e6f8300

Please sign in to comment.