Skip to content

Commit

Permalink
Merge branch 'refs/heads/issue_40'
Browse files Browse the repository at this point in the history
  • Loading branch information
olbrich committed May 13, 2012
2 parents 7e27a1e + 6dee6df commit 68eb642
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/ruby_units/unit.rb
Expand Up @@ -314,6 +314,7 @@ def initialize(*options)
@unit_name = nil @unit_name = nil
@signature = nil @signature = nil
@output = {} @output = {}
raise ArgumentError, "Invalid Unit Format" if options[0].nil?
if options.size == 2 if options.size == 2
# options[0] is the scalar # options[0] is the scalar
# options[1] is a unit string # options[1] is a unit string
Expand Down
11 changes: 8 additions & 3 deletions spec/ruby-units/unit_spec.rb
Expand Up @@ -427,7 +427,7 @@
its(:temperature_scale) {should be_nil} its(:temperature_scale) {should be_nil}
end end


describe Unit.new("1 m^2 s^-2") do describe Unit("1 m^2 s^-2") do
it {should be_an_instance_of Unit} it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer} its(:scalar) {should be_an Integer}
its(:units) {should == "m^2/s^2"} its(:units) {should == "m^2/s^2"}
Expand All @@ -441,7 +441,7 @@
its(:temperature_scale) {should be_nil} its(:temperature_scale) {should be_nil}
end end


describe Unit.new(1,"m^2","s^2") do describe Unit(1,"m^2","s^2") do
it {should be_an_instance_of Unit} it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer} its(:scalar) {should be_an Integer}
its(:units) {should == "m^2/s^2"} its(:units) {should == "m^2/s^2"}
Expand All @@ -456,7 +456,7 @@
end end


#scientific notation #scientific notation
describe Unit.new("1e6 cells") do describe Unit("1e6 cells") do
it {should be_an_instance_of Unit} it {should be_an_instance_of Unit}
its(:scalar) {should be_an Integer} its(:scalar) {should be_an Integer}
its(:scalar) {should == 1e6 } its(:scalar) {should == 1e6 }
Expand Down Expand Up @@ -568,6 +568,11 @@
expect {Unit("-100 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero") expect {Unit("-100 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero")
expect {Unit("-500/9 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero") expect {Unit("-500/9 tempR")}.to raise_error(ArgumentError,"Temperatures must not be less than absolute zero")
end end

specify "no nil scalar" do
expect {Unit(nil, "feet")}.to raise_error(ArgumentError, "Invalid Unit Format")
expect {Unit(nil, "feet", "min")}.to raise_error(ArgumentError, "Invalid Unit Format")
end


end end


Expand Down

0 comments on commit 68eb642

Please sign in to comment.