eymiha_units 0.1.0
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.
- data/gem_package.rb +34 -0
- data/lib/units/definitions/area.rb +5 -0
- data/lib/units/definitions/length.rb +34 -0
- data/lib/units/definitions/mass.rb +16 -0
- data/lib/units/definitions/measures.rb +6 -0
- data/lib/units/definitions/time.rb +61 -0
- data/lib/units/definitions/velocity.rb +9 -0
- data/lib/units/definitions/volume.rb +27 -0
- data/lib/units/numeric.rb +88 -0
- data/lib/units/numeric_with_units.rb +635 -0
- data/lib/units/object.rb +79 -0
- data/lib/units/units.rb +229 -0
- data/lib/units/units_exception.rb +14 -0
- data/lib/units/units_hash.rb +112 -0
- data/lib/units/units_measure.rb +91 -0
- data/lib/units/units_system.rb +85 -0
- data/lib/units/units_unit.rb +60 -0
- data/lib/units.rb +4 -0
- data/rakefile.rb +2 -0
- data/test/framework.rb +7 -0
- data/test/tc_definitions.rb +49 -0
- data/test/tc_formatting.rb +41 -0
- data/test/tc_formatting_derived.rb +73 -0
- data/test/tc_measure_create.rb +59 -0
- data/test/tc_measure_derive.rb +46 -0
- data/test/tc_system_create.rb +31 -0
- data/test/tc_unit_ambiguity.rb +46 -0
- data/test/tc_unit_arithmetic.rb +41 -0
- data/test/tc_unit_create.rb +35 -0
- data/test/tc_unit_derive.rb +87 -0
- data/test/tc_unit_equality.rb +54 -0
- data/test/tc_unit_forward_reference.rb +44 -0
- data/test/tc_unit_greek.rb +163 -0
- data/test/tc_unit_hash.rb +66 -0
- data/test/tc_unit_identifiers.rb +48 -0
- data/test/tc_unit_rank.rb +53 -0
- data/test/tc_uses_1.rb +212 -0
- data/test/tc_uses_2.rb +149 -0
- metadata +118 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/framework'
|
3
|
+
|
4
|
+
require 'units'
|
5
|
+
|
6
|
+
class TC_unit_hash < Test::Unit::TestCase
|
7
|
+
|
8
|
+
understands UnitsTest
|
9
|
+
|
10
|
+
def test_unit_hash
|
11
|
+
|
12
|
+
Units.create :length do |m|
|
13
|
+
m.system :english do |s|
|
14
|
+
s.unit :name => :inch,
|
15
|
+
:plural => :inches,
|
16
|
+
:abbrev => :in
|
17
|
+
end
|
18
|
+
end
|
19
|
+
Units.create :mass do |m|
|
20
|
+
m.system :english do |s|
|
21
|
+
s.unit :name => :pound,
|
22
|
+
:abbrev => :lb
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Units.create :time do |m|
|
26
|
+
m.system :english do |s|
|
27
|
+
s.unit :name => :second,
|
28
|
+
:abbrev => :s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
nwu1 = 2.inches
|
33
|
+
u1 = (Units.lookup :inch)[0]
|
34
|
+
nwu2 = 3.pounds
|
35
|
+
u2 = (Units.lookup :pound)[0]
|
36
|
+
nwu3 = 5.seconds
|
37
|
+
u3 = (Units.lookup :second)[0]
|
38
|
+
|
39
|
+
assert(nwu1.unit == nwu1.unit.clone)
|
40
|
+
nwu1.unit.merge! nwu2
|
41
|
+
assert(nwu1.unit.size == 2)
|
42
|
+
assert(nwu1.unit[u1] == 1)
|
43
|
+
assert(nwu1.unit[u2] == 1)
|
44
|
+
nwu1.unit.merge! nwu3,-2
|
45
|
+
assert(nwu1.unit.size == 3)
|
46
|
+
assert(nwu1.unit[u1] == 1)
|
47
|
+
assert(nwu1.unit[u2] == 1)
|
48
|
+
assert(nwu1.unit[u3] == -2)
|
49
|
+
nwu1.unit.merge! nwu2,-1
|
50
|
+
assert(nwu1.unit.size == 2)
|
51
|
+
assert(nwu1.unit[u1] == 1)
|
52
|
+
assert(nwu1.unit[u3] == -2)
|
53
|
+
|
54
|
+
unit1 = nwu1.unit**2
|
55
|
+
assert(unit1.size == 2)
|
56
|
+
assert(unit1[u1] == 2)
|
57
|
+
assert(unit1[u3] == -4)
|
58
|
+
|
59
|
+
unit2 = UnitsHash.new(unit1,2)
|
60
|
+
assert(unit2.size == 2)
|
61
|
+
assert(unit2[u1] == 4)
|
62
|
+
assert(unit2[u3] == -8)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/framework'
|
3
|
+
|
4
|
+
require 'units'
|
5
|
+
|
6
|
+
class TC_unit_identifiers < Test::Unit::TestCase
|
7
|
+
|
8
|
+
understands UnitsTest
|
9
|
+
|
10
|
+
def test_unit_identifiers
|
11
|
+
|
12
|
+
Units.create :length do |m|
|
13
|
+
m.system :english do |s|
|
14
|
+
s.unit :name => :inch,
|
15
|
+
:plural => :inches,
|
16
|
+
:abbrev => :in
|
17
|
+
s.unit :name => :foot,
|
18
|
+
:plural => :feet,
|
19
|
+
:abbrev => [ :ft ]
|
20
|
+
s.unit :name => :yard,
|
21
|
+
:abbrevs => :yd
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
assert(Units.length.english.inch.kind_of?(UnitsUnit))
|
26
|
+
assert(Units.length.english.inch.plural == 'inches')
|
27
|
+
assert(Units.length.english.inch.abbrevs == [ 'in' ])
|
28
|
+
assert(Units.length.english.foot.kind_of?(UnitsUnit))
|
29
|
+
assert(Units.length.english.foot.plural == 'feet')
|
30
|
+
assert(Units.length.english.foot.abbrevs == [ 'ft' ])
|
31
|
+
assert(Units.length.english.yard.kind_of?(UnitsUnit))
|
32
|
+
assert(Units.length.english.yard.plural == 'yards')
|
33
|
+
assert(Units.length.english.yard.abbrevs == [ 'yd' ])
|
34
|
+
|
35
|
+
assert_raise(UnitsException) { Units.length.english.unit({}) }
|
36
|
+
assert(Units.lookup('inch')[0] == Units.length.english.inch)
|
37
|
+
assert(Units.lookup('inches')[0] == Units.length.english.inch)
|
38
|
+
assert(Units.lookup('in')[0] == Units.length.english.inch)
|
39
|
+
assert(Units.lookup('foot')[0] == Units.length.english.foot)
|
40
|
+
assert(Units.lookup('feet')[0] == Units.length.english.foot)
|
41
|
+
assert(Units.lookup('ft')[0] == Units.length.english.foot)
|
42
|
+
assert(Units.lookup('yard')[0] == Units.length.english.yard)
|
43
|
+
assert(Units.lookup('yards')[0] == Units.length.english.yard)
|
44
|
+
assert(Units.lookup('yd')[0] == Units.length.english.yard)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/framework'
|
3
|
+
|
4
|
+
require 'units'
|
5
|
+
|
6
|
+
class TC_unit_rank < Test::Unit::TestCase
|
7
|
+
|
8
|
+
understands UnitsTest
|
9
|
+
|
10
|
+
def load_units
|
11
|
+
|
12
|
+
Units.create :length do |m|
|
13
|
+
m.system :english do |s|
|
14
|
+
s.unit :name => :inch, :plural => :inches, :abbrev => :in
|
15
|
+
s.unit :name => :foot, :plural => :feet, :abbrev => :ft,
|
16
|
+
:equals => 12.inches
|
17
|
+
s.unit :name => :yard, :abbrevs => :yd, :equals => 3.feet
|
18
|
+
s.unit :name => :mile, :abbrevs => :mi, :equals => 1760.yards
|
19
|
+
end
|
20
|
+
m.system :metric do |s|
|
21
|
+
s.unit :name => :meter, :abbrev => :m, :equals => 39.370079.in,
|
22
|
+
:greek => :ten
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Units.create :time do |m|
|
27
|
+
m.system :base do |s|
|
28
|
+
s.unit :name => :second, :abbrev => :sec
|
29
|
+
s.unit :name => :minute, :abbrev => :min, :equals => 60.seconds
|
30
|
+
s.unit :name => :hour, :abbrev => :hr, :equals => 60.minutes
|
31
|
+
s.unit :name => :day, :abbrev => :dy, :equals => 24.hours
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_unit_rank
|
39
|
+
|
40
|
+
load_units
|
41
|
+
|
42
|
+
unit_choices = {1.meter/min => 2, 1.mile/hour => 1, 1.km/hr => 1}
|
43
|
+
samples = [7.35.in/sec, 1.18.in/sec, 0.92.in/sec]
|
44
|
+
|
45
|
+
ranks = Units.rank(unit_choices,samples)
|
46
|
+
|
47
|
+
assert(ranks[0] == 1.m/min)
|
48
|
+
assert(ranks[1] == 1.km/hr)
|
49
|
+
assert(ranks[2] == 1.mi/hr)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/test/tc_uses_1.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/framework'
|
3
|
+
|
4
|
+
require 'units'
|
5
|
+
|
6
|
+
class TC_unes < Test::Unit::TestCase
|
7
|
+
|
8
|
+
understands UnitsTest
|
9
|
+
|
10
|
+
def load_units
|
11
|
+
|
12
|
+
Units.create :length do |m|
|
13
|
+
m.system :english do |s|
|
14
|
+
s.unit :name => :inch,
|
15
|
+
:plural => :inches,
|
16
|
+
:abbrev => :in
|
17
|
+
s.unit :name => :foot,
|
18
|
+
:plural => :feet,
|
19
|
+
:abbrev => :ft,
|
20
|
+
:equals => 12.inches
|
21
|
+
s.unit :name => :yard,
|
22
|
+
:abbrevs => :yd,
|
23
|
+
:equals => 3.feet
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_use_1_identities
|
30
|
+
|
31
|
+
load_units
|
32
|
+
|
33
|
+
assert(72.inches.to_s == '72 inches')
|
34
|
+
assert(6.feet.to_s == '6 feet')
|
35
|
+
assert(2.yards.to_s == '2 yards')
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_use_1_test_use_1_multiplication
|
41
|
+
|
42
|
+
load_units
|
43
|
+
|
44
|
+
assert((72.inches/10).to_s == '7 inches')
|
45
|
+
assert((6.feet*5).to_s == '30 feet')
|
46
|
+
assert((2.yards**2).to_s == '4 yd^2')
|
47
|
+
assert((72.0.inches/10).to_s == '7.2 inches')
|
48
|
+
|
49
|
+
assert((12.inches*12.inches).to_s == '144.0 in^2')
|
50
|
+
assert((12.inches*1.foot).to_s == '1.0 ft^2')
|
51
|
+
assert((1.foot*12.inches).to_s == '144.0 in^2')
|
52
|
+
assert((1.foot*1.foot).to_s == '1.0 ft^2')
|
53
|
+
|
54
|
+
assert(12.0.in == 1.0.ft)
|
55
|
+
assert(144.0.in**2 != 1.0.ft**2)
|
56
|
+
assert(NumericWithUnits.new(144.0,Units.length.english.inch,2).to_s ==
|
57
|
+
'144.0 in^2')
|
58
|
+
assert(144.0.in^2 == 1.0.ft^2)
|
59
|
+
|
60
|
+
assert(72.inches/2.feet == 3.0)
|
61
|
+
assert(6.feet/2.feet == 3.0)
|
62
|
+
assert(2.yards/2.feet == 3.0)
|
63
|
+
|
64
|
+
assert((144 * 1.in^2).to_s == '144 in^2')
|
65
|
+
assert((2.0 / 3.ft^3).to_s == '0.666666666666667 1/ft^3')
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def test_use_1_addition
|
71
|
+
|
72
|
+
load_units
|
73
|
+
|
74
|
+
assert(((2.0.ft^2) + (3.0.in^2)).to_s == '291.0 in^2')
|
75
|
+
assert(((1.0.yd^2) - (1.0.ft^2)).to_s == '8.0 ft^2')
|
76
|
+
|
77
|
+
assert((5.0.inches + 2).to_s == '7.0 inches')
|
78
|
+
assert((2 + 5.0.inches).to_s == '7.0 inches')
|
79
|
+
assert((5.0.inches - 2).to_s == '3.0 inches')
|
80
|
+
assert((2 - 5.0.inches).to_s == '-3.0 inches')
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def test_use_1_comparison
|
86
|
+
|
87
|
+
load_units
|
88
|
+
|
89
|
+
assert((13.inches <=> 1.foot) == 1)
|
90
|
+
assert((12.inches <=> 1.foot) == 0)
|
91
|
+
assert((11.inches <=> 1.foot) == -1)
|
92
|
+
assert((13.inches > 1.foot) == true)
|
93
|
+
assert((12.inches > 1.foot) == false)
|
94
|
+
assert((11.inches > 1.foot) == false)
|
95
|
+
assert((13.inches < 1.foot) == false)
|
96
|
+
assert((12.inches < 1.foot) == false)
|
97
|
+
assert((11.inches < 1.foot) == true)
|
98
|
+
assert((13.inches >= 1.foot) == true)
|
99
|
+
assert((12.inches >= 1.foot) == true)
|
100
|
+
assert((11.inches >= 1.foot) == false)
|
101
|
+
assert((13.inches <= 1.foot) == false)
|
102
|
+
assert((12.inches <= 1.foot) == true)
|
103
|
+
assert((11.inches <= 1.foot) == true)
|
104
|
+
assert((13.inches == 1.foot) == false)
|
105
|
+
assert((12.inches == 1.foot) == true)
|
106
|
+
assert((11.inches == 1.foot) == false)
|
107
|
+
|
108
|
+
assert((13.inches <=> 12) == 1)
|
109
|
+
assert((12.inches <=> 12) == 0)
|
110
|
+
assert((11.inches <=> 12) == -1)
|
111
|
+
assert((13.inches > 12) == true)
|
112
|
+
assert((12.inches > 12) == false)
|
113
|
+
assert((11.inches > 12) == false)
|
114
|
+
assert((13.inches < 12) == false)
|
115
|
+
assert((12.inches < 12) == false)
|
116
|
+
assert((11.inches < 12) == true)
|
117
|
+
assert((13.inches >= 12) == true)
|
118
|
+
assert((12.inches >= 12) == true)
|
119
|
+
assert((11.inches >= 12) == false)
|
120
|
+
assert((13.inches <= 12) == false)
|
121
|
+
assert((12.inches <= 12) == true)
|
122
|
+
assert((11.inches <= 12) == true)
|
123
|
+
assert((13.inches == 12) == false)
|
124
|
+
assert((12.inches == 12) == true)
|
125
|
+
assert((11.inches == 12) == false)
|
126
|
+
|
127
|
+
assert((13 <=> 12.inches) == 1)
|
128
|
+
assert((12 <=> 12.inches) == 0)
|
129
|
+
assert((11 <=> 12.inches) == -1)
|
130
|
+
assert((13 > 12.inches) == true)
|
131
|
+
assert((12 > 12.inches) == false)
|
132
|
+
assert((11 > 12.inches) == false)
|
133
|
+
assert((13 < 12.inches) == false)
|
134
|
+
assert((12 < 12.inches) == false)
|
135
|
+
assert((11 < 12.inches) == true)
|
136
|
+
assert((13 >= 12.inches) == true)
|
137
|
+
assert((12 >= 12.inches) == true)
|
138
|
+
assert((11 >= 12.inches) == false)
|
139
|
+
assert((13 <= 12.inches) == false)
|
140
|
+
assert((12 <= 12.inches) == true)
|
141
|
+
assert((11 <= 12.inches) == true)
|
142
|
+
assert((13 == 12.inches) == false)
|
143
|
+
assert((12 == 12.inches) == true)
|
144
|
+
assert((11 == 12.inches) == false)
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def test_use_1_modulo
|
150
|
+
|
151
|
+
load_units
|
152
|
+
|
153
|
+
assert((5.feet % 7.inches).to_s == '4.0 inches')
|
154
|
+
assert((27.inches % 2.feet).to_s == '0.25 feet')
|
155
|
+
assert((12.inches % 5).to_s == '2 inches')
|
156
|
+
assert((12 % 9.inches).to_s == '3 inches')
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def test_use_1_niceties
|
162
|
+
|
163
|
+
load_units
|
164
|
+
|
165
|
+
assert(10.4.inches.ceil.to_s == '11 inches')
|
166
|
+
assert(-10.4.inches.ceil.to_s == '-10 inches')
|
167
|
+
assert(10.4.inches.floor.to_s == '10 inches')
|
168
|
+
assert(-10.4.inches.floor.to_s == '-11 inches')
|
169
|
+
assert(10.4.inches.abs.to_s == '10.4 inches')
|
170
|
+
assert(-10.4.inches.abs.to_s == '10.4 inches')
|
171
|
+
assert(10.4.inches.round.to_s == '10 inches')
|
172
|
+
assert(-10.4.inches.round.to_s == '-10 inches')
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
def test_use_1_inheritence
|
178
|
+
|
179
|
+
load_units
|
180
|
+
|
181
|
+
assert(10.inches.kind_of?(Numeric) == true)
|
182
|
+
assert(10.inches.kind_of?(Fixnum) == true)
|
183
|
+
assert(10.0.inches.kind_of?(Float) == true)
|
184
|
+
assert(10.0.inches.kind_of?(String) == false)
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_use_1_promotion
|
189
|
+
|
190
|
+
load_units
|
191
|
+
|
192
|
+
inch = Units.length.english.inch
|
193
|
+
|
194
|
+
n = 10
|
195
|
+
assert((n.unite inch).to_s == '10 inches')
|
196
|
+
assert((n.unite "inch").to_s == '10 inches')
|
197
|
+
assert((n.unite :inch).to_s == '10 inches')
|
198
|
+
assert((n.unite 1.inch).to_s == '10 inches')
|
199
|
+
assert((n.unite 1.inch.unit).to_s == '10 inches')
|
200
|
+
assert((n.unite nil).to_s == '10')
|
201
|
+
|
202
|
+
n = 10.feet
|
203
|
+
assert((n.unite inch).to_s == '10 inches')
|
204
|
+
assert((n.unite "inch").to_s == '10 inches')
|
205
|
+
assert((n.unite :inch).to_s == '10 inches')
|
206
|
+
assert((n.unite 1.inch).to_s == '10 inches')
|
207
|
+
assert((n.unite 1.inch.unit).to_s == '10 inches')
|
208
|
+
assert((n.unite nil).to_s == '10')
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
data/test/tc_uses_2.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/framework'
|
3
|
+
|
4
|
+
require 'units'
|
5
|
+
|
6
|
+
class TC_uses_2 < Test::Unit::TestCase
|
7
|
+
|
8
|
+
understands UnitsTest
|
9
|
+
|
10
|
+
def load_units
|
11
|
+
|
12
|
+
Units.create :length do |m|
|
13
|
+
m.system :english do |s|
|
14
|
+
s.unit :name => :inch, :plural => :inches, :abbrev => :in
|
15
|
+
s.unit :name => :foot, :plural => :feet, :abbrev => :ft,
|
16
|
+
:equals => 12.inches
|
17
|
+
s.unit :name => :yard, :abbrevs => :yd, :equals => 3.feet
|
18
|
+
s.unit :name => :mile, :abbrevs => :mi, :equals => 1760.yards
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Units.create :time do |m|
|
23
|
+
m.system :base do |s|
|
24
|
+
s.unit :name => :second, :abbrev => :sec
|
25
|
+
s.unit :name => :minute, :abbrev => :min, :equals => 60.seconds
|
26
|
+
s.unit :name => :hour, :abbrev => :hr, :equals => 60.minutes
|
27
|
+
s.unit :name => :day, :abbrev => :dy, :equals => 24.hours
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_use_2_convert
|
35
|
+
|
36
|
+
load_units
|
37
|
+
|
38
|
+
foot = 1.foot
|
39
|
+
mile = 1.mile
|
40
|
+
|
41
|
+
d = 140.miles
|
42
|
+
assert(d.convert(mile).to_s == '140.0 miles')
|
43
|
+
assert(d.convert(foot).to_s == '739200.0 feet')
|
44
|
+
assert(d.convert(1.yard).to_s == '246400.0 yards')
|
45
|
+
|
46
|
+
second = 1.second
|
47
|
+
hour = 1.hour
|
48
|
+
|
49
|
+
t = 2.hours + 35.minutes
|
50
|
+
assert(t.convert(hour).to_s == '2.58333333333333 hours')
|
51
|
+
assert(t.convert(second).to_s == '9300.0 seconds')
|
52
|
+
|
53
|
+
r = d/t
|
54
|
+
assert(r.to_s == '0.903225806451613 mi / min')
|
55
|
+
assert(r.convert([mile, hour]).to_s == '54.1935483870968 mi / hr')
|
56
|
+
assert(r.convert([foot, second]).to_s == '79.4838709677419 ft / sec')
|
57
|
+
|
58
|
+
fps = [foot,second]
|
59
|
+
mph = [mile,hour]
|
60
|
+
|
61
|
+
assert(r.convert(fps).to_s == '79.4838709677419 ft / sec')
|
62
|
+
assert(r.convert(mph).to_s == '54.1935483870968 mi / hr')
|
63
|
+
|
64
|
+
assert((5.days * r).to_s == '6503.22580645161 miles')
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_use_2_to
|
69
|
+
|
70
|
+
load_units
|
71
|
+
|
72
|
+
r = 55.feet / 1.second
|
73
|
+
|
74
|
+
assert(r.to_s == '55 ft / sec')
|
75
|
+
r.to_miles_and_hours
|
76
|
+
assert(r.to_s == '37.5 mi / hr')
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_use_2_in
|
81
|
+
|
82
|
+
load_units
|
83
|
+
|
84
|
+
r1 = 55.feet / 1.second
|
85
|
+
|
86
|
+
assert(r1.to_s == '55 ft / sec')
|
87
|
+
r2 = r1.in_miles_and_hours
|
88
|
+
assert(r1.to_s == '55 ft / sec')
|
89
|
+
assert(r2.to_s == '37.5 mi / hr')
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_use_2_per
|
94
|
+
|
95
|
+
load_units
|
96
|
+
|
97
|
+
r1 = 55.ft/1.sec
|
98
|
+
|
99
|
+
assert(r1.miles_per_hour.to_s == '37.5 mi / hr')
|
100
|
+
assert(r1.minutes_per_mile.to_s == '1.6 min / mi')
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_use_2_in_implicit
|
105
|
+
|
106
|
+
load_units
|
107
|
+
|
108
|
+
r1 = 55.feet / 1.second
|
109
|
+
|
110
|
+
assert(r1.to_s == '55 ft / sec')
|
111
|
+
r2 = r1.miles_and_hours
|
112
|
+
assert(r1.to_s == '55 ft / sec')
|
113
|
+
assert(r2.to_s == '37.5 mi / hr')
|
114
|
+
assert(102.inches.feet.to_s == '8.5 feet')
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_use_2_object_unite
|
119
|
+
|
120
|
+
load_units
|
121
|
+
|
122
|
+
r1 = 55.ft/sec
|
123
|
+
|
124
|
+
assert(r1.miles_per_hour.to_s == '37.5 mi / hr')
|
125
|
+
assert(r1.minutes_per_mile.to_s == '1.6 min / mi')
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_use_2_numeric_unite_per
|
130
|
+
|
131
|
+
load_units
|
132
|
+
|
133
|
+
r1 = 55.feet_per_second
|
134
|
+
|
135
|
+
assert(r1.miles_per_hour.to_s == '37.5 mi / hr')
|
136
|
+
assert(r1.minutes_per_mile.to_s == '1.6 min / mi')
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_use_2_object_per
|
141
|
+
|
142
|
+
load_units
|
143
|
+
|
144
|
+
r1 = feet_per_mile
|
145
|
+
assert(r1.to_s == '5280.0')
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eymiha_units
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Anderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-03 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eymiha
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.1
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: eymiha_math
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.1.1
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: eymiha_util
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.5
|
41
|
+
version:
|
42
|
+
description:
|
43
|
+
email: dave@eymiha.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- gem_package.rb
|
52
|
+
- rakefile.rb
|
53
|
+
- lib/units
|
54
|
+
- lib/units/definitions
|
55
|
+
- lib/units/definitions/area.rb
|
56
|
+
- lib/units/definitions/length.rb
|
57
|
+
- lib/units/definitions/mass.rb
|
58
|
+
- lib/units/definitions/measures.rb
|
59
|
+
- lib/units/definitions/time.rb
|
60
|
+
- lib/units/definitions/velocity.rb
|
61
|
+
- lib/units/definitions/volume.rb
|
62
|
+
- lib/units/numeric.rb
|
63
|
+
- lib/units/numeric_with_units.rb
|
64
|
+
- lib/units/object.rb
|
65
|
+
- lib/units/units.rb
|
66
|
+
- lib/units/units_exception.rb
|
67
|
+
- lib/units/units_hash.rb
|
68
|
+
- lib/units/units_measure.rb
|
69
|
+
- lib/units/units_system.rb
|
70
|
+
- lib/units/units_unit.rb
|
71
|
+
- lib/units.rb
|
72
|
+
- test/framework.rb
|
73
|
+
- test/tc_definitions.rb
|
74
|
+
- test/tc_formatting.rb
|
75
|
+
- test/tc_formatting_derived.rb
|
76
|
+
- test/tc_measure_create.rb
|
77
|
+
- test/tc_measure_derive.rb
|
78
|
+
- test/tc_system_create.rb
|
79
|
+
- test/tc_unit_ambiguity.rb
|
80
|
+
- test/tc_unit_arithmetic.rb
|
81
|
+
- test/tc_unit_create.rb
|
82
|
+
- test/tc_unit_derive.rb
|
83
|
+
- test/tc_unit_equality.rb
|
84
|
+
- test/tc_unit_forward_reference.rb
|
85
|
+
- test/tc_unit_greek.rb
|
86
|
+
- test/tc_unit_hash.rb
|
87
|
+
- test/tc_unit_identifiers.rb
|
88
|
+
- test/tc_unit_rank.rb
|
89
|
+
- test/tc_uses_1.rb
|
90
|
+
- test/tc_uses_2.rb
|
91
|
+
has_rdoc: true
|
92
|
+
homepage: http://www.eymiha.com
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options:
|
95
|
+
- --all
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
version:
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project: cori
|
113
|
+
rubygems_version: 1.0.1
|
114
|
+
signing_key:
|
115
|
+
specification_version: 2
|
116
|
+
summary: Emiyha - units and conversions
|
117
|
+
test_files: []
|
118
|
+
|