phys-units 0.9.7 → 0.9.8
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.
- checksums.yaml +4 -4
- data/lib/phys/units/version.rb +1 -1
- data/spec/all_units_spec.rb +2326 -2326
- data/spec/helper.rb +15 -1
- data/spec/jp_units_spec.rb +83 -83
- data/spec/quantity_spec.rb +89 -89
- data/spec/unit_spec.rb +174 -174
- data/spec/utils_spec.rb +2 -2
- metadata +4 -3
data/spec/unit_spec.rb
CHANGED
@@ -4,226 +4,226 @@ require "helper"
|
|
4
4
|
describe "Create Units" do
|
5
5
|
|
6
6
|
describe U[1] do
|
7
|
-
it {
|
8
|
-
its(:factor) {
|
9
|
-
its(:conversion_factor) {
|
10
|
-
its(:name) {
|
11
|
-
its(:expr) {
|
12
|
-
its(:offset) {
|
13
|
-
its(:dimension) {
|
14
|
-
its(:dimension_value) {
|
15
|
-
its(:string_form) {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
7
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
8
|
+
its(:factor) {is_expected.to eq 1}
|
9
|
+
its(:conversion_factor) {is_expected.to eq 1}
|
10
|
+
its(:name) {is_expected.to be_nil}
|
11
|
+
its(:expr) {is_expected.to be_nil}
|
12
|
+
its(:offset) {is_expected.to be_nil}
|
13
|
+
its(:dimension) {is_expected.to eq({})}
|
14
|
+
its(:dimension_value) {is_expected.to eq 1}
|
15
|
+
its(:string_form) {is_expected.to eq ""}
|
16
|
+
it {is_expected.to be_dimensionless}
|
17
|
+
it {is_expected.to be_scalar}
|
18
|
+
it {is_expected.to be_operable}
|
19
19
|
end
|
20
20
|
|
21
21
|
describe U[2] do
|
22
|
-
it {
|
23
|
-
its(:factor) {
|
24
|
-
its(:conversion_factor) {
|
25
|
-
its(:name) {
|
26
|
-
its(:expr) {
|
27
|
-
its(:offset) {
|
28
|
-
its(:dimension) {
|
29
|
-
its(:dimension_value) {
|
30
|
-
its(:string_form) {
|
31
|
-
it {
|
32
|
-
it {
|
33
|
-
it {
|
22
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
23
|
+
its(:factor) {is_expected.to eq 2}
|
24
|
+
its(:conversion_factor) {is_expected.to eq 2}
|
25
|
+
its(:name) {is_expected.to be_nil}
|
26
|
+
its(:expr) {is_expected.to be_nil}
|
27
|
+
its(:offset) {is_expected.to be_nil}
|
28
|
+
its(:dimension) {is_expected.to eq({})}
|
29
|
+
its(:dimension_value) {is_expected.to eq 1}
|
30
|
+
its(:string_form) {is_expected.to eq "2"}
|
31
|
+
it {is_expected.to be_dimensionless}
|
32
|
+
it {is_expected.not_to be_scalar}
|
33
|
+
it {is_expected.to be_operable}
|
34
34
|
end
|
35
35
|
|
36
36
|
describe U['pi'] do
|
37
|
-
it {
|
38
|
-
its(:factor) {
|
39
|
-
its(:conversion_factor) {
|
40
|
-
its(:name) {
|
41
|
-
its(:expr) {
|
42
|
-
its(:offset) {
|
43
|
-
its(:dimension) {
|
44
|
-
its(:dimension_value) {
|
45
|
-
its(:string_form) {
|
46
|
-
it {
|
47
|
-
it {
|
48
|
-
it {
|
37
|
+
it {is_expected.to be_an_kind_of Phys::Unit}
|
38
|
+
its(:factor) {is_expected.to eq 1}
|
39
|
+
its(:conversion_factor) {is_expected.to eq Math::PI}
|
40
|
+
its(:name) {is_expected.to eq 'pi'}
|
41
|
+
its(:expr) {is_expected.to eq '!dimensionless'}
|
42
|
+
its(:offset) {is_expected.to be_nil}
|
43
|
+
its(:dimension) {is_expected.to eq({'pi'=>1})}
|
44
|
+
its(:dimension_value) {is_expected.to eq Math::PI}
|
45
|
+
its(:string_form) {is_expected.to eq "pi"}
|
46
|
+
it {is_expected.to be_dimensionless}
|
47
|
+
it {is_expected.not_to be_scalar}
|
48
|
+
it {is_expected.to be_operable}
|
49
49
|
end
|
50
50
|
|
51
51
|
describe U['m'] do
|
52
|
-
it {
|
53
|
-
its(:factor) {
|
54
|
-
its(:conversion_factor) {
|
55
|
-
its(:name) {
|
56
|
-
its(:expr) {
|
57
|
-
its(:offset) {
|
58
|
-
its(:dimension) {
|
59
|
-
its(:dimension_value) {
|
60
|
-
its(:string_form) {
|
61
|
-
it {
|
62
|
-
it {
|
63
|
-
it {
|
52
|
+
it {is_expected.to be_an_kind_of Phys::Unit}
|
53
|
+
its(:factor) {is_expected.to eq 1}
|
54
|
+
its(:conversion_factor) {is_expected.to eq 1}
|
55
|
+
its(:name) {is_expected.to eq 'm'}
|
56
|
+
its(:expr) {is_expected.to eq '!'}
|
57
|
+
its(:offset) {is_expected.to be_nil}
|
58
|
+
its(:dimension) {is_expected.to eq({'m'=>1})}
|
59
|
+
its(:dimension_value) {is_expected.to eq 1}
|
60
|
+
its(:string_form) {is_expected.to eq "m"}
|
61
|
+
it {is_expected.not_to be_dimensionless}
|
62
|
+
it {is_expected.not_to be_scalar}
|
63
|
+
it {is_expected.to be_operable}
|
64
64
|
end
|
65
65
|
|
66
66
|
describe U[:m] do
|
67
|
-
it {
|
67
|
+
it {is_expected.to eq U["m"]}
|
68
68
|
end
|
69
69
|
|
70
70
|
describe U['miles'] do
|
71
|
-
it {
|
72
|
-
its(:factor) {
|
73
|
-
its(:factor) {
|
74
|
-
its(:conversion_factor) {
|
75
|
-
its(:name) {
|
76
|
-
its(:expr) {
|
77
|
-
its(:offset) {
|
78
|
-
its(:dimension) {
|
79
|
-
its(:dimension_value) {
|
80
|
-
its(:string_form) {
|
81
|
-
it {
|
82
|
-
it {
|
83
|
-
it {
|
71
|
+
it {is_expected.to be_an_kind_of Phys::Unit}
|
72
|
+
its(:factor) {is_expected.to eq 1609.344}
|
73
|
+
its(:factor) {is_expected.to be_an_instance_of Rational}
|
74
|
+
its(:conversion_factor) {is_expected.to eq 1609.344}
|
75
|
+
its(:name) {is_expected.to eq 'mile'}
|
76
|
+
its(:expr) {is_expected.to eq "5280 ft"}
|
77
|
+
its(:offset) {is_expected.to be_nil}
|
78
|
+
its(:dimension) {is_expected.to eq({'m'=>1})}
|
79
|
+
its(:dimension_value) {is_expected.to eq 1}
|
80
|
+
its(:string_form) {is_expected.to eq "1609.344 m"}
|
81
|
+
it {is_expected.not_to be_dimensionless}
|
82
|
+
it {is_expected.not_to be_scalar}
|
83
|
+
it {is_expected.to be_operable}
|
84
84
|
end
|
85
85
|
|
86
86
|
describe 1.609344*U['km'] do
|
87
|
-
it {
|
88
|
-
it {
|
89
|
-
its(:factor) {
|
90
|
-
its(:conversion_factor) {
|
91
|
-
its(:name) {
|
92
|
-
its(:expr) {
|
93
|
-
its(:offset) {
|
94
|
-
its(:dimension) {
|
95
|
-
its(:dimension_value) {
|
96
|
-
its(:string_form) {
|
97
|
-
it {
|
98
|
-
it {
|
99
|
-
it {
|
87
|
+
it {is_expected.to be_an_kind_of Phys::Unit}
|
88
|
+
it {is_expected.to eq Phys::Unit[:miles]}
|
89
|
+
its(:factor) {is_expected.to eq 1609.344}
|
90
|
+
its(:conversion_factor) {is_expected.to eq 1609.344}
|
91
|
+
its(:name) {is_expected.to be_nil}
|
92
|
+
its(:expr) {is_expected.to be_nil}
|
93
|
+
its(:offset) {is_expected.to be_nil}
|
94
|
+
its(:dimension) {is_expected.to eq({'m'=>1})}
|
95
|
+
its(:dimension_value) {is_expected.to eq 1}
|
96
|
+
its(:string_form) {is_expected.to eq "1609.344 m"}
|
97
|
+
it {is_expected.not_to be_dimensionless}
|
98
|
+
it {is_expected.not_to be_scalar}
|
99
|
+
it {is_expected.to be_operable}
|
100
100
|
end
|
101
101
|
|
102
102
|
describe U['g'] do
|
103
|
-
it {
|
104
|
-
its(:factor) {
|
105
|
-
its(:conversion_factor) {
|
106
|
-
its(:name) {
|
107
|
-
#its(:expr) {
|
108
|
-
its(:offset) {
|
109
|
-
its(:dimension) {
|
110
|
-
its(:dimension_value) {
|
111
|
-
its(:string_form) {
|
112
|
-
it {
|
113
|
-
it {
|
114
|
-
it {
|
103
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
104
|
+
its(:factor) {is_expected.to eq Rational(1,1000)}
|
105
|
+
its(:conversion_factor) {is_expected.to eq Rational(1,1000)}
|
106
|
+
its(:name) {is_expected.to eq 'g'}
|
107
|
+
#its(:expr) {is_expected.to eq 'gram'}
|
108
|
+
its(:offset) {is_expected.to be_nil}
|
109
|
+
its(:dimension) {is_expected.to eq({'kg'=>1})}
|
110
|
+
its(:dimension_value) {is_expected.to eq 1}
|
111
|
+
its(:string_form) {is_expected.to eq "0.001 kg"}
|
112
|
+
it {is_expected.not_to be_dimensionless}
|
113
|
+
it {is_expected.not_to be_scalar}
|
114
|
+
it {is_expected.to be_operable}
|
115
115
|
end
|
116
116
|
|
117
117
|
|
118
118
|
describe U['h'] do
|
119
|
-
it {
|
120
|
-
its(:factor) {
|
121
|
-
its(:conversion_factor) {
|
122
|
-
its(:name) {
|
123
|
-
its(:expr) {
|
124
|
-
its(:offset) {
|
125
|
-
its(:dimension) {
|
126
|
-
its(:dimension_value) {
|
127
|
-
its(:string_form) {
|
128
|
-
it {
|
129
|
-
it {
|
130
|
-
it {
|
119
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
120
|
+
its(:factor) {is_expected.to be_within(1e-16*1e-33).of 6.626069574766962e-34}
|
121
|
+
its(:conversion_factor) {is_expected.to be_within(1e-16*1e-33).of 6.626069574766962e-34}
|
122
|
+
its(:name) {is_expected.to eq 'h'}
|
123
|
+
its(:expr) {is_expected.to eq "4.135667516e-15 eV s"}
|
124
|
+
its(:offset) {is_expected.to be_nil}
|
125
|
+
its(:dimension) {is_expected.to eq({'kg'=>1,'m'=>2,'s'=>-1})}
|
126
|
+
its(:dimension_value) {is_expected.to eq 1}
|
127
|
+
its(:string_form) {is_expected.to eq "6.626069574766962e-34 s^-1 kg m^2"}
|
128
|
+
it {is_expected.not_to be_dimensionless}
|
129
|
+
it {is_expected.not_to be_scalar}
|
130
|
+
it {is_expected.to be_operable}
|
131
131
|
end
|
132
132
|
|
133
133
|
describe U['e'] do
|
134
|
-
it {
|
135
|
-
its(:factor) {
|
136
|
-
its(:conversion_factor) {
|
137
|
-
its(:name) {
|
138
|
-
its(:expr) {
|
139
|
-
its(:offset) {
|
140
|
-
its(:dimension) {
|
141
|
-
its(:dimension_value) {
|
142
|
-
its(:string_form) {
|
143
|
-
it {
|
144
|
-
it {
|
145
|
-
it {
|
134
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
135
|
+
its(:factor) {is_expected.to be_within(1e-15*1e-18).of 1.602176565e-19}
|
136
|
+
its(:conversion_factor) {is_expected.to be_within(1e-15*1e-18).of 1.602176565e-19}
|
137
|
+
its(:name) {is_expected.to eq 'e'}
|
138
|
+
its(:expr) {is_expected.to eq "1.602176565e-19 C"}
|
139
|
+
its(:offset) {is_expected.to be_nil}
|
140
|
+
its(:dimension) {is_expected.to eq({'A'=>1,'s'=>1})}
|
141
|
+
its(:dimension_value) {is_expected.to eq 1}
|
142
|
+
its(:string_form) {is_expected.to eq "1.602176565e-19 A s"}
|
143
|
+
it {is_expected.not_to be_dimensionless}
|
144
|
+
it {is_expected.not_to be_scalar}
|
145
|
+
it {is_expected.to be_operable}
|
146
146
|
end
|
147
147
|
|
148
148
|
describe U.parse('123.5 s') do
|
149
|
-
it {
|
150
|
-
its(:factor) {
|
151
|
-
its(:conversion_factor) {
|
152
|
-
its(:name) {
|
153
|
-
its(:expr) {
|
154
|
-
its(:offset) {
|
155
|
-
its(:dimension) {
|
156
|
-
its(:dimension_value) {
|
157
|
-
its(:string_form) {
|
158
|
-
it {
|
159
|
-
it {
|
160
|
-
it {
|
149
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
150
|
+
its(:factor) {is_expected.to eq 123.5}
|
151
|
+
its(:conversion_factor) {is_expected.to eq 123.5}
|
152
|
+
its(:name) {is_expected.to be_nil}
|
153
|
+
its(:expr) {is_expected.to be_nil}
|
154
|
+
its(:offset) {is_expected.to be_nil}
|
155
|
+
its(:dimension) {is_expected.to eq({'s'=>1})}
|
156
|
+
its(:dimension_value) {is_expected.to eq 1}
|
157
|
+
its(:string_form) {is_expected.to eq "123.5 s"}
|
158
|
+
it {is_expected.not_to be_dimensionless}
|
159
|
+
it {is_expected.not_to be_scalar}
|
160
|
+
it {is_expected.to be_operable}
|
161
161
|
end
|
162
162
|
|
163
163
|
describe U['m']/U['s'] do
|
164
|
-
it {
|
165
|
-
its(:factor) {
|
166
|
-
its(:conversion_factor) {
|
167
|
-
its(:name) {
|
168
|
-
its(:expr) {
|
169
|
-
its(:offset) {
|
170
|
-
its(:dimension) {
|
171
|
-
its(:dimension_value) {
|
172
|
-
its(:string_form) {
|
173
|
-
it {
|
174
|
-
it {
|
175
|
-
it {
|
176
|
-
it {
|
164
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
165
|
+
its(:factor) {is_expected.to eq 1}
|
166
|
+
its(:conversion_factor) {is_expected.to eq 1}
|
167
|
+
its(:name) {is_expected.to be_nil}
|
168
|
+
its(:expr) {is_expected.to be_nil}
|
169
|
+
its(:offset) {is_expected.to be_nil}
|
170
|
+
its(:dimension) {is_expected.to eq({'m'=>1, 's'=>-1})}
|
171
|
+
its(:dimension_value) {is_expected.to eq 1}
|
172
|
+
its(:string_form) {is_expected.to eq "m s^-1"}
|
173
|
+
it {is_expected.not_to be_dimensionless}
|
174
|
+
it {is_expected.not_to be_scalar}
|
175
|
+
it {is_expected.to be_operable}
|
176
|
+
it {is_expected.to be_comformable_with Q[1,'miles/hr']}
|
177
177
|
end
|
178
178
|
|
179
179
|
describe U.parse('(m/s)**2') do
|
180
|
-
it {
|
181
|
-
its(:factor) {
|
182
|
-
its(:conversion_factor) {
|
183
|
-
its(:name) {
|
184
|
-
its(:expr) {
|
185
|
-
its(:offset) {
|
186
|
-
its(:dimension) {
|
187
|
-
its(:dimension_value) {
|
188
|
-
its(:string_form) {
|
189
|
-
it {
|
190
|
-
it {
|
191
|
-
it {
|
180
|
+
it {is_expected.to be_an_instance_of Phys::Unit}
|
181
|
+
its(:factor) {is_expected.to eq 1}
|
182
|
+
its(:conversion_factor) {is_expected.to eq 1}
|
183
|
+
its(:name) {is_expected.to be_nil}
|
184
|
+
its(:expr) {is_expected.to be_nil}
|
185
|
+
its(:offset) {is_expected.to be_nil}
|
186
|
+
its(:dimension) {is_expected.to eq({'m'=>2, 's'=>-2})}
|
187
|
+
its(:dimension_value) {is_expected.to eq 1}
|
188
|
+
its(:string_form) {is_expected.to eq "m^2 s^-2"}
|
189
|
+
it {is_expected.not_to be_dimensionless}
|
190
|
+
it {is_expected.not_to be_scalar}
|
191
|
+
it {is_expected.to be_operable}
|
192
192
|
end
|
193
193
|
|
194
194
|
describe U.parse("3.6 km/hour") do
|
195
|
-
its(:string_form) {
|
195
|
+
its(:string_form) {is_expected.to eq "m s^-1"}
|
196
196
|
end
|
197
197
|
|
198
198
|
describe U['tempC'] do
|
199
|
-
it {
|
200
|
-
its(:factor) {
|
201
|
-
its(:conversion_factor) {
|
202
|
-
its(:name) {
|
203
|
-
its(:expr) {
|
204
|
-
its(:offset) {
|
205
|
-
its(:dimension) {
|
206
|
-
its(:dimension_value) {
|
207
|
-
its(:string_form) {
|
208
|
-
it {
|
209
|
-
it {
|
210
|
-
it {
|
199
|
+
it {is_expected.to be_an_instance_of Phys::OffsetUnit}
|
200
|
+
its(:factor) {is_expected.to eq 1}
|
201
|
+
its(:conversion_factor) {is_expected.to eq 1}
|
202
|
+
its(:name) {is_expected.to eq 'tempC'}
|
203
|
+
its(:expr) {is_expected.to be_nil}
|
204
|
+
its(:offset) {is_expected.to eq 273.15}
|
205
|
+
its(:dimension) {is_expected.to eq({'K'=>1})}
|
206
|
+
its(:dimension_value) {is_expected.to eq 1}
|
207
|
+
its(:string_form) {is_expected.to eq "K"}
|
208
|
+
it {is_expected.not_to be_dimensionless}
|
209
|
+
it {is_expected.not_to be_scalar}
|
210
|
+
it {is_expected.not_to be_operable}
|
211
211
|
end
|
212
212
|
|
213
213
|
describe U['tempF'] do
|
214
|
-
it {
|
215
|
-
its(:factor) {
|
216
|
-
its(:factor) {
|
217
|
-
its(:conversion_factor) {
|
218
|
-
its(:name) {
|
219
|
-
its(:expr) {
|
220
|
-
its(:offset) {
|
221
|
-
its(:dimension) {
|
222
|
-
its(:dimension_value) {
|
223
|
-
its(:string_form) {
|
224
|
-
it {
|
225
|
-
it {
|
226
|
-
it {
|
214
|
+
it {is_expected.to be_an_instance_of Phys::OffsetUnit}
|
215
|
+
its(:factor) {is_expected.to eq Rational(5,9)}
|
216
|
+
its(:factor) {is_expected.to be_an_instance_of Rational}
|
217
|
+
its(:conversion_factor) {is_expected.to eq Rational(5,9)}
|
218
|
+
its(:name) {is_expected.to eq 'tempF'}
|
219
|
+
its(:expr) {is_expected.to be_nil}
|
220
|
+
its(:offset) {is_expected.to eq Rational(45967,180)}
|
221
|
+
its(:dimension) {is_expected.to eq({'K'=>1})}
|
222
|
+
its(:dimension_value) {is_expected.to eq 1}
|
223
|
+
its(:string_form) {is_expected.to eq "(1/1.8) K"}
|
224
|
+
it {is_expected.not_to be_dimensionless}
|
225
|
+
it {is_expected.not_to be_scalar}
|
226
|
+
it {is_expected.not_to be_operable}
|
227
227
|
end
|
228
228
|
|
229
229
|
describe "temperature unit" do
|
data/spec/utils_spec.rb
CHANGED
@@ -6,11 +6,11 @@ Utils = Phys::Unit::Utils
|
|
6
6
|
describe "UnitUtils test" do
|
7
7
|
|
8
8
|
describe Utils.num_inspect(Rational(1609344,1000)) do
|
9
|
-
it {
|
9
|
+
it {is_expected.to eq "1609.344"}
|
10
10
|
end
|
11
11
|
|
12
12
|
describe Utils.num_inspect(Rational(1000,1609344)) do
|
13
|
-
it {
|
13
|
+
it {is_expected.to eq "(1/1609.344)"}
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phys-units
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.4.5
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Library for Unit conversion of Physical Quantities using GNU Units data.
|
@@ -111,3 +111,4 @@ test_files:
|
|
111
111
|
- spec/quantity_spec.rb
|
112
112
|
- spec/unit_spec.rb
|
113
113
|
- spec/utils_spec.rb
|
114
|
+
has_rdoc:
|