Permalink
Browse files

remote old tests and replace with specs

  • Loading branch information...
1 parent c4e1680 commit aed66e86d3465dac7eb054c0112ec773b71d7768 @olbrich committed Feb 24, 2012
Showing with 10 additions and 87 deletions.
  1. +9 −1 spec/ruby-units/unit_spec.rb
  2. +1 −86 test/test_ruby-units.rb
@@ -365,8 +365,9 @@
end
# time string
- describe Unit("1:23:45") do
+ describe Unit("1:23:45,200") do
it {should be_an_instance_of Unit}
+ it {should == Unit("1 h") + Unit("23 min") + Unit("45 seconds") + Unit("200 usec")}
its(:scalar) {should be_an Rational}
its(:units) {should == "h"}
its(:kind) {should == :time}
@@ -495,11 +496,18 @@
its(:kind) {should == :unitless}
end
+ # create with another unit
describe 10.unit(Unit("1 mm")) do
its(:units) {should == "mm"}
its(:scalar) {should == 10}
end
+ #explicit create
+ describe Unit("1 <meter>/<second>") do
+ its(:kind) {should == :speed}
+ its(:units) {should == "m/s"}
+ end
+
end
describe "Unit handles attempts to create bad units" do
View
@@ -113,28 +113,6 @@ def test_temperature_conversions
assert_raises(ArgumentError) { c - '400 degK'.unit}
assert_equal a, a.convert_to('tempF')
end
-
- def test_to_s
- unit1 = Unit.new("1")
- assert_equal "1", unit1.to_s
- unit2 = Unit.new("mm")
- assert_equal "1 mm", unit2.to_s
- assert_equal "0.04 in", unit2.to_s("%0.2f in")
- assert_equal "1/10 cm", unit2.to_s("cm")
- unit3 = Unit.new("1 mm")
- assert_equal "1 mm", unit3.to_s
- assert_equal "0.04 in", unit3.to_s("%0.2f in")
- unit4 = Unit.new("1 mm^2")
- assert_equal "1 mm^2", unit4.to_s
- unit5 = Unit.new("1 mm^2 s^-2")
- assert_equal "1 mm^2/s^2", unit5.to_s
- unit6= Unit.new("1 kg*m/s")
- assert_equal "1 kg*m/s", unit6.to_s
- unit7= Unit.new("1 1/m")
- assert_equal "1 1/m", unit7.to_s
- assert_equal("1.5 mm", Unit.new("1.5 mm").to_s)
- assert_equal("1.5 mm", "#{Unit.new('1.5 mm')}")
- end
def test_ideal_gas_law
p = Unit "100 kPa"
@@ -144,77 +122,14 @@ def test_ideal_gas_law
t = ((p*v)/(n*r)).convert_to('tempK')
assert_in_delta 12027.16,t.base_scalar, 0.1
end
-
- def test_eliminate_terms
- a = ['<meter>','<meter>','<kelvin>','<second>']
- b = ['<meter>','<meter>','<second>']
- h = Unit.eliminate_terms(1,a,b)
- assert_equal ['<kelvin>'], h[:numerator]
- end
-
- def test_to_base_consistency
- a = "1 W*m/J*s".unit
- assert_equal a.signature, a.to_base.signature
- end
-
- def test_unit_roots
- unit1 = Unit "2 m*J*kg"
- unit2 = Unit "4 m^2*J^2*kg^2"
- unit3 = Unit "8 m^3*J^3*kg^3"
- assert_equal unit2**(1/2), unit1
- assert_equal unit3**(1/3), unit1
- end
def test_time_conversions
today = Time.now
assert_equal today,@april_fools
last_century = today - '150 years'.unit
assert_equal last_century.to_date, DateTime.parse('1856-04-01')
end
-
- def test_parse_durations
- assert_equal "1:00".unit, '1 hour'.unit
- assert_equal "1:30".unit, "1.5 hour".unit
- assert_equal "1:30:30".unit, "1.5 hour".unit + '30 sec'.unit
- assert_equal "1:30:30,200".unit, "1.5 hour".unit + '30 sec'.unit + '200 usec'.unit
- end
-
- def test_to_date
- a = Time.now
- assert_equal a.send(:to_date), Date.today
- end
-
- def test_explicit_init
- assert_equal '1 lbf'.unit, '1 <pound-force>'.unit
- assert_equal '1 lbs'.unit, '1 <pound>'.unit
- assert_equal('1 kg*m'.unit, '1 <kilogram>*<meter>'.unit)
- end
-
- def test_to_s_cache
- Unit.clear_cache
- a = Unit.new('1 mm')
- a.to_s # cache the conversion to itself
- b = Unit.new('2 mm')
- assert_equal('2 mm', b.to_s)
- assert_equal('1/1000 m', a.to_s('m'))
- assert_equal('1/1000 m', a.output['m'])
- end
-
- def test_parse_into_numbers_and_units
- assert_equal([1,"m"], Unit.parse_into_numbers_and_units("1 m"))
- assert_equal([1.0,"m"], Unit.parse_into_numbers_and_units("1.0 m"))
- assert_equal([0.1,"m"], Unit.parse_into_numbers_and_units("0.1 m"))
- assert_equal([0.1,"m"], Unit.parse_into_numbers_and_units(".1 m"))
- assert_equal([-1.23E-3,"m"], Unit.parse_into_numbers_and_units("-1.23E-3 m"))
- assert_equal([1/4,"m"], Unit.parse_into_numbers_and_units("1/4 m"))
- assert_equal([-1/4,"m"], Unit.parse_into_numbers_and_units("-1/4 m"))
- assert_equal([1,"m"], Unit.parse_into_numbers_and_units("1 m"))
- assert_equal([1,"m"], Unit.parse_into_numbers_and_units("m"))
- assert_equal([10,""], Unit.parse_into_numbers_and_units("10"))
- assert_equal([10.0,""], Unit.parse_into_numbers_and_units("10.0"))
- assert_equal([(1/4),""], Unit.parse_into_numbers_and_units("1/4"))
- assert_equal([Complex(1,1),""], Unit.parse_into_numbers_and_units("1+1i"))
- end
+
end

0 comments on commit aed66e8

Please sign in to comment.