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.
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
@@ -5,252 +5,252 @@ require "helper"
5
5
 
6
6
  describe "Japanese Units" do
7
7
  describe Q[1,"一"] do
8
- it {should be_a_quantity_close_to Q[1] }
8
+ it {is_expected.to be_a_quantity_close_to Q[1] }
9
9
  end
10
10
  describe Q[1,"二"] do
11
- it {should be_a_quantity_close_to Q[2] }
11
+ it {is_expected.to be_a_quantity_close_to Q[2] }
12
12
  end
13
13
  describe Q[1,"三"] do
14
- it {should be_a_quantity_close_to Q[3] }
14
+ it {is_expected.to be_a_quantity_close_to Q[3] }
15
15
  end
16
16
  describe Q[1,"四"] do
17
- it {should be_a_quantity_close_to Q[4] }
17
+ it {is_expected.to be_a_quantity_close_to Q[4] }
18
18
  end
19
19
  describe Q[1,"五"] do
20
- it {should be_a_quantity_close_to Q[5] }
20
+ it {is_expected.to be_a_quantity_close_to Q[5] }
21
21
  end
22
22
  describe Q[1,"六"] do
23
- it {should be_a_quantity_close_to Q[6] }
23
+ it {is_expected.to be_a_quantity_close_to Q[6] }
24
24
  end
25
25
  describe Q[1,"七"] do
26
- it {should be_a_quantity_close_to Q[7] }
26
+ it {is_expected.to be_a_quantity_close_to Q[7] }
27
27
  end
28
28
  describe Q[1,"八"] do
29
- it {should be_a_quantity_close_to Q[8] }
29
+ it {is_expected.to be_a_quantity_close_to Q[8] }
30
30
  end
31
31
  describe Q[1,"九"] do
32
- it {should be_a_quantity_close_to Q[9] }
32
+ it {is_expected.to be_a_quantity_close_to Q[9] }
33
33
  end
34
34
  describe Q[1,"十"] do
35
- it {should be_a_quantity_close_to Q[10] }
35
+ it {is_expected.to be_a_quantity_close_to Q[10] }
36
36
  end
37
37
  describe Q[1,"百"] do
38
- it {should be_a_quantity_close_to Q[100] }
38
+ it {is_expected.to be_a_quantity_close_to Q[100] }
39
39
  end
40
40
  describe Q[1,"千"] do
41
- it {should be_a_quantity_close_to Q[1000] }
41
+ it {is_expected.to be_a_quantity_close_to Q[1000] }
42
42
  end
43
43
  describe Q[1,"万"] do
44
- it {should be_a_quantity_close_to Q[10000] }
44
+ it {is_expected.to be_a_quantity_close_to Q[10000] }
45
45
  end
46
46
  describe Q[1,"億"] do
47
- it {should be_a_quantity_close_to Q[100000000] }
47
+ it {is_expected.to be_a_quantity_close_to Q[100000000] }
48
48
  end
49
49
  describe Q[1,"兆"] do
50
- it {should be_a_quantity_close_to Q[1e+12] }
50
+ it {is_expected.to be_a_quantity_close_to Q[1e+12] }
51
51
  end
52
52
  describe Q[1,"京"] do
53
- it {should be_a_quantity_close_to Q[1e+16] }
53
+ it {is_expected.to be_a_quantity_close_to Q[1e+16] }
54
54
  end
55
55
  describe Q[1,"垓"] do
56
- it {should be_a_quantity_close_to Q[1e+20] }
56
+ it {is_expected.to be_a_quantity_close_to Q[1e+20] }
57
57
  end
58
58
  describe Q[1,"秭"] do
59
- it {should be_a_quantity_close_to Q[1e+24] }
59
+ it {is_expected.to be_a_quantity_close_to Q[1e+24] }
60
60
  end
61
61
  describe Q[1,"秭"] do
62
- it {should be_a_quantity_close_to Q[1e+24] }
62
+ it {is_expected.to be_a_quantity_close_to Q[1e+24] }
63
63
  end
64
64
  describe Q[1,"穰"] do
65
- it {should be_a_quantity_close_to Q[1e+28] }
65
+ it {is_expected.to be_a_quantity_close_to Q[1e+28] }
66
66
  end
67
67
  describe Q[1,"溝"] do
68
- it {should be_a_quantity_close_to Q[1e+32] }
68
+ it {is_expected.to be_a_quantity_close_to Q[1e+32] }
69
69
  end
70
70
  describe Q[1,"澗"] do
71
- it {should be_a_quantity_close_to Q[1e+36] }
71
+ it {is_expected.to be_a_quantity_close_to Q[1e+36] }
72
72
  end
73
73
  describe Q[1,"正"] do
74
- it {should be_a_quantity_close_to Q[1e+40] }
74
+ it {is_expected.to be_a_quantity_close_to Q[1e+40] }
75
75
  end
76
76
  describe Q[1,"載"] do
77
- it {should be_a_quantity_close_to Q[1e+44] }
77
+ it {is_expected.to be_a_quantity_close_to Q[1e+44] }
78
78
  end
79
79
  describe Q[1,"極"] do
80
- it {should be_a_quantity_close_to Q[1e+48] }
80
+ it {is_expected.to be_a_quantity_close_to Q[1e+48] }
81
81
  end
82
82
  describe Q[1,"恒河沙"] do
83
- it {should be_a_quantity_close_to Q[1e+52] }
83
+ it {is_expected.to be_a_quantity_close_to Q[1e+52] }
84
84
  end
85
85
  describe Q[1,"阿僧祇"] do
86
- it {should be_a_quantity_close_to Q[1e+56] }
86
+ it {is_expected.to be_a_quantity_close_to Q[1e+56] }
87
87
  end
88
88
  describe Q[1,"那由他"] do
89
- it {should be_a_quantity_close_to Q[1e+60] }
89
+ it {is_expected.to be_a_quantity_close_to Q[1e+60] }
90
90
  end
91
91
  describe Q[1,"不可思議"] do
92
- it {should be_a_quantity_close_to Q[1e+64] }
92
+ it {is_expected.to be_a_quantity_close_to Q[1e+64] }
93
93
  end
94
94
  describe Q[1,"無量大数"] do
95
- it {should be_a_quantity_close_to Q[1e+68] }
95
+ it {is_expected.to be_a_quantity_close_to Q[1e+68] }
96
96
  end
97
97
  describe Q[1,"割"] do
98
- it {should be_a_quantity_close_to Q[0.1] }
98
+ it {is_expected.to be_a_quantity_close_to Q[0.1] }
99
99
  end
100
100
  describe Q[1,"分"] do
101
- it {should be_a_quantity_close_to Q[0.01] }
101
+ it {is_expected.to be_a_quantity_close_to Q[0.01] }
102
102
  end
103
103
  describe Q[1,"厘"] do
104
- it {should be_a_quantity_close_to Q[0.001] }
104
+ it {is_expected.to be_a_quantity_close_to Q[0.001] }
105
105
  end
106
106
  describe Q[1,"釐"] do
107
- it {should be_a_quantity_close_to Q[0.001] }
107
+ it {is_expected.to be_a_quantity_close_to Q[0.001] }
108
108
  end
109
109
  describe Q[1,"毛"] do
110
- it {should be_a_quantity_close_to Q[0.0001] }
110
+ it {is_expected.to be_a_quantity_close_to Q[0.0001] }
111
111
  end
112
112
  describe Q[1,"毫"] do
113
- it {should be_a_quantity_close_to Q[0.0001] }
113
+ it {is_expected.to be_a_quantity_close_to Q[0.0001] }
114
114
  end
115
115
  describe Q[1,"糸"] do
116
- it {should be_a_quantity_close_to Q[0.0001] }
116
+ it {is_expected.to be_a_quantity_close_to Q[0.0001] }
117
117
  end
118
118
  describe Q[1,"絲"] do
119
- it {should be_a_quantity_close_to Q[0.0001] }
119
+ it {is_expected.to be_a_quantity_close_to Q[0.0001] }
120
120
  end
121
121
  describe Q[1,"忽"] do
122
- it {should be_a_quantity_close_to Q[1e-05] }
122
+ it {is_expected.to be_a_quantity_close_to Q[1e-05] }
123
123
  end
124
124
  describe Q[1,"微"] do
125
- it {should be_a_quantity_close_to Q[1e-06] }
125
+ it {is_expected.to be_a_quantity_close_to Q[1e-06] }
126
126
  end
127
127
  describe Q[1,"繊"] do
128
- it {should be_a_quantity_close_to Q[1e-07] }
128
+ it {is_expected.to be_a_quantity_close_to Q[1e-07] }
129
129
  end
130
130
  describe Q[1,"沙"] do
131
- it {should be_a_quantity_close_to Q[1e-08] }
131
+ it {is_expected.to be_a_quantity_close_to Q[1e-08] }
132
132
  end
133
133
  describe Q[1,"塵"] do
134
- it {should be_a_quantity_close_to Q[1e-09] }
134
+ it {is_expected.to be_a_quantity_close_to Q[1e-09] }
135
135
  end
136
136
  describe Q[1,"埃"] do
137
- it {should be_a_quantity_close_to Q[1e-10] }
137
+ it {is_expected.to be_a_quantity_close_to Q[1e-10] }
138
138
  end
139
139
  describe Q[1,"渺"] do
140
- it {should be_a_quantity_close_to Q[1e-11] }
140
+ it {is_expected.to be_a_quantity_close_to Q[1e-11] }
141
141
  end
142
142
  describe Q[1,"漠"] do
143
- it {should be_a_quantity_close_to Q[1e-12] }
143
+ it {is_expected.to be_a_quantity_close_to Q[1e-12] }
144
144
  end
145
145
  describe Q[1,"模糊"] do
146
- it {should be_a_quantity_close_to Q[1e-13] }
146
+ it {is_expected.to be_a_quantity_close_to Q[1e-13] }
147
147
  end
148
148
  describe Q[1,"逡巡"] do
149
- it {should be_a_quantity_close_to Q[1e-14] }
149
+ it {is_expected.to be_a_quantity_close_to Q[1e-14] }
150
150
  end
151
151
  describe Q[1,"須臾"] do
152
- it {should be_a_quantity_close_to Q[1e-15] }
152
+ it {is_expected.to be_a_quantity_close_to Q[1e-15] }
153
153
  end
154
154
  describe Q[1,"瞬息"] do
155
- it {should be_a_quantity_close_to Q[1e-16] }
155
+ it {is_expected.to be_a_quantity_close_to Q[1e-16] }
156
156
  end
157
157
  describe Q[1,"弾指"] do
158
- it {should be_a_quantity_close_to Q[1e-17] }
158
+ it {is_expected.to be_a_quantity_close_to Q[1e-17] }
159
159
  end
160
160
  describe Q[1,"刹那"] do
161
- it {should be_a_quantity_close_to Q[1e-18] }
161
+ it {is_expected.to be_a_quantity_close_to Q[1e-18] }
162
162
  end
163
163
  describe Q[1,"六徳"] do
164
- it {should be_a_quantity_close_to Q[1e-19] }
164
+ it {is_expected.to be_a_quantity_close_to Q[1e-19] }
165
165
  end
166
166
  describe Q[1,"虚空"] do
167
- it {should be_a_quantity_close_to Q[1e-20] }
167
+ it {is_expected.to be_a_quantity_close_to Q[1e-20] }
168
168
  end
169
169
  describe Q[1,"清浄"] do
170
- it {should be_a_quantity_close_to Q[1e-21] }
170
+ it {is_expected.to be_a_quantity_close_to Q[1e-21] }
171
171
  end
172
172
  describe Q[1,"阿頼耶"] do
173
- it {should be_a_quantity_close_to Q[1e-22] }
173
+ it {is_expected.to be_a_quantity_close_to Q[1e-22] }
174
174
  end
175
175
  describe Q[1,"阿摩羅"] do
176
- it {should be_a_quantity_close_to Q[1e-23] }
176
+ it {is_expected.to be_a_quantity_close_to Q[1e-23] }
177
177
  end
178
178
  describe Q[1,"涅槃寂静"] do
179
- it {should be_a_quantity_close_to Q[1e-24] }
179
+ it {is_expected.to be_a_quantity_close_to Q[1e-24] }
180
180
  end
181
181
  describe Q[1,"尺"] do
182
- it {should be_a_quantity_close_to Q[0.303030303,"m"] }
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 {should be_a_quantity_close_to Q[0.0303030303,"m"] }
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 {should be_a_quantity_close_to Q[3927.27273,"m"] }
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 {should be_a_quantity_close_to Q[109.090909,"m"] }
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 {should be_a_quantity_close_to Q[1.81818182,"m"] }
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 {should be_a_quantity_close_to Q[3.03030303,"m"] }
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 {should be_a_quantity_close_to Q[0.303030303,"m"] }
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 {should be_a_quantity_close_to Q[0.378787879,"m"] }
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 {should be_a_quantity_close_to Q[3.30578512,"m^2"] }
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 {should be_a_quantity_close_to Q[99.1735537,"m^2"] }
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 {should be_a_quantity_close_to Q[991.735537,"m^2"] }
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 {should be_a_quantity_close_to Q[991.735537,"m^2"] }
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 {should be_a_quantity_close_to Q[1.54453627,"m^2"] }
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 {should be_a_quantity_close_to Q[1.82231405,"m^2"] }
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 {should be_a_quantity_close_to Q[1.65289256,"m^2"] }
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 {should be_a_quantity_close_to Q[1.54453627,"m^2"] }
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 {should be_a_quantity_close_to Q[0.00180390684,"m^3"] }
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 {should be_a_quantity_close_to Q[0.0180390684,"m^3"] }
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 {should be_a_quantity_close_to Q[0.180390684,"m^3"] }
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 {should be_a_quantity_close_to Q[0.000180390684,"m^3"] }
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 {should be_a_quantity_close_to Q[1.80390684e-05,"m^3"] }
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 {should be_a_quantity_close_to Q[3.75,"kg"] }
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 {should be_a_quantity_close_to Q[0.6,"kg"] }
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 {should be_a_quantity_close_to Q[0.0375,"kg"] }
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 {should be_a_quantity_close_to Q[0.00375,"kg"] }
254
+ it {is_expected.to be_a_quantity_close_to Q[0.00375,"kg"] }
255
255
  end
256
256
  end
@@ -5,150 +5,150 @@ describe "Phys::Quantity" do
5
5
 
6
6
  context "equality" do
7
7
  describe Q[12] do
8
- it {should == 12}
9
- it {should == Q[12]}
10
- it {should == Q[12,"radian"]}
11
- it {should == Q[1,"dozen"]}
12
- it {should_not == Q[12,"pi"]}
13
- it {should_not == Q[12,"km"]}
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 {should == 12}
17
- it {should == Q[12]}
18
- it {should == Q[12,"radian"]}
19
- it {should == Q[1,"dozen"]}
20
- it {should_not == Q[12,"pi"]}
21
- it {should_not == Q[12,"km"]}
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 {should_not == 12}
25
- it {should_not == Q[12]}
26
- it {should_not == Q[12,"radian"]}
27
- it {should_not == Q[1,"dozen"]}
28
- it {should_not == Q[12,"pi"]}
29
- it {should == Q[12,"km"]}
30
- it {should == Q[1,"dozen km"]}
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 {should == Q[12]}
34
- it {should == Q[12,"radian"]}
35
- it {should == Q[1,"dozen"]}
36
- it {should_not == Q[12,"pi"]}
37
- it {should_not == Q[12,"km"]}
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.should == 1.25}
45
- it {@q.expr.should == "km"}
46
- it {@q.unit.should == Phys::Unit["km"]}
47
- it {@q.want("cm").value.should == 125000}
48
- it {(@q >> "cm").value.should == 125000}
49
- it {(@q >> U["cm"]).value.should == 125000}
50
- it {(@q >> Q[1,"cm"]).value.should == 125000}
51
- it {(@q + @r).should == Q[1.75,"km"]}
52
- it {(@q - @r).should == Q[0.75,"km"]}
53
- it {@q.abs.should == Q[1.25,"km"]}
54
- it {@q.abs2.should == Q[1.5625,"km^2"]}
55
- it {@q.ceil.should == Q[2,"km"]}
56
- it {@q.round.should == Q[1,"km"]}
57
- it {@q.floor.should == Q[1,"km"]}
58
- it {@q.truncate.should == Q[1,"km"]}
59
- it {(+@q).should == Q[1.25,"km"]}
60
- it {(-@q).should == Q[-1.25,"km"]}
61
- it {(@q <=> @r).should == 1}
62
- it {(@q == @r).should be_false}
63
- it {(@q > @r).should be_true}
64
- it {(@q >= @r).should be_true}
65
- it {(@q < @r).should be_false}
66
- it {(@q <= @r).should be_false}
67
- it {(@q **2).should == Q[1.5625,"km^2"]}
68
- it {(@q * @r).should == Q[0.625,"km^2"]}
69
- it {(@q / @r).should == Q[2.5]}
70
- it {(@q.quo @r).should == Q[2.5]}
71
- it {(@q.div @r).should == 2}
72
- it {(@q.div 0.5).should == Q[2,"km"]}
73
- it {(@q % @r).should == 0.25}
74
- it {(@q % 0.5).should == Q[0.25,"km"]}
75
- it {(@q.divmod @r).should == [2,0.25]}
76
- it {(@q.divmod 0.5).should == [Q[2,"km"],Q[0.25,"km"]]}
77
- it {(@q.remainder @r).should == 0.25}
78
- it {@q.to_base_unit.value.should == 1250}
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 {should be_an_instance_of Phys::Quantity}
86
- its(:value) {should == 1}
87
- its(:unit) {should be_an_instance_of Phys::Unit}
88
- its(:unit) {should == U[1]}
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 {should be_an_instance_of Phys::Quantity}
92
- its(:value) {should == 1}
93
- its(:unit) {should be_an_instance_of Phys::Unit}
94
- its(:unit) {should == U['']}
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.should == 0.5}
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.should == 1000}
106
- it {@q.want("cm").value.should == 100000}
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 {should == Q[149597870700,"m"]}
109
+ it {is_expected.to eq Q[149597870700,"m"]}
110
110
  end
111
111
  describe Q[1,"parsec"] do
112
- it {should == Q[3.0856775814671916e+16,"m"]}
112
+ it {is_expected.to eq Q[3.0856775814671916e+16,"m"]}
113
113
  end
114
114
  describe Q[1,"lightyear"] do
115
- it {should == Q[9460730472580800,"m"]}
115
+ it {is_expected.to eq Q[9460730472580800,"m"]}
116
116
  end
117
117
  describe Q[1,"lightyear"].want(:m).value do
118
- it {should == 9460730472580800}
118
+ it {is_expected.to eq 9460730472580800}
119
119
  end
120
120
  describe Q[1,"inch"] do
121
- it {should == Q[0.0254,"m"]}
121
+ it {is_expected.to eq Q[0.0254,"m"]}
122
122
  end
123
123
  describe Q[1,"feet"] do
124
- it {should == Q[0.3048,"m"]}
124
+ it {is_expected.to eq Q[0.3048,"m"]}
125
125
  end
126
126
  describe Q[1,"mile"] do
127
- it {should == Q[1609.344,"m"]}
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 {should == Q[0,"tempC"]}
133
+ it {is_expected.to eq Q[0,"tempC"]}
134
134
  end
135
135
  describe Q[50,"tempF"] + Q[10,"degC"] do
136
- it {should == Q[68,"tempF"]}
136
+ it {is_expected.to eq Q[68,"tempF"]}
137
137
  end
138
138
  describe Q[0,"tempC"].want("tempF") do
139
- its(:value) {should == 32}
139
+ its(:value) {is_expected.to eq 32}
140
140
  end
141
141
  describe Q[32,"tempF"].want("tempC") do
142
- its(:value){should == 0}
142
+ its(:value){is_expected.to eq 0}
143
143
  end
144
144
  describe 2 * Q[2,"tempF"] do
145
- it {should == Q[4,"tempF"]}
145
+ it {is_expected.to eq Q[4,"tempF"]}
146
146
  end
147
147
  describe Q[2.5,"tempC"] * 4 do
148
- its(:value){should == 10}
148
+ its(:value){is_expected.to eq 10}
149
149
  end
150
150
  describe Q[10.0,"tempC"] / 4 do
151
- its(:value){should == 2.5}
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){should == Q[10,"m/s"]}
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){should == 10}
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){should be_within(1e-15).of Q[180,"1/pi"].to_f}
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{should be_within(1e-15).of 0.5 }
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{should be_a_quantity_close_to Q[43.533969,"psi"]}
190
+ it{is_expected.to be_a_quantity_close_to Q[43.533969,"psi"]}
191
191
  end
192
192
  end
193
193