Sha256: 9b0536312d81e4fb3df9fdfd933122f708baa967f2a345b3686207aabd5afd78

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

$LOAD_PATH << "./lib"
require 'phys/units'

$debug=false

def close_values(a,b)
  (a-b).abs < (a.abs+b.abs)*3e-8
end

puts <<EOL
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift File.dirname(__FILE__)
require "helper"

describe "Unit Conversion" do
EOL

keys = Phys::Unit::LIST.keys
keys.each do |k,u|
  puts k  if $debug
  u = Phys::Unit::LIST[k]
  f = u.conversion_factor
  s = u.base_unit.string_form
  #s = '1' if s==''
  puts "#{k}, #{u.name}, #{u.string_form}, #{u.factor} base: #{f}, #{s}" if $debug
  n = u.name
  if /'/ =~ n
    c = "units "#{n}" '#{s}'"
    puts c if $debug
    next
  else
    c = "units '#{n}' '#{s}'"
  end
  puts c if $debug
  x = `#{c}`
  puts x if $debug

  if /\* ([\d.e+-]+)\s+\/ ([\d.e+-]+)/m =~ x
    factor = $1
    s2 = (s=='') ? "" : ",#{s.inspect}"
    puts <<EOL
  describe Q[1,#{n.inspect}] do
    it {should be_a_quantity_close_to Q[#{factor}#{s2}] }
  end
EOL
    factor = factor.to_f
    puts "factor = #{factor} <=> f=#{f} => #{factor.to_f<=>f}" if $debug
    if !close_values(factor, f)
      puts "#{k}, #{u.name}, #{u.string_form}, #{u.factor} base: #{f}, #{s}"
      puts c
      puts x
      puts "factor = #{factor} <=> f=#{f} => #{factor<=>f}"
      puts "diff = #{(factor-f).abs/(factor.abs+f.abs)}"
      puts "--"
    end
  end
end

puts <<EOL
end
EOL

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
phys-units-0.9.9 misc/mkunitspec.rb
phys-units-0.9.8 misc/mkunitspec.rb
phys-units-0.9.7 misc/mkunitspec.rb
phys-units-0.9.6 misc/mkunitspec.rb
phys-units-0.9.5 misc/mkunitspec.rb