alchemist 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ module Alchemist
2
+ VERSION = "0.1.5"
3
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__) + '../lib')
2
+
3
+ require 'test/unit'
4
+ require 'alchemist'
5
+
6
+ class AlchemistCompoundTest < Test::Unit::TestCase
7
+ def test_compound
8
+ assert_equal 30.miles, (10.miles.per.second * 3.seconds)
9
+ assert_equal 30.km, (10.km.p.h * 3.hours)
10
+ assert_equal 4, 4.m.per.m
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift(File.dirname(__FILE__) + '../lib')
2
+
3
+ require 'test/unit'
4
+ require 'alchemist'
5
+
6
+ class AlchemistMeasurementTest < Test::Unit::TestCase
7
+
8
+ def test_measurement
9
+ unit = Alchemist.measurement(1, :meter)
10
+ assert_equal(unit, 1.meter)
11
+ end
12
+
13
+ end
@@ -0,0 +1,98 @@
1
+ $:.unshift(File.dirname(__FILE__) + '../lib')
2
+
3
+ require 'test/unit'
4
+ require 'alchemist'
5
+
6
+ # TODO: Remove this
7
+ class Float
8
+ # truncates float to specified decimal places
9
+ def truncate(dec = 0)
10
+ return to_i if dec == 0
11
+ sprintf("%.#{dec}f", self).to_f
12
+ end
13
+ end
14
+
15
+ class AlchemistTest < Test::Unit::TestCase
16
+
17
+ def test_equivalence
18
+ assert_equal(1.m, 1.meter)
19
+ end
20
+
21
+ def test_bit_and_bytes
22
+ assert_equal( 65.bit.to_f, (1.bit + 8.bytes).to_f )
23
+ assert_equal( 0.125.bytes.to_f, 1.bit.to.bytes.to_f )
24
+ assert_in_delta(1.MB.to.kB.to_f, 1024.0, 1e-5)
25
+ assert_in_delta(1.MB.to.b.to_f, 8388608.0, 1e-5)
26
+ assert_in_delta(1.GB.to.B.to_f, 1073741824.0, 1e-5)
27
+ assert_in_delta(1.MiB.to(:KiB).to_f, 1024.0, 1e-5)
28
+ assert_in_delta(1.MiB.to.b.to_f, 8388608.0, 1e-5)
29
+ assert_in_delta(1.GiB.to.B.to_f, 1073741824.0, 1e-5)
30
+ Alchemist::use_si = true
31
+ assert_in_delta(1.GB.to.B.to_f, 1000000000.0, 1e-5)
32
+ assert_in_delta(1.MB.to.b.to_f, 8000000.0, 1e-5)
33
+ assert_in_delta(1.MB.to.kB.to_f, 1000.0, 1e-5)
34
+ end
35
+
36
+ def test_feet_to_miles
37
+ assert_equal( 5280.feet, 1.mile.to.feet )
38
+ end
39
+
40
+ def test_acre_to_yards_squared
41
+ assert_in_delta( 4840.square_yards.to_f, 1.acre.to.square_yards.to_f, 1e-5)
42
+ end
43
+
44
+ def test_gallon_to_liter
45
+ assert_in_delta( 3.785411784.L.to_f, 1.gallon.to.L.to_f, 1e-5 )
46
+ end
47
+
48
+ def test_lb_to_kg
49
+ assert_equal( 0.45359237.kg.to_f, 1.lb.to.kg.to_f )
50
+ end
51
+
52
+ def test_comparison
53
+ assert_equal( 5.grams, 0.005.kilograms )
54
+ end
55
+
56
+ def test_register
57
+ Alchemist.register(:distance, [:beard_second, :beard_seconds], 5.angstroms)
58
+ assert_equal( 1.beard_second, 5.angstroms)
59
+ Alchemist.register(:temperature, :yeti, [Proc.new{|t| t + 1}, Proc.new{|t| t - 1}])
60
+ assert_equal( 0.yeti, 1.kelvin)
61
+ end
62
+
63
+ def test_meters_times_meters
64
+ assert_equal(1.meter * 1.meter, 1.square_meter)
65
+ end
66
+
67
+ def test_meters_times_meters_times_meters
68
+ assert_equal(1.meter * 2.meter * 3.meter, 6.cubic_meters)
69
+ assert_equal(2.square_meters * 3.meters, 6.cubic_meters)
70
+ end
71
+
72
+ def test_division
73
+ assert_equal(2.meters / 1.meters, 2.0)
74
+ end
75
+
76
+ # Don't think these worked before
77
+ # def test_temperature
78
+ # assert_equal(1.fahrenheit, 1.fahrenheit)
79
+ # assert_in_delta(1.fahrenheit, 1.fahrenheit.to.fahrenheit, 1e-5)
80
+ # end
81
+
82
+ def test_density
83
+ assert_equal(25.brix.to_f, 1.1058.sg.to.brix.truncate(1))
84
+ assert_equal(25.plato, 25.125.brix)
85
+ end
86
+
87
+ def test_frequency
88
+ assert_equal(1.hertz, 60.rpm)
89
+ assert_equal(60.hz, 3600.rpm)
90
+ assert_equal(2400.rpm, 40.hz)
91
+ end
92
+
93
+ def test_conversion_to_datatypes
94
+ assert_equal(10.meters.to_i, 10)
95
+ assert_equal(10.meters.to_f, 10.0)
96
+ assert_equal(10.meters.to_s, "10.0")
97
+ end
98
+ end
metadata CHANGED
@@ -1,47 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matthew Mongeau
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000Z
13
- dependencies: []
11
+ date: 2013-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  description: Conversions... like you've never seen them before!!
15
- email: halogenandtoast@gmail.com
28
+ email:
29
+ - halogenandtoast@gmail.com
16
30
  executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
20
39
  - Rakefile
21
- - lib/alchemist/compound.rb
40
+ - alchemist.gemspec
22
41
  - lib/alchemist.rb
42
+ - lib/alchemist/binary_prefixes.rb
43
+ - lib/alchemist/compound.rb
44
+ - lib/alchemist/compound_numeric_conversion.rb
45
+ - lib/alchemist/numeric_conversion.rb
46
+ - lib/alchemist/numeric_ext.rb
47
+ - lib/alchemist/si_units.rb
48
+ - lib/alchemist/unit_prefixes.rb
49
+ - lib/alchemist/units.rb
50
+ - lib/alchemist/units.yml
51
+ - lib/alchemist/version.rb
52
+ - test/alchemist_compound_test.rb
53
+ - test/alchemist_measurement_test.rb
54
+ - test/alchemist_test.rb
23
55
  homepage: http://github.com/halogenandtoast/alchemist
24
56
  licenses: []
57
+ metadata: {}
25
58
  post_install_message:
26
59
  rdoc_options: []
27
60
  require_paths:
28
61
  - lib
29
62
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
63
  requirements:
32
- - - ! '>='
64
+ - - '>='
33
65
  - !ruby/object:Gem::Version
34
66
  version: '0'
35
67
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
68
  requirements:
38
- - - ! '>='
69
+ - - '>='
39
70
  - !ruby/object:Gem::Version
40
71
  version: '0'
41
72
  requirements: []
42
73
  rubyforge_project:
43
- rubygems_version: 1.8.16
74
+ rubygems_version: 2.0.2
44
75
  signing_key:
45
- specification_version: 3
76
+ specification_version: 4
46
77
  summary: Conversions... like you've never seen them before!
47
- test_files: []
78
+ test_files:
79
+ - test/alchemist_compound_test.rb
80
+ - test/alchemist_measurement_test.rb
81
+ - test/alchemist_test.rb