phys-units 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- 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/helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
begin
|
3
|
+
require "rspec/its"
|
4
|
+
rescue LoadError
|
5
|
+
$stderr.puts "Install rspec-its by:
|
6
|
+
gem install rspec-its"
|
7
|
+
exit(1)
|
8
|
+
end
|
9
|
+
|
2
10
|
require "phys/units"
|
3
11
|
|
4
12
|
U = Phys::Unit
|
@@ -7,7 +15,7 @@ Q = Phys::Quantity
|
|
7
15
|
RSpec::Matchers.define :be_sfloat_close_to do |y|
|
8
16
|
match do |x|
|
9
17
|
if x==0 && y==0
|
10
|
-
true
|
18
|
+
true
|
11
19
|
else
|
12
20
|
x = x.to_f
|
13
21
|
(x-y).abs/(x.abs+y.abs) < 1.2e-7
|
@@ -24,3 +32,9 @@ RSpec::Matchers.define :be_a_quantity_close_to do |expected|
|
|
24
32
|
end
|
25
33
|
end
|
26
34
|
end
|
35
|
+
|
36
|
+
RSpec::Matchers.define :be_comformable_with do |expected|
|
37
|
+
match do |actual|
|
38
|
+
actual === expected
|
39
|
+
end
|
40
|
+
end
|
data/spec/jp_units_spec.rb
CHANGED
@@ -5,252 +5,252 @@ require "helper"
|
|
5
5
|
|
6
6
|
describe "Japanese Units" do
|
7
7
|
describe Q[1,"一"] do
|
8
|
-
it {
|
8
|
+
it {is_expected.to be_a_quantity_close_to Q[1] }
|
9
9
|
end
|
10
10
|
describe Q[1,"二"] do
|
11
|
-
it {
|
11
|
+
it {is_expected.to be_a_quantity_close_to Q[2] }
|
12
12
|
end
|
13
13
|
describe Q[1,"三"] do
|
14
|
-
it {
|
14
|
+
it {is_expected.to be_a_quantity_close_to Q[3] }
|
15
15
|
end
|
16
16
|
describe Q[1,"四"] do
|
17
|
-
it {
|
17
|
+
it {is_expected.to be_a_quantity_close_to Q[4] }
|
18
18
|
end
|
19
19
|
describe Q[1,"五"] do
|
20
|
-
it {
|
20
|
+
it {is_expected.to be_a_quantity_close_to Q[5] }
|
21
21
|
end
|
22
22
|
describe Q[1,"六"] do
|
23
|
-
it {
|
23
|
+
it {is_expected.to be_a_quantity_close_to Q[6] }
|
24
24
|
end
|
25
25
|
describe Q[1,"七"] do
|
26
|
-
it {
|
26
|
+
it {is_expected.to be_a_quantity_close_to Q[7] }
|
27
27
|
end
|
28
28
|
describe Q[1,"八"] do
|
29
|
-
it {
|
29
|
+
it {is_expected.to be_a_quantity_close_to Q[8] }
|
30
30
|
end
|
31
31
|
describe Q[1,"九"] do
|
32
|
-
it {
|
32
|
+
it {is_expected.to be_a_quantity_close_to Q[9] }
|
33
33
|
end
|
34
34
|
describe Q[1,"十"] do
|
35
|
-
it {
|
35
|
+
it {is_expected.to be_a_quantity_close_to Q[10] }
|
36
36
|
end
|
37
37
|
describe Q[1,"百"] do
|
38
|
-
it {
|
38
|
+
it {is_expected.to be_a_quantity_close_to Q[100] }
|
39
39
|
end
|
40
40
|
describe Q[1,"千"] do
|
41
|
-
it {
|
41
|
+
it {is_expected.to be_a_quantity_close_to Q[1000] }
|
42
42
|
end
|
43
43
|
describe Q[1,"万"] do
|
44
|
-
it {
|
44
|
+
it {is_expected.to be_a_quantity_close_to Q[10000] }
|
45
45
|
end
|
46
46
|
describe Q[1,"億"] do
|
47
|
-
it {
|
47
|
+
it {is_expected.to be_a_quantity_close_to Q[100000000] }
|
48
48
|
end
|
49
49
|
describe Q[1,"兆"] do
|
50
|
-
it {
|
50
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+12] }
|
51
51
|
end
|
52
52
|
describe Q[1,"京"] do
|
53
|
-
it {
|
53
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+16] }
|
54
54
|
end
|
55
55
|
describe Q[1,"垓"] do
|
56
|
-
it {
|
56
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+20] }
|
57
57
|
end
|
58
58
|
describe Q[1,"秭"] do
|
59
|
-
it {
|
59
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+24] }
|
60
60
|
end
|
61
61
|
describe Q[1,"秭"] do
|
62
|
-
it {
|
62
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+24] }
|
63
63
|
end
|
64
64
|
describe Q[1,"穰"] do
|
65
|
-
it {
|
65
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+28] }
|
66
66
|
end
|
67
67
|
describe Q[1,"溝"] do
|
68
|
-
it {
|
68
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+32] }
|
69
69
|
end
|
70
70
|
describe Q[1,"澗"] do
|
71
|
-
it {
|
71
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+36] }
|
72
72
|
end
|
73
73
|
describe Q[1,"正"] do
|
74
|
-
it {
|
74
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+40] }
|
75
75
|
end
|
76
76
|
describe Q[1,"載"] do
|
77
|
-
it {
|
77
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+44] }
|
78
78
|
end
|
79
79
|
describe Q[1,"極"] do
|
80
|
-
it {
|
80
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+48] }
|
81
81
|
end
|
82
82
|
describe Q[1,"恒河沙"] do
|
83
|
-
it {
|
83
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+52] }
|
84
84
|
end
|
85
85
|
describe Q[1,"阿僧祇"] do
|
86
|
-
it {
|
86
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+56] }
|
87
87
|
end
|
88
88
|
describe Q[1,"那由他"] do
|
89
|
-
it {
|
89
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+60] }
|
90
90
|
end
|
91
91
|
describe Q[1,"不可思議"] do
|
92
|
-
it {
|
92
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+64] }
|
93
93
|
end
|
94
94
|
describe Q[1,"無量大数"] do
|
95
|
-
it {
|
95
|
+
it {is_expected.to be_a_quantity_close_to Q[1e+68] }
|
96
96
|
end
|
97
97
|
describe Q[1,"割"] do
|
98
|
-
it {
|
98
|
+
it {is_expected.to be_a_quantity_close_to Q[0.1] }
|
99
99
|
end
|
100
100
|
describe Q[1,"分"] do
|
101
|
-
it {
|
101
|
+
it {is_expected.to be_a_quantity_close_to Q[0.01] }
|
102
102
|
end
|
103
103
|
describe Q[1,"厘"] do
|
104
|
-
it {
|
104
|
+
it {is_expected.to be_a_quantity_close_to Q[0.001] }
|
105
105
|
end
|
106
106
|
describe Q[1,"釐"] do
|
107
|
-
it {
|
107
|
+
it {is_expected.to be_a_quantity_close_to Q[0.001] }
|
108
108
|
end
|
109
109
|
describe Q[1,"毛"] do
|
110
|
-
it {
|
110
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0001] }
|
111
111
|
end
|
112
112
|
describe Q[1,"毫"] do
|
113
|
-
it {
|
113
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0001] }
|
114
114
|
end
|
115
115
|
describe Q[1,"糸"] do
|
116
|
-
it {
|
116
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0001] }
|
117
117
|
end
|
118
118
|
describe Q[1,"絲"] do
|
119
|
-
it {
|
119
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0001] }
|
120
120
|
end
|
121
121
|
describe Q[1,"忽"] do
|
122
|
-
it {
|
122
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-05] }
|
123
123
|
end
|
124
124
|
describe Q[1,"微"] do
|
125
|
-
it {
|
125
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-06] }
|
126
126
|
end
|
127
127
|
describe Q[1,"繊"] do
|
128
|
-
it {
|
128
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-07] }
|
129
129
|
end
|
130
130
|
describe Q[1,"沙"] do
|
131
|
-
it {
|
131
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-08] }
|
132
132
|
end
|
133
133
|
describe Q[1,"塵"] do
|
134
|
-
it {
|
134
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-09] }
|
135
135
|
end
|
136
136
|
describe Q[1,"埃"] do
|
137
|
-
it {
|
137
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-10] }
|
138
138
|
end
|
139
139
|
describe Q[1,"渺"] do
|
140
|
-
it {
|
140
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-11] }
|
141
141
|
end
|
142
142
|
describe Q[1,"漠"] do
|
143
|
-
it {
|
143
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-12] }
|
144
144
|
end
|
145
145
|
describe Q[1,"模糊"] do
|
146
|
-
it {
|
146
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-13] }
|
147
147
|
end
|
148
148
|
describe Q[1,"逡巡"] do
|
149
|
-
it {
|
149
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-14] }
|
150
150
|
end
|
151
151
|
describe Q[1,"須臾"] do
|
152
|
-
it {
|
152
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-15] }
|
153
153
|
end
|
154
154
|
describe Q[1,"瞬息"] do
|
155
|
-
it {
|
155
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-16] }
|
156
156
|
end
|
157
157
|
describe Q[1,"弾指"] do
|
158
|
-
it {
|
158
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-17] }
|
159
159
|
end
|
160
160
|
describe Q[1,"刹那"] do
|
161
|
-
it {
|
161
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-18] }
|
162
162
|
end
|
163
163
|
describe Q[1,"六徳"] do
|
164
|
-
it {
|
164
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-19] }
|
165
165
|
end
|
166
166
|
describe Q[1,"虚空"] do
|
167
|
-
it {
|
167
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-20] }
|
168
168
|
end
|
169
169
|
describe Q[1,"清浄"] do
|
170
|
-
it {
|
170
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-21] }
|
171
171
|
end
|
172
172
|
describe Q[1,"阿頼耶"] do
|
173
|
-
it {
|
173
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-22] }
|
174
174
|
end
|
175
175
|
describe Q[1,"阿摩羅"] do
|
176
|
-
it {
|
176
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-23] }
|
177
177
|
end
|
178
178
|
describe Q[1,"涅槃寂静"] do
|
179
|
-
it {
|
179
|
+
it {is_expected.to be_a_quantity_close_to Q[1e-24] }
|
180
180
|
end
|
181
181
|
describe Q[1,"尺"] do
|
182
|
-
it {
|
182
|
+
it {is_expected.to be_a_quantity_close_to Q[0.303030303,"m"] }
|
183
183
|
end
|
184
184
|
describe Q[1,"寸"] do
|
185
|
-
it {
|
185
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0303030303,"m"] }
|
186
186
|
end
|
187
187
|
describe Q[1,"里"] do
|
188
|
-
it {
|
188
|
+
it {is_expected.to be_a_quantity_close_to Q[3927.27273,"m"] }
|
189
189
|
end
|
190
190
|
describe Q[1,"町"] do
|
191
|
-
it {
|
191
|
+
it {is_expected.to be_a_quantity_close_to Q[109.090909,"m"] }
|
192
192
|
end
|
193
193
|
describe Q[1,"間"] do
|
194
|
-
it {
|
194
|
+
it {is_expected.to be_a_quantity_close_to Q[1.81818182,"m"] }
|
195
195
|
end
|
196
196
|
describe Q[1,"丈"] do
|
197
|
-
it {
|
197
|
+
it {is_expected.to be_a_quantity_close_to Q[3.03030303,"m"] }
|
198
198
|
end
|
199
199
|
describe Q[1,"曲尺"] do
|
200
|
-
it {
|
200
|
+
it {is_expected.to be_a_quantity_close_to Q[0.303030303,"m"] }
|
201
201
|
end
|
202
202
|
describe Q[1,"鯨尺"] do
|
203
|
-
it {
|
203
|
+
it {is_expected.to be_a_quantity_close_to Q[0.378787879,"m"] }
|
204
204
|
end
|
205
205
|
describe Q[1,"坪"] do
|
206
|
-
it {
|
206
|
+
it {is_expected.to be_a_quantity_close_to Q[3.30578512,"m^2"] }
|
207
207
|
end
|
208
208
|
describe Q[1,"畝"] do
|
209
|
-
it {
|
209
|
+
it {is_expected.to be_a_quantity_close_to Q[99.1735537,"m^2"] }
|
210
210
|
end
|
211
211
|
describe Q[1,"反"] do
|
212
|
-
it {
|
212
|
+
it {is_expected.to be_a_quantity_close_to Q[991.735537,"m^2"] }
|
213
213
|
end
|
214
214
|
describe Q[1,"段"] do
|
215
|
-
it {
|
215
|
+
it {is_expected.to be_a_quantity_close_to Q[991.735537,"m^2"] }
|
216
216
|
end
|
217
217
|
describe Q[1,"江戸間"] do
|
218
|
-
it {
|
218
|
+
it {is_expected.to be_a_quantity_close_to Q[1.54453627,"m^2"] }
|
219
219
|
end
|
220
220
|
describe Q[1,"京間"] do
|
221
|
-
it {
|
221
|
+
it {is_expected.to be_a_quantity_close_to Q[1.82231405,"m^2"] }
|
222
222
|
end
|
223
223
|
describe Q[1,"中京間"] do
|
224
|
-
it {
|
224
|
+
it {is_expected.to be_a_quantity_close_to Q[1.65289256,"m^2"] }
|
225
225
|
end
|
226
226
|
describe Q[1,"畳"] do
|
227
|
-
it {
|
227
|
+
it {is_expected.to be_a_quantity_close_to Q[1.54453627,"m^2"] }
|
228
228
|
end
|
229
229
|
describe Q[1,"升"] do
|
230
|
-
it {
|
230
|
+
it {is_expected.to be_a_quantity_close_to Q[0.00180390684,"m^3"] }
|
231
231
|
end
|
232
232
|
describe Q[1,"斗"] do
|
233
|
-
it {
|
233
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0180390684,"m^3"] }
|
234
234
|
end
|
235
235
|
describe Q[1,"石"] do
|
236
|
-
it {
|
236
|
+
it {is_expected.to be_a_quantity_close_to Q[0.180390684,"m^3"] }
|
237
237
|
end
|
238
238
|
describe Q[1,"合"] do
|
239
|
-
it {
|
239
|
+
it {is_expected.to be_a_quantity_close_to Q[0.000180390684,"m^3"] }
|
240
240
|
end
|
241
241
|
describe Q[1,"勺"] do
|
242
|
-
it {
|
242
|
+
it {is_expected.to be_a_quantity_close_to Q[1.80390684e-05,"m^3"] }
|
243
243
|
end
|
244
244
|
describe Q[1,"貫"] do
|
245
|
-
it {
|
245
|
+
it {is_expected.to be_a_quantity_close_to Q[3.75,"kg"] }
|
246
246
|
end
|
247
247
|
describe Q[1,"斤"] do
|
248
|
-
it {
|
248
|
+
it {is_expected.to be_a_quantity_close_to Q[0.6,"kg"] }
|
249
249
|
end
|
250
250
|
describe Q[1,"両"] do
|
251
|
-
it {
|
251
|
+
it {is_expected.to be_a_quantity_close_to Q[0.0375,"kg"] }
|
252
252
|
end
|
253
253
|
describe Q[1,"匁"] do
|
254
|
-
it {
|
254
|
+
it {is_expected.to be_a_quantity_close_to Q[0.00375,"kg"] }
|
255
255
|
end
|
256
256
|
end
|
data/spec/quantity_spec.rb
CHANGED
@@ -5,150 +5,150 @@ describe "Phys::Quantity" do
|
|
5
5
|
|
6
6
|
context "equality" do
|
7
7
|
describe Q[12] do
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
8
|
+
it {is_expected.to eq 12}
|
9
|
+
it {is_expected.to eq Q[12]}
|
10
|
+
it {is_expected.to eq Q[12,"radian"]}
|
11
|
+
it {is_expected.to eq Q[1,"dozen"]}
|
12
|
+
it {is_expected.not_to eq Q[12,"pi"]}
|
13
|
+
it {is_expected.not_to eq Q[12,"km"]}
|
14
14
|
end
|
15
15
|
describe Q[12,"radian"] do
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
16
|
+
it {is_expected.to eq 12}
|
17
|
+
it {is_expected.to eq Q[12]}
|
18
|
+
it {is_expected.to eq Q[12,"radian"]}
|
19
|
+
it {is_expected.to eq Q[1,"dozen"]}
|
20
|
+
it {is_expected.not_to eq Q[12,"pi"]}
|
21
|
+
it {is_expected.not_to eq Q[12,"km"]}
|
22
22
|
end
|
23
23
|
describe Q[12,"km"] do
|
24
|
-
it {
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
it {
|
29
|
-
it {
|
30
|
-
it {
|
24
|
+
it {is_expected.not_to eq 12}
|
25
|
+
it {is_expected.not_to eq Q[12]}
|
26
|
+
it {is_expected.not_to eq Q[12,"radian"]}
|
27
|
+
it {is_expected.not_to eq Q[1,"dozen"]}
|
28
|
+
it {is_expected.not_to eq Q[12,"pi"]}
|
29
|
+
it {is_expected.to eq Q[12,"km"]}
|
30
|
+
it {is_expected.to eq Q[1,"dozen km"]}
|
31
31
|
end
|
32
32
|
describe 12 do
|
33
|
-
it {
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
33
|
+
it {is_expected.to eq Q[12]}
|
34
|
+
it {is_expected.to eq Q[12,"radian"]}
|
35
|
+
it {is_expected.to eq Q[1,"dozen"]}
|
36
|
+
it {is_expected.not_to eq Q[12,"pi"]}
|
37
|
+
it {is_expected.not_to eq Q[12,"km"]}
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context "methods" do
|
42
42
|
describe Q[1.25,"km"] do
|
43
43
|
before {@q = Q[1.25,"km"]; @r = Q[500,"m"]}
|
44
|
-
it {@q.value.
|
45
|
-
it {@q.expr.
|
46
|
-
it {@q.unit.
|
47
|
-
it {@q.want("cm").value.
|
48
|
-
it {(@q >> "cm").value.
|
49
|
-
it {(@q >> U["cm"]).value.
|
50
|
-
it {(@q >> Q[1,"cm"]).value.
|
51
|
-
it {(@q + @r).
|
52
|
-
it {(@q - @r).
|
53
|
-
it {@q.abs.
|
54
|
-
it {@q.abs2.
|
55
|
-
it {@q.ceil.
|
56
|
-
it {@q.round.
|
57
|
-
it {@q.floor.
|
58
|
-
it {@q.truncate.
|
59
|
-
it {(+@q).
|
60
|
-
it {(-@q).
|
61
|
-
it {(@q <=> @r).
|
62
|
-
it {(@q == @r).
|
63
|
-
it {(@q > @r).
|
64
|
-
it {(@q >= @r).
|
65
|
-
it {(@q < @r).
|
66
|
-
it {(@q <= @r).
|
67
|
-
it {(@q **2).
|
68
|
-
it {(@q * @r).
|
69
|
-
it {(@q / @r).
|
70
|
-
it {(@q.quo @r).
|
71
|
-
it {(@q.div @r).
|
72
|
-
it {(@q.div 0.5).
|
73
|
-
it {(@q % @r).
|
74
|
-
it {(@q % 0.5).
|
75
|
-
it {(@q.divmod @r).
|
76
|
-
it {(@q.divmod 0.5).
|
77
|
-
it {(@q.remainder @r).
|
78
|
-
it {@q.to_base_unit.value.
|
44
|
+
it {expect(@q.value).to eq 1.25}
|
45
|
+
it {expect(@q.expr).to eq "km"}
|
46
|
+
it {expect(@q.unit).to eq Phys::Unit["km"]}
|
47
|
+
it {expect(@q.want("cm").value).to eq 125000}
|
48
|
+
it {expect((@q >> "cm").value).to eq 125000}
|
49
|
+
it {expect((@q >> U["cm"]).value).to eq 125000}
|
50
|
+
it {expect((@q >> Q[1,"cm"]).value).to eq 125000}
|
51
|
+
it {expect((@q + @r)).to eq Q[1.75,"km"]}
|
52
|
+
it {expect((@q - @r)).to eq Q[0.75,"km"]}
|
53
|
+
it {expect(@q.abs).to eq Q[1.25,"km"]}
|
54
|
+
it {expect(@q.abs2).to eq Q[1.5625,"km^2"]}
|
55
|
+
it {expect(@q.ceil).to eq Q[2,"km"]}
|
56
|
+
it {expect(@q.round).to eq Q[1,"km"]}
|
57
|
+
it {expect(@q.floor).to eq Q[1,"km"]}
|
58
|
+
it {expect(@q.truncate).to eq Q[1,"km"]}
|
59
|
+
it {expect((+@q)).to eq Q[1.25,"km"]}
|
60
|
+
it {expect((-@q)).to eq Q[-1.25,"km"]}
|
61
|
+
it {expect((@q <=> @r)).to eq 1}
|
62
|
+
it {expect((@q == @r)).to be_falsey}
|
63
|
+
it {expect((@q > @r)).to be_truthy}
|
64
|
+
it {expect((@q >= @r)).to be_truthy}
|
65
|
+
it {expect((@q < @r)).to be_falsey}
|
66
|
+
it {expect((@q <= @r)).to be_falsey}
|
67
|
+
it {expect((@q **2)).to eq Q[1.5625,"km^2"]}
|
68
|
+
it {expect((@q * @r)).to eq Q[0.625,"km^2"]}
|
69
|
+
it {expect((@q / @r)).to eq Q[2.5]}
|
70
|
+
it {expect((@q.quo @r)).to eq Q[2.5]}
|
71
|
+
it {expect((@q.div @r)).to eq 2}
|
72
|
+
it {expect((@q.div 0.5)).to eq Q[2,"km"]}
|
73
|
+
it {expect((@q % @r)).to eq 0.25}
|
74
|
+
it {expect((@q % 0.5)).to eq Q[0.25,"km"]}
|
75
|
+
it {expect((@q.divmod @r)).to eq [2,0.25]}
|
76
|
+
it {expect((@q.divmod 0.5)).to eq [Q[2,"km"],Q[0.25,"km"]]}
|
77
|
+
it {expect((@q.remainder @r)).to eq 0.25}
|
78
|
+
it {expect(@q.to_base_unit.value).to eq 1250}
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
|
83
83
|
context "Dimensionless" do
|
84
84
|
describe Q[1] do
|
85
|
-
it {
|
86
|
-
its(:value) {
|
87
|
-
its(:unit) {
|
88
|
-
its(:unit) {
|
85
|
+
it {is_expected.to be_an_instance_of Phys::Quantity}
|
86
|
+
its(:value) {is_expected.to eq 1}
|
87
|
+
its(:unit) {is_expected.to be_an_instance_of Phys::Unit}
|
88
|
+
its(:unit) {is_expected.to eq U[1]}
|
89
89
|
end
|
90
90
|
describe Q[1,""] do
|
91
|
-
it {
|
92
|
-
its(:value) {
|
93
|
-
its(:unit) {
|
94
|
-
its(:unit) {
|
91
|
+
it {is_expected.to be_an_instance_of Phys::Quantity}
|
92
|
+
its(:value) {is_expected.to eq 1}
|
93
|
+
its(:unit) {is_expected.to be_an_instance_of Phys::Unit}
|
94
|
+
its(:unit) {is_expected.to eq U['']}
|
95
95
|
end
|
96
96
|
describe Q[1,""] do
|
97
97
|
before {@q=Q[1,""]}
|
98
|
-
it {@q.want(2).value.
|
98
|
+
it {expect(@q.want(2).value).to eq 0.5}
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
context "Length" do
|
103
103
|
describe Q[1,"km"] do
|
104
104
|
before { @q = Q[1,"km"] }
|
105
|
-
it {@q.want("m").value.
|
106
|
-
it {@q.want("cm").value.
|
105
|
+
it {expect(@q.want("m").value).to eq 1000}
|
106
|
+
it {expect(@q.want("cm").value).to eq 100000}
|
107
107
|
end
|
108
108
|
describe Q[1,"au"] do
|
109
|
-
it {
|
109
|
+
it {is_expected.to eq Q[149597870700,"m"]}
|
110
110
|
end
|
111
111
|
describe Q[1,"parsec"] do
|
112
|
-
it {
|
112
|
+
it {is_expected.to eq Q[3.0856775814671916e+16,"m"]}
|
113
113
|
end
|
114
114
|
describe Q[1,"lightyear"] do
|
115
|
-
it {
|
115
|
+
it {is_expected.to eq Q[9460730472580800,"m"]}
|
116
116
|
end
|
117
117
|
describe Q[1,"lightyear"].want(:m).value do
|
118
|
-
it {
|
118
|
+
it {is_expected.to eq 9460730472580800}
|
119
119
|
end
|
120
120
|
describe Q[1,"inch"] do
|
121
|
-
it {
|
121
|
+
it {is_expected.to eq Q[0.0254,"m"]}
|
122
122
|
end
|
123
123
|
describe Q[1,"feet"] do
|
124
|
-
it {
|
124
|
+
it {is_expected.to eq Q[0.3048,"m"]}
|
125
125
|
end
|
126
126
|
describe Q[1,"mile"] do
|
127
|
-
it {
|
127
|
+
it {is_expected.to eq Q[1609.344,"m"]}
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
131
|
context "Temperature" do
|
132
132
|
describe Q[1,"tempC"] - Q[1,"degC"] do
|
133
|
-
it {
|
133
|
+
it {is_expected.to eq Q[0,"tempC"]}
|
134
134
|
end
|
135
135
|
describe Q[50,"tempF"] + Q[10,"degC"] do
|
136
|
-
it {
|
136
|
+
it {is_expected.to eq Q[68,"tempF"]}
|
137
137
|
end
|
138
138
|
describe Q[0,"tempC"].want("tempF") do
|
139
|
-
its(:value) {
|
139
|
+
its(:value) {is_expected.to eq 32}
|
140
140
|
end
|
141
141
|
describe Q[32,"tempF"].want("tempC") do
|
142
|
-
its(:value){
|
142
|
+
its(:value){is_expected.to eq 0}
|
143
143
|
end
|
144
144
|
describe 2 * Q[2,"tempF"] do
|
145
|
-
it {
|
145
|
+
it {is_expected.to eq Q[4,"tempF"]}
|
146
146
|
end
|
147
147
|
describe Q[2.5,"tempC"] * 4 do
|
148
|
-
its(:value){
|
148
|
+
its(:value){is_expected.to eq 10}
|
149
149
|
end
|
150
150
|
describe Q[10.0,"tempC"] / 4 do
|
151
|
-
its(:value){
|
151
|
+
its(:value){is_expected.to eq 2.5}
|
152
152
|
end
|
153
153
|
describe "tempC*tempC" do
|
154
154
|
it {expect{Q[1,"tempC"]*Q[2,"tempC"]}.to raise_error}
|
@@ -169,25 +169,25 @@ describe "Phys::Quantity" do
|
|
169
169
|
|
170
170
|
context "Velocity" do
|
171
171
|
describe Q[36,"km/hour"] do
|
172
|
-
its(:to_base_unit){
|
172
|
+
its(:to_base_unit){is_expected.to eq Q[10,"m/s"]}
|
173
173
|
end
|
174
174
|
describe Q[36,"km/hour"].want('m/s') do
|
175
|
-
its(:value){
|
175
|
+
its(:value){is_expected.to eq 10}
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
context "Radian" do
|
180
180
|
describe Q[1,"radian"].want("degree") do
|
181
|
-
its(:value){
|
181
|
+
its(:value){is_expected.to be_within(1e-15).of Q[180,"1/pi"].to_f}
|
182
182
|
end
|
183
183
|
describe Math.sin(Q[30,"degree"].to_f) do
|
184
|
-
it{
|
184
|
+
it{is_expected.to be_within(1e-15).of 0.5 }
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
188
|
context "Complex units" do
|
189
189
|
describe Q[1,"(8/pi^2)(lbm/ft^3)ft(ft^3/s)^2(1/in^5)"] do
|
190
|
-
it{
|
190
|
+
it{is_expected.to be_a_quantity_close_to Q[43.533969,"psi"]}
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|