dr_light 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/config/check_specs.yml +3 -1
- data/config/yardstick.yml +10 -2
- data/lib/dr_light.rb +2 -1
- data/lib/dr_light/scientific_number.rb +42 -5
- data/lib/dr_light/scientific_number/formatter.rb +35 -47
- data/lib/dr_light/scientific_number/normalizer.rb +146 -0
- data/lib/dr_light/utils.rb +41 -0
- data/lib/dr_light/version.rb +1 -1
- data/spec/integration/yard/dr_light/scientific_number_spec.rb +18 -0
- data/spec/integration/yard/dr_light/utils_spec.rb +31 -0
- data/spec/lib/dr_light/scientific_number/formatter_spec.rb +479 -0
- data/spec/lib/dr_light/scientific_number/normalizer_spec.rb +377 -0
- data/spec/lib/dr_light/utils_spec.rb +95 -0
- metadata +9 -2
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe DrLight::Utils do
|
4
|
+
describe '.order' do
|
5
|
+
describe 'yard' do
|
6
|
+
it 'returns order 1 for -100' do
|
7
|
+
expect(described_class.order(-100)).to eq(2)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns order -2 for 0.01' do
|
11
|
+
expect(described_class.order(0.01)).to eq(-2)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns order 0 for 0' do
|
15
|
+
expect(described_class.order(0)).to eq(0)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.order_difference' do
|
21
|
+
describe 'yard' do
|
22
|
+
subject(:difference) do
|
23
|
+
described_class.order_difference(-10, 0.1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns order difference between numbers' do
|
27
|
+
expect(difference).to eq(2)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,479 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DrLight::ScientificNumber::Formatter do
|
6
|
+
subject(:formatter) { described_class.new(normalizer) }
|
7
|
+
|
8
|
+
let(:normalizer) do
|
9
|
+
DrLight::ScientificNumber::Normalizer.new(value: value, deviance: deviance)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#format_string' do
|
13
|
+
context 'when there is no deviance' do
|
14
|
+
let(:deviance) { 0 }
|
15
|
+
|
16
|
+
context 'when negative number only has 2 digits and order 10' do
|
17
|
+
let(:value) { -12 }
|
18
|
+
|
19
|
+
it 'shows 2 digits' do
|
20
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when negative number has 3 digits and order 10^2' do
|
25
|
+
let(:value) { -123 }
|
26
|
+
|
27
|
+
it 'shows 2 digits' do
|
28
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when negative number only has 2 digits and order 1' do
|
33
|
+
let(:value) { -1.2 }
|
34
|
+
|
35
|
+
it 'shows 2 digits' do
|
36
|
+
expect(formatter.format_string).to eq('%<value>.1f')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when negative number has 3 digits and order 1' do
|
41
|
+
let(:value) { -1.23 }
|
42
|
+
|
43
|
+
it 'shows 2 digits' do
|
44
|
+
expect(formatter.format_string).to eq('%<value>.1f')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when negative number only has 2 digits and order 10^-1' do
|
49
|
+
let(:value) { -0.12 }
|
50
|
+
|
51
|
+
it 'shows 2 digits' do
|
52
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when negative number has 3 digits and order 10^-1' do
|
57
|
+
let(:value) { -0.123 }
|
58
|
+
|
59
|
+
it 'shows 2 digits' do
|
60
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when positive number only has 2 digits and order 10' do
|
65
|
+
let(:value) { 12 }
|
66
|
+
|
67
|
+
it 'shows 2 digits' do
|
68
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when positive number has 3 digits and order 10^2' do
|
73
|
+
let(:value) { 123 }
|
74
|
+
|
75
|
+
it 'shows 2 digits' do
|
76
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when positive number only has 2 digits and order 1' do
|
81
|
+
let(:value) { 1.2 }
|
82
|
+
|
83
|
+
it 'shows 2 digits' do
|
84
|
+
expect(formatter.format_string).to eq('%<value>.1f')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when positive number has 3 digits and order 1' do
|
89
|
+
let(:value) { 1.23 }
|
90
|
+
|
91
|
+
it 'shows 2 digits' do
|
92
|
+
expect(formatter.format_string).to eq('%<value>.1f')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when positive number only has 2 digits and order 10^-1' do
|
97
|
+
let(:value) { 0.12 }
|
98
|
+
|
99
|
+
it 'shows 2 digits' do
|
100
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when positive number has 3 digits and order 10^-1' do
|
105
|
+
let(:value) { 0.123 }
|
106
|
+
|
107
|
+
it 'shows 2 digits' do
|
108
|
+
expect(formatter.format_string).to eq('%<value>.1fe%<exponential>d')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when deviance has the same order as the value' do
|
114
|
+
context 'when negative number only has 2 digits and order 10' do
|
115
|
+
let(:value) { -12 }
|
116
|
+
let(:deviance) { 13 }
|
117
|
+
|
118
|
+
it 'shows 2 digits' do
|
119
|
+
expect(formatter.format_string)
|
120
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when negative number has 3 digits and order 10^2' do
|
125
|
+
let(:value) { -123 }
|
126
|
+
let(:deviance) { 134 }
|
127
|
+
|
128
|
+
it 'shows 2 digits' do
|
129
|
+
expect(formatter.format_string)
|
130
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when negative number only has 2 digits and order 1' do
|
135
|
+
let(:value) { -1.2 }
|
136
|
+
let(:deviance) { 1.3 }
|
137
|
+
|
138
|
+
it 'shows 2 digits' do
|
139
|
+
expect(formatter.format_string)
|
140
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'when negative number has 3 digits and order 1' do
|
145
|
+
let(:value) { -1.23 }
|
146
|
+
let(:deviance) { 1.34 }
|
147
|
+
|
148
|
+
it 'shows 2 digits' do
|
149
|
+
expect(formatter.format_string)
|
150
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'when negative number only has 2 digits and order 10^-1' do
|
155
|
+
let(:value) { -0.12 }
|
156
|
+
let(:deviance) { 0.13 }
|
157
|
+
|
158
|
+
it 'shows 2 digits' do
|
159
|
+
expect(formatter.format_string)
|
160
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when negative number has 3 digits and order 10^-1' do
|
165
|
+
let(:value) { -0.123 }
|
166
|
+
let(:deviance) { 0.134 }
|
167
|
+
|
168
|
+
it 'shows 2 digits' do
|
169
|
+
expect(formatter.format_string)
|
170
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when positive number only has 2 digits and order 10' do
|
175
|
+
let(:value) { 12 }
|
176
|
+
let(:deviance) { 13 }
|
177
|
+
|
178
|
+
it 'shows 2 digits' do
|
179
|
+
expect(formatter.format_string)
|
180
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when positive number has 3 digits and order 10^2' do
|
185
|
+
let(:value) { 123 }
|
186
|
+
let(:deviance) { 134 }
|
187
|
+
|
188
|
+
it 'shows 2 digits' do
|
189
|
+
expect(formatter.format_string)
|
190
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when positive number only has 2 digits and order 1' do
|
195
|
+
let(:value) { 1.2 }
|
196
|
+
let(:deviance) { 1.3 }
|
197
|
+
|
198
|
+
it 'shows 2 digits' do
|
199
|
+
expect(formatter.format_string)
|
200
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'when positive number has 3 digits and order 1' do
|
205
|
+
let(:value) { 1.23 }
|
206
|
+
let(:deviance) { 1.34 }
|
207
|
+
|
208
|
+
it 'shows 2 digits' do
|
209
|
+
expect(formatter.format_string)
|
210
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'when positive number only has 2 digits and order 10^-1' do
|
215
|
+
let(:value) { 0.12 }
|
216
|
+
let(:deviance) { 0.13 }
|
217
|
+
|
218
|
+
it 'shows 2 digits' do
|
219
|
+
expect(formatter.format_string)
|
220
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'when positive number has 3 digits and order 10^-1' do
|
225
|
+
let(:value) { 0.123 }
|
226
|
+
let(:deviance) { 0.134 }
|
227
|
+
|
228
|
+
it 'shows 2 digits' do
|
229
|
+
expect(formatter.format_string)
|
230
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'when deviance has smaller order than the value' do
|
236
|
+
context 'when negative number only has 2 digits and order 10' do
|
237
|
+
let(:value) { -12 }
|
238
|
+
let(:deviance) { 0.13 }
|
239
|
+
|
240
|
+
it 'shows 2 deviance digits' do
|
241
|
+
expect(formatter.format_string)
|
242
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when negative number has 3 digits and order 10^2' do
|
247
|
+
let(:value) { -123 }
|
248
|
+
let(:deviance) { 1.34 }
|
249
|
+
|
250
|
+
it 'shows 2 deviance digits' do
|
251
|
+
expect(formatter.format_string)
|
252
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'when negative number only has 2 digits and order 1' do
|
257
|
+
let(:value) { -1.2 }
|
258
|
+
let(:deviance) { 0.013 }
|
259
|
+
|
260
|
+
it 'shows 2 deviance digits' do
|
261
|
+
expect(formatter.format_string)
|
262
|
+
.to eq('%<value>.3f(%<deviance>d)')
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'when negative number has 3 digits and order 1' do
|
267
|
+
let(:value) { -1.23 }
|
268
|
+
let(:deviance) { 0.0134 }
|
269
|
+
|
270
|
+
it 'shows 2 deviance digits' do
|
271
|
+
expect(formatter.format_string)
|
272
|
+
.to eq('%<value>.3f(%<deviance>d)')
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'when negative number only has 2 digits and order 10^-1' do
|
277
|
+
let(:value) { -0.12 }
|
278
|
+
let(:deviance) { 0.0013 }
|
279
|
+
|
280
|
+
it 'shows 2 deviance digits' do
|
281
|
+
expect(formatter.format_string)
|
282
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
context 'when negative number has 3 digits and order 10^-1' do
|
287
|
+
let(:value) { -0.123 }
|
288
|
+
let(:deviance) { 0.00134 }
|
289
|
+
|
290
|
+
it 'shows 2 deviance digits' do
|
291
|
+
expect(formatter.format_string)
|
292
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'when positive number only has 2 digits and order 10' do
|
297
|
+
let(:value) { 12 }
|
298
|
+
let(:deviance) { 0.13 }
|
299
|
+
|
300
|
+
it 'shows 2 deviance digits' do
|
301
|
+
expect(formatter.format_string)
|
302
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'when positive number has 3 digits and order 10^2' do
|
307
|
+
let(:value) { 123 }
|
308
|
+
let(:deviance) { 1.34 }
|
309
|
+
|
310
|
+
it 'shows 2 deviance digits' do
|
311
|
+
expect(formatter.format_string)
|
312
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context 'when positive number only has 2 digits and order 1' do
|
317
|
+
let(:value) { 1.2 }
|
318
|
+
let(:deviance) { 0.013 }
|
319
|
+
|
320
|
+
it 'shows 2 deviance digits' do
|
321
|
+
expect(formatter.format_string)
|
322
|
+
.to eq('%<value>.3f(%<deviance>d)')
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context 'when positive number has 3 digits and order 1' do
|
327
|
+
let(:value) { 1.23 }
|
328
|
+
let(:deviance) { 0.0134 }
|
329
|
+
|
330
|
+
it 'shows 2 deviance digits' do
|
331
|
+
expect(formatter.format_string)
|
332
|
+
.to eq('%<value>.3f(%<deviance>d)')
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
context 'when positive number only has 2 digits and order 10^-1' do
|
337
|
+
let(:value) { 0.12 }
|
338
|
+
let(:deviance) { 0.0013 }
|
339
|
+
|
340
|
+
it 'shows 2 deviance digits' do
|
341
|
+
expect(formatter.format_string)
|
342
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context 'when positive number has 3 digits and order 10^-1' do
|
347
|
+
let(:value) { 0.123 }
|
348
|
+
let(:deviance) { 0.00134 }
|
349
|
+
|
350
|
+
it 'shows 2 deviance digits' do
|
351
|
+
expect(formatter.format_string)
|
352
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
context 'when deviance has bigger order than the value' do
|
358
|
+
context 'when negative number only has 2 digits and order 10' do
|
359
|
+
let(:value) { -12 }
|
360
|
+
let(:deviance) { 130 }
|
361
|
+
|
362
|
+
it 'shows 2 deviance digits' do
|
363
|
+
expect(formatter.format_string)
|
364
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context 'when negative number has 3 digits and order 10^2' do
|
369
|
+
let(:value) { -123 }
|
370
|
+
let(:deviance) { 1340 }
|
371
|
+
|
372
|
+
it 'shows 2 deviance digits' do
|
373
|
+
expect(formatter.format_string)
|
374
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
context 'when negative number only has 2 digits and order 1' do
|
379
|
+
let(:value) { -1.2 }
|
380
|
+
let(:deviance) { 13 }
|
381
|
+
|
382
|
+
it 'shows 2 deviance digits' do
|
383
|
+
expect(formatter.format_string)
|
384
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
context 'when negative number has 3 digits and order 1' do
|
389
|
+
let(:value) { -1.23 }
|
390
|
+
let(:deviance) { 13.4 }
|
391
|
+
|
392
|
+
it 'shows 2 deviance digits' do
|
393
|
+
expect(formatter.format_string)
|
394
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context 'when negative number only has 2 digits and order 10^-1' do
|
399
|
+
let(:value) { -0.12 }
|
400
|
+
let(:deviance) { 1.3 }
|
401
|
+
|
402
|
+
it 'shows 2 deviance digits' do
|
403
|
+
expect(formatter.format_string)
|
404
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
context 'when negative number has 3 digits and order 10^-1' do
|
409
|
+
let(:value) { -0.123 }
|
410
|
+
let(:deviance) { 1.34 }
|
411
|
+
|
412
|
+
it 'shows 2 deviance digits' do
|
413
|
+
expect(formatter.format_string)
|
414
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
context 'when positive number only has 2 digits and order 10' do
|
419
|
+
let(:value) { 12 }
|
420
|
+
let(:deviance) { 0.13 }
|
421
|
+
|
422
|
+
it 'shows 2 deviance digits' do
|
423
|
+
expect(formatter.format_string)
|
424
|
+
.to eq('%<value>.3f(%<deviance>d)e%<exponential>d')
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
context 'when positive number has 3 digits and order 10^2' do
|
429
|
+
let(:value) { 123 }
|
430
|
+
let(:deviance) { 1340 }
|
431
|
+
|
432
|
+
it 'shows 2 deviance digits' do
|
433
|
+
expect(formatter.format_string)
|
434
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
context 'when positive number only has 2 digits and order 1' do
|
439
|
+
let(:value) { 1.2 }
|
440
|
+
let(:deviance) { 13 }
|
441
|
+
|
442
|
+
it 'shows 2 deviance digits' do
|
443
|
+
expect(formatter.format_string)
|
444
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'when positive number has 3 digits and order 1' do
|
449
|
+
let(:value) { 1.23 }
|
450
|
+
let(:deviance) { 13.4 }
|
451
|
+
|
452
|
+
it 'shows 2 deviance digits' do
|
453
|
+
expect(formatter.format_string)
|
454
|
+
.to eq('%<value>.1f(%<deviance>d)e%<exponential>d')
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
context 'when positive number only has 2 digits and order 10^-1' do
|
459
|
+
let(:value) { 0.12 }
|
460
|
+
let(:deviance) { 1.3 }
|
461
|
+
|
462
|
+
it 'shows 2 deviance digits' do
|
463
|
+
expect(formatter.format_string)
|
464
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context 'when positive number has 3 digits and order 10^-1' do
|
469
|
+
let(:value) { 0.123 }
|
470
|
+
let(:deviance) { 1.34 }
|
471
|
+
|
472
|
+
it 'shows 2 deviance digits' do
|
473
|
+
expect(formatter.format_string)
|
474
|
+
.to eq('%<value>.1f(%<deviance>d)')
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|