Skip to content

Commit

Permalink
Merge branch 'remove_tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
olbrich committed Feb 25, 2012
2 parents e7543f2 + 91704fe commit b14ca88
Show file tree
Hide file tree
Showing 12 changed files with 484 additions and 1,471 deletions.
56 changes: 14 additions & 42 deletions RakeFile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,16 +41,6 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end end


begin
require 'rcov/rcovtask'
desc "Generate code coverage"
Rcov::RcovTask.new do |t|
t.test_files = FileList['test/test*.rb']
#t.verbose = true # uncomment to see the executed command
end
rescue LoadError
end

begin begin
require 'simplecov' require 'simplecov'
desc "code coverage report using simplecov (ruby 1.9+)" desc "code coverage report using simplecov (ruby 1.9+)"
Expand Down Expand Up @@ -79,41 +69,23 @@ begin
rescue LoadError rescue LoadError
end end



desc "Run unit tests"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
end

task :specs => :spec task :specs => :spec


desc "Run tests against several ruby versions, requires rvm" rubies = {
task :multitest do "ruby-1.8.7" => %w{ruby-1.8.7-p357@ruby-units ruby-1.8.7-p357@ruby-units-with-chronic},
rubies = %w{ "ruby-1.9.2" => %w{ruby-1.9.2-p290@ruby-units ruby-1.9.2-p290@ruby-units-with-chronic},
ruby-1.8.7-p352@ruby-units "rbx" => %w{rbx-head@ruby-units},
ruby-1.8.7-p352@ruby-units-with-chronic "jruby" => %w{jruby-1.6.5.1@ruby-units}
ruby-1.9.2-p290@ruby-units }
ruby-1.9.2-p290@ruby-units-with-chronic
rbx-head@ruby-units rubies.each do |name, ruby|
jruby-1.6.5@ruby-units desc "Run Spec against #{name}"
} task "spec:#{name}" do
exec "rvm #{rubies.join(',')} do rake tests" sh "rvm #{ruby.join(',')} do rake spec"
end
end end


desc "Run specs against several ruby versions, requires rvm" desc "Run specs against several ruby versions, requires rvm"
task :multispec do task "spec:all" => rubies.keys.map {|name| "spec:#{name}"}
rubies = %w{
ruby-1.8.7-p352@ruby-units
ruby-1.8.7-p352@ruby-units-with-chronic
ruby-1.9.2-p290@ruby-units
ruby-1.9.2-p290@ruby-units-with-chronic
rbx-head@ruby-units
jruby-1.6.5@ruby-units
}
exec "rvm #{rubies.join(',')} do rake spec"
end

task :default => :test


task :tests => :test task :default => :spec
166 changes: 0 additions & 166 deletions lib/ruby_units/string/extra.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/ruby_units/unit.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -427,10 +427,6 @@ def to_unit
# @return [Boolean] # @return [Boolean]
def is_base? def is_base?
return @is_base if defined? @is_base return @is_base if defined? @is_base
# return @is_base = true if self.degree? &&
# self.numerator.size == 1 &&
# self.denominator == UNITY_ARRAY &&
# self.units =~ /(?:deg|temp)K/
@is_base = (@numerator + @denominator).compact.uniq. @is_base = (@numerator + @denominator).compact.uniq.
map {|unit| Unit.definition(unit)}. map {|unit| Unit.definition(unit)}.
all? {|element| element.unity? || element.base? } all? {|element| element.unity? || element.base? }
Expand Down
31 changes: 31 additions & 0 deletions spec/ruby-units/cache_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Unit::Cache do
subject { Unit::Cache }
let(:unit) { Unit('1 m') }

before(:each) do
subject.clear
subject.set("m", unit)
end

context ".clear" do
it "should clear the cache" do
subject.clear
subject.get('m').should be_nil
end
end

context ".get" do
it "should retrieve values already in the cache" do
subject.get['m'].should == unit
end
end

context ".set" do
it "should put a unit into the cache" do
subject.set('kg', Unit('1 kg'))
subject.get['kg'].should == Unit('1 kg')
end
end
end
4 changes: 2 additions & 2 deletions spec/ruby-units/definition_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
its(:name) {should == "<eV>"} its(:name) {should == "<eV>"}
its(:aliases) {should == %w{eV electron-volt}} its(:aliases) {should == %w{eV electron-volt}}
its(:scalar) {should == 1.602E-19} its(:scalar) {should == 1.602E-19}
its(:numerator) {should == %w{<kilogram> <meter> <meter>}} its(:numerator) {should include("<kilogram>", "<meter>", "<meter>")}
its(:denominator) {should == %w{<second> <second>}} its(:denominator) {should include("<second>", "<second>")}
its(:display_name) {should == "electron-volt"} its(:display_name) {should == "electron-volt"}
end end
46 changes: 22 additions & 24 deletions spec/ruby-units/math_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,24 +1,25 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'


describe Math do describe Math do
context "with '1 mm^6'" do
subject { '1 mm^6'.to_unit } describe "#sqrt" do

specify { Math.sqrt(Unit('1 mm^6')).should == Unit('1 mm^3') }
specify { Math.sqrt(subject).should == '1 mm^3'.to_unit }
specify { Math.sqrt(4).should == 2 } specify { Math.sqrt(4).should == 2 }

specify { Math.sqrt(Unit("-9 mm^2")).should be_kind_of(Complex) }
if RUBY_VERSION > "1.9" end
# cbrt is only defined in Ruby > 1.9
specify { Math.cbrt(subject).should == '1 mm^2'.to_unit } if RUBY_VERSION > "1.9"
# cbrt is only defined in Ruby > 1.9
describe '#cbrt' do
specify { Math.cbrt(Unit('1 mm^6')).should == Unit('1 mm^2') }
specify { Math.cbrt(8).should == 2 } specify { Math.cbrt(8).should == 2 }
end end

end end

context "Trigonometry functions" do context "Trigonometry functions" do

context "with '45 deg' unit" do context "with '45 deg' unit" do
subject { "45 deg".unit } subject { Unit("45 deg") }
specify { Math.sin(subject).should be_within(0.01).of(0.70710678) } specify { Math.sin(subject).should be_within(0.01).of(0.70710678) }
specify { Math.cos(subject).should be_within(0.01).of(0.70710678) } specify { Math.cos(subject).should be_within(0.01).of(0.70710678) }
specify { Math.tan(subject).should be_within(0.01).of(1) } specify { Math.tan(subject).should be_within(0.01).of(1) }
Expand All @@ -28,7 +29,7 @@
end end


context "with 'PI/4 radians' unit" do context "with 'PI/4 radians' unit" do
subject { (Math::PI/4).unit('radians') } subject { Unit((Math::PI/4),'radians') }
specify { Math.sin(subject).should be_within(0.01).of(0.70710678) } specify { Math.sin(subject).should be_within(0.01).of(0.70710678) }
specify { Math.cos(subject).should be_within(0.01).of(0.70710678) } specify { Math.cos(subject).should be_within(0.01).of(0.70710678) }
specify { Math.tan(subject).should be_within(0.01).of(1) } specify { Math.tan(subject).should be_within(0.01).of(1) }
Expand All @@ -47,17 +48,14 @@
specify { Math.tanh(subject).should be_within(0.01).of(0.6557942026326724) } specify { Math.tanh(subject).should be_within(0.01).of(0.6557942026326724) }
end end


specify { Math.hypot("1 m".unit, "2 m".unit).should be_within("0.01 m".unit).of("2.23607 m".unit) } specify { Math.hypot(Unit("1 m"), Unit("2 m")).should be_within(Unit("0.01 m")).of(Unit("2.23607 m")) }
specify { Math.hypot("1 m".unit, "2 ft".unit).should be_within("0.01 m".unit).of("1.17116 m".unit) } specify { Math.hypot(Unit("1 m"), Unit("2 ft")).should be_within(Unit("0.01 m")).of(Unit("1.17116 m")) }
specify { expect {Math.hypot("1 m".unit, "2 lbs".unit) }.to raise_error(ArgumentError) } specify { Math.hypot(3,4).should == 5}

specify { expect {Math.hypot(Unit("1 m"), Unit("2 lbs")) }.to raise_error(ArgumentError) }
specify { Math.atan2("1 m".unit, "2 m".unit).should be_within(0.01).of(0.4636476090008061) }
specify { Math.atan2("1 m".unit, "2 ft".unit).should be_within(0.01).of(1.0233478888629426) } specify { Math.atan2(Unit("1 m"), Unit("2 m")).should be_within(0.01).of(0.4636476090008061) }
specify { Math.atan2(Unit("1 m"), Unit("2 ft")).should be_within(0.01).of(1.0233478888629426) }
specify { Math.atan2(1,1).should be_within(0.01).of(0.785398163397448)} specify { Math.atan2(1,1).should be_within(0.01).of(0.785398163397448)}
specify { expect {Math.atan2("1 m".unit, "2 lbs".unit)}.to raise_error(ArgumentError) } specify { expect {Math.atan2(Unit("1 m"), Unit("2 lbs"))}.to raise_error(ArgumentError) }

end end



end end
16 changes: 16 additions & 0 deletions spec/ruby-units/range_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe "Range" do

context "of integer units" do
subject { (Unit('1 mm')..Unit('3 mm')) }
it { should include(Unit('2 mm')) }
its(:to_a) { should == [ Unit('1 mm'), Unit('2 mm'), Unit('3 mm') ] }
end

context "of floating point units" do
subject { (Unit('1.5 mm')..Unit('3.5 mm')) }
it { should include(Unit('2.0 mm')) }
specify { expect { subject.to_a }.to raise_exception(ArgumentError)}
end
end
Loading

0 comments on commit b14ca88

Please sign in to comment.