aixm 0.3.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +72 -6
  4. data/README.md +191 -53
  5. data/exe/ckmid +11 -0
  6. data/exe/mkmid +11 -0
  7. data/lib/aixm/association.rb +367 -0
  8. data/lib/aixm/classes.rb +44 -0
  9. data/lib/aixm/component/fato.rb +44 -52
  10. data/lib/aixm/component/frequency.rb +13 -14
  11. data/lib/aixm/component/geometry/arc.rb +2 -2
  12. data/lib/aixm/component/geometry/border.rb +14 -5
  13. data/lib/aixm/component/geometry/circle.rb +8 -2
  14. data/lib/aixm/component/geometry/point.rb +10 -3
  15. data/lib/aixm/component/geometry/rhumb_line.rb +54 -0
  16. data/lib/aixm/component/geometry.rb +38 -38
  17. data/lib/aixm/component/helipad.rb +29 -37
  18. data/lib/aixm/component/layer.rb +28 -19
  19. data/lib/aixm/component/lighting.rb +11 -12
  20. data/lib/aixm/component/runway.rb +46 -53
  21. data/lib/aixm/{feature → component}/service.rb +36 -35
  22. data/lib/aixm/component/surface.rb +3 -3
  23. data/lib/aixm/component/timetable.rb +5 -3
  24. data/lib/aixm/component/{vertical_limits.rb → vertical_limit.rb} +12 -6
  25. data/lib/aixm/config.rb +6 -3
  26. data/lib/aixm/document.rb +31 -49
  27. data/lib/aixm/executables.rb +85 -0
  28. data/lib/aixm/f.rb +28 -0
  29. data/lib/aixm/feature/address.rb +20 -15
  30. data/lib/aixm/feature/airport.rb +113 -129
  31. data/lib/aixm/feature/airspace.rb +54 -23
  32. data/lib/aixm/feature/navigational_aid/designated_point.rb +12 -14
  33. data/lib/aixm/feature/navigational_aid/dme.rb +10 -11
  34. data/lib/aixm/feature/navigational_aid/marker.rb +6 -2
  35. data/lib/aixm/feature/navigational_aid/ndb.rb +6 -2
  36. data/lib/aixm/feature/navigational_aid/tacan.rb +6 -2
  37. data/lib/aixm/feature/navigational_aid/vor.rb +22 -14
  38. data/lib/aixm/feature/navigational_aid.rb +7 -9
  39. data/lib/aixm/feature/obstacle.rb +22 -20
  40. data/lib/aixm/feature/obstacle_group.rb +30 -30
  41. data/lib/aixm/feature/organisation.rb +20 -4
  42. data/lib/aixm/feature/unit.rb +35 -45
  43. data/lib/aixm/feature.rb +13 -3
  44. data/lib/aixm/memoize.rb +89 -0
  45. data/lib/aixm/object.rb +9 -0
  46. data/lib/aixm/payload_hash.rb +114 -0
  47. data/lib/aixm/refinements.rb +34 -50
  48. data/lib/aixm/shortcuts.rb +6 -43
  49. data/lib/aixm/version.rb +1 -1
  50. data/lib/aixm/xy.rb +9 -1
  51. data/lib/aixm.rb +18 -7
  52. data/schemas/ofmx/{0 → 0.1}/OFMX-CSV-Obstacle.json +0 -0
  53. data/schemas/ofmx/{0 → 0.1}/OFMX-CSV.json +0 -0
  54. data/schemas/ofmx/{0 → 0.1}/OFMX-DataTypes.xsd +52 -2
  55. data/schemas/ofmx/{0 → 0.1}/OFMX-Features.xsd +225 -14
  56. data/schemas/ofmx/{0 → 0.1}/OFMX-Snapshot.xsd +0 -5
  57. data.tar.gz.sig +0 -0
  58. metadata +116 -164
  59. metadata.gz.sig +0 -0
  60. data/.gitignore +0 -6
  61. data/.ruby-version +0 -1
  62. data/.travis.yml +0 -8
  63. data/.yardopts +0 -3
  64. data/Guardfile +0 -8
  65. data/aixm.gemspec +0 -35
  66. data/gems.rb +0 -3
  67. data/lib/aixm/component.rb +0 -6
  68. data/rakefile.rb +0 -22
  69. data/spec/factory.rb +0 -559
  70. data/spec/lib/aixm/a_spec.rb +0 -203
  71. data/spec/lib/aixm/component/fato_spec.rb +0 -260
  72. data/spec/lib/aixm/component/frequency_spec.rb +0 -75
  73. data/spec/lib/aixm/component/geometry/arc_spec.rb +0 -75
  74. data/spec/lib/aixm/component/geometry/border_spec.rb +0 -33
  75. data/spec/lib/aixm/component/geometry/circle_spec.rb +0 -70
  76. data/spec/lib/aixm/component/geometry/point_spec.rb +0 -39
  77. data/spec/lib/aixm/component/geometry_spec.rb +0 -321
  78. data/spec/lib/aixm/component/helipad_spec.rb +0 -187
  79. data/spec/lib/aixm/component/layer_spec.rb +0 -137
  80. data/spec/lib/aixm/component/lighting_spec.rb +0 -88
  81. data/spec/lib/aixm/component/runway_spec.rb +0 -472
  82. data/spec/lib/aixm/component/surface_spec.rb +0 -124
  83. data/spec/lib/aixm/component/timetable_spec.rb +0 -49
  84. data/spec/lib/aixm/component/vertical_limits_spec.rb +0 -97
  85. data/spec/lib/aixm/config_spec.rb +0 -41
  86. data/spec/lib/aixm/d_spec.rb +0 -150
  87. data/spec/lib/aixm/document_spec.rb +0 -1875
  88. data/spec/lib/aixm/errors_spec.rb +0 -14
  89. data/spec/lib/aixm/f_spec.rb +0 -85
  90. data/spec/lib/aixm/feature/address_spec.rb +0 -55
  91. data/spec/lib/aixm/feature/airport_spec.rb +0 -770
  92. data/spec/lib/aixm/feature/airspace_spec.rb +0 -390
  93. data/spec/lib/aixm/feature/navigational_aid/designated_point_spec.rb +0 -98
  94. data/spec/lib/aixm/feature/navigational_aid/dme_spec.rb +0 -92
  95. data/spec/lib/aixm/feature/navigational_aid/marker_spec.rb +0 -79
  96. data/spec/lib/aixm/feature/navigational_aid/ndb_spec.rb +0 -89
  97. data/spec/lib/aixm/feature/navigational_aid/tacan_spec.rb +0 -88
  98. data/spec/lib/aixm/feature/navigational_aid/vor_spec.rb +0 -245
  99. data/spec/lib/aixm/feature/navigational_aid_spec.rb +0 -52
  100. data/spec/lib/aixm/feature/obstacle_group_spec.rb +0 -326
  101. data/spec/lib/aixm/feature/obstacle_spec.rb +0 -279
  102. data/spec/lib/aixm/feature/organisation_spec.rb +0 -77
  103. data/spec/lib/aixm/feature/service_spec.rb +0 -59
  104. data/spec/lib/aixm/feature/unit_spec.rb +0 -230
  105. data/spec/lib/aixm/feature_spec.rb +0 -38
  106. data/spec/lib/aixm/p_spec.rb +0 -189
  107. data/spec/lib/aixm/refinements_spec.rb +0 -381
  108. data/spec/lib/aixm/version_spec.rb +0 -7
  109. data/spec/lib/aixm/w_spec.rb +0 -150
  110. data/spec/lib/aixm/xy_spec.rb +0 -180
  111. data/spec/lib/aixm/z_spec.rb +0 -94
  112. data/spec/macros/marking.rb +0 -12
  113. data/spec/macros/organisation.rb +0 -11
  114. data/spec/macros/remarks.rb +0 -12
  115. data/spec/macros/timetable.rb +0 -11
  116. data/spec/macros/xy.rb +0 -11
  117. data/spec/macros/z_qnh.rb +0 -11
  118. data/spec/sounds/failure.mp3 +0 -0
  119. data/spec/sounds/success.mp3 +0 -0
  120. data/spec/spec_helper.rb +0 -55
@@ -1,381 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- using AIXM::Refinements
4
-
5
- describe AIXM::Refinements do
6
-
7
- context Array do
8
- describe :to_digest do
9
- it "must digest single string" do
10
- %w(a).to_digest.must_equal "1f40fc92"
11
- end
12
-
13
- it "must digest double string" do
14
- %w(a b).to_digest.must_equal "3c075e5f"
15
- end
16
-
17
- it "must digest integer" do
18
- [5].to_digest.must_equal "06df0537"
19
- end
20
-
21
- it "must digest nested array" do
22
- [1, [2, 3]].to_digest.must_equal "e9609e81"
23
- end
24
-
25
- it "must digest float" do
26
- [5.0].to_digest.must_equal "78fc651d"
27
- end
28
-
29
- it "must digest boolean" do
30
- [true, false].to_digest.must_equal "79bdc67a"
31
- end
32
-
33
- it "must digest nil" do
34
- [nil].to_digest.must_equal "cf83e135"
35
- end
36
- end
37
-
38
- describe :to_uuid do
39
- it "must digest single string" do
40
- %w(a).to_uuid.must_equal "0cc175b9-c0f1-b6a8-31c3-99e269772661"
41
- end
42
-
43
- it "must digest double string" do
44
- %w(a b).to_uuid.must_equal "d0726241-0206-76b1-4aa6-298ce6a18b21"
45
- end
46
-
47
- it "must digest integer" do
48
- [5].to_uuid.must_equal "e4da3b7f-bbce-2345-d777-2b0674a318d5"
49
- end
50
-
51
- it "must digest nested array" do
52
- [1, [2, 3]].to_uuid.must_equal "02b12e93-0c8b-cc7e-92e7-4ff5d96ce118"
53
- end
54
-
55
- it "must digest float" do
56
- [5.0].to_uuid.must_equal "336669db-e720-233e-d557-7ddf81b653d3"
57
- end
58
-
59
- it "must digest boolean" do
60
- [true, false].to_uuid.must_equal "215c2d45-b491-f5c8-15ac-e782ce450fdf"
61
- end
62
-
63
- it "must digest nil" do
64
- [nil].to_uuid.must_equal "d41d8cd9-8f00-b204-e980-0998ecf8427e"
65
- end
66
- end
67
- end
68
-
69
- context Float do
70
- describe :to_dms do
71
- it "must convert +1. DD to DMS" do
72
- 1.37595556.to_dms.must_equal %q(001°22'33.44")
73
- end
74
-
75
- it "must convert -1. DD to DMS" do
76
- -1.37595556.to_dms.must_equal %q(-001°22'33.44")
77
- end
78
-
79
- it "must convert +2. DD to DMS" do
80
- 11.37595556.to_dms.must_equal %q(011°22'33.44")
81
- end
82
-
83
- it "must convert -2. DD to DMS" do
84
- -11.37595556.to_dms.must_equal %q(-011°22'33.44")
85
- end
86
-
87
- it "must convert +3. DD to DMS" do
88
- 111.37595556.to_dms.must_equal %q(111°22'33.44")
89
- end
90
-
91
- it "must convert -3. DD to DMS" do
92
- -111.37595556.to_dms.must_equal %q(-111°22'33.44")
93
- end
94
-
95
- it "must convert DD to DMS with degrees only" do
96
- 11.0.to_dms.must_equal %q(011°00'00.00")
97
- end
98
-
99
- it "must convert DD to DMS with degrees and minutes only" do
100
- 11.36666667.to_dms.must_equal %q(011°22'00.00")
101
- end
102
-
103
- it "must convert DD to DMS with tenth of seconds only" do
104
- 1.37594444.to_dms.must_equal %q(001°22'33.40")
105
- end
106
-
107
- it "must convert DD to DMS with whole seconds only" do
108
- 1.37583333.to_dms.must_equal %q(001°22'33.00")
109
- end
110
-
111
- it "must convert DD to two zero padded DMS" do
112
- 1.37595556.to_dms(2).must_equal %q(01°22'33.44")
113
- end
114
-
115
- it "must convert DD to no zero padded DMS" do
116
- 1.37595556.to_dms(0).must_equal %q(1°22'33.44")
117
- end
118
- end
119
-
120
- describe :to_rad do
121
- it "must convert correctly" do
122
- 0.0.to_rad.must_equal 0
123
- 180.0.to_rad.must_equal Math::PI
124
- -123.0.to_rad.must_equal(-2.1467549799530254)
125
- end
126
- end
127
- end
128
-
129
- context Hash do
130
- describe :lookup do
131
- subject do
132
- { one: 1, two: 2, three: 3, four: :three }
133
- end
134
-
135
- it "must return value for key if key is present" do
136
- subject.lookup(:one).must_equal 1
137
- end
138
-
139
- it "must return value if key is not found but value is present" do
140
- subject.lookup(1).must_equal 1
141
- end
142
-
143
- it "must return value for key if both key and value are present" do
144
- subject.lookup(:three).must_equal 3
145
- end
146
-
147
- it "returns default if neither key nor value are present" do
148
- subject.lookup(:foo, :default).must_equal :default
149
- subject.lookup(:foo, nil).must_be_nil
150
- end
151
-
152
- it "fails if neither key, value nor default are present" do
153
- -> { subject.lookup(:foo) }.must_raise KeyError
154
- end
155
- end
156
- end
157
-
158
- context Object do
159
- describe :then_if do
160
- subject do
161
- "foobar"
162
- end
163
-
164
- it "must return self if the condition is false" do
165
- subject.then_if(false) { |s| s.gsub(/o/, 'i') }.must_equal subject
166
- end
167
-
168
- it "must return apply the block if the condition is true" do
169
- subject.then_if(true) { |s| s.gsub(/o/, 'i') }.must_equal 'fiibar'
170
- end
171
- end
172
- end
173
-
174
- context Regexp do
175
- describe :decapture do
176
- it "should replace capture groups with non-capture groups" do
177
- /(foo) baz (bar)/.decapture.must_equal /(?-mix:(?:foo) baz (?:bar))/
178
- /(foo) baz (bar)/i.decapture.must_equal /(?i-mx:(?:foo) baz (?:bar))/
179
- end
180
-
181
- it "should replace named capture groups with non-capture groups" do
182
- /(?<a>foo) baz (?<b>bar)/.decapture.must_equal /(?-mix:(?:foo) baz (?:bar))/
183
- /(?<a>foo) baz (?<b>bar)/i.decapture.must_equal /(?i-mx:(?:foo) baz (?:bar))/
184
- end
185
-
186
- it "should not replace special groups" do
187
- /(?:foo) (?<=baz) bar/.decapture.must_equal /(?-mix:(?:foo) (?<=baz) bar)/
188
- end
189
-
190
- it "should not replace literal round brackets" do
191
- /\(foo\)/.decapture.must_equal /(?-mix:\(foo\))/
192
- end
193
-
194
- it "should replace literal backslash followed by literal round brackets" do
195
- /\\(foo\\)/.decapture.must_equal /(?-mix:\\(?:foo\\))/
196
- end
197
- end
198
- end
199
-
200
- context String do
201
- describe :indent do
202
- it "must indent single line string" do
203
- 'foobar'.indent(2).must_equal ' foobar'
204
- end
205
-
206
- it "must indent multi line string" do
207
- "foo\nbar".indent(2).must_equal " foo\n bar"
208
- "foo\nbar\n".indent(2).must_equal " foo\n bar\n"
209
- end
210
- end
211
-
212
- describe :payload_hash do
213
- subject do
214
- <<~END
215
- <?xml version="1.0" encoding="utf-8"?>
216
- <OFMX-Snapshot region="LF">
217
- <Ser type="essential" active="true">
218
- <SerUid>
219
- <UniUid>
220
- <txtName>STRASBOURG APP</txtName>
221
- </UniUid>
222
- <codeType version="1" subversion="2">APP</codeType>
223
- <noSeq>1</noSeq>
224
- </SerUid>
225
- <Stt priority="1">
226
- <codeWorkHr>H24</codeWorkHr>
227
- </Stt>
228
- <Stt priority="2">
229
- <codeWorkHr>HX</codeWorkHr>
230
- </Stt>
231
- <txtRmk>aka STRASBOURG approche</txtRmk>
232
- </Ser>
233
- </OFMX-Snapshot>
234
- END
235
- end
236
-
237
- it "must calculate the hash" do
238
- subject.payload_hash(region: 'LF', element: 'Ser').must_equal "269b1f18-cabe-3c9e-1d71-48a7414a4cb9"
239
- end
240
- end
241
-
242
- describe :to_dd do
243
- it "must convert +6.2 DMS to DD" do
244
- %q(12°34'56.78"N).to_dd.must_equal 12.58243888888889
245
- %q(12°34'56.78").to_dd.must_equal 12.58243888888889
246
- %q(12°34'56.78'').to_dd.must_equal 12.58243888888889
247
- %q(12 34 56.78).to_dd.must_equal 12.58243888888889
248
- %q(123456.78N).to_dd.must_equal 12.58243888888889
249
- end
250
-
251
- it "must convert -6.2 DMS to DD" do
252
- %q(12°34'56.78"S).to_dd.must_equal(-12.58243888888889)
253
- %q(-12°34'56.78").to_dd.must_equal(-12.58243888888889)
254
- %q(-12 34 56.78).to_dd.must_equal(-12.58243888888889)
255
- %q(123456.78S).to_dd.must_equal(-12.58243888888889)
256
- end
257
-
258
- it "must convert +7.2 DMS to DD" do
259
- %q(111°22'33.44"N).to_dd.must_equal 111.37595555555555
260
- %q(111°22'33.44").to_dd.must_equal 111.37595555555555
261
- %q(111 22 33.44).to_dd.must_equal 111.37595555555555
262
- %q(1112233.44N).to_dd.must_equal 111.37595555555555
263
- end
264
-
265
- it "must convert -7.2 DMS to DD" do
266
- %q(111°22'33.44"S).to_dd.must_equal(-111.37595555555555)
267
- %q(-111°22'33.44").to_dd.must_equal(-111.37595555555555)
268
- %q(-111 22 33.44).to_dd.must_equal(-111.37595555555555)
269
- %q(1112233.44S).to_dd.must_equal(-111.37595555555555)
270
- end
271
-
272
- it "must convert +6.1 DMS to DD" do
273
- %q(12°34'56.7"N).to_dd.must_equal 12.582416666666667
274
- %q(12°34'56.7").to_dd.must_equal 12.582416666666667
275
- %q(12 34 56.7).to_dd.must_equal 12.582416666666667
276
- %q(123456.7N).to_dd.must_equal 12.582416666666667
277
- end
278
-
279
- it "must convert -6.1 DMS to DD" do
280
- %q(12°34'56.7"S).to_dd.must_equal(-12.582416666666667)
281
- %q(-12°34'56.7").to_dd.must_equal(-12.582416666666667)
282
- %q(-12 34 56.7).to_dd.must_equal(-12.582416666666667)
283
- %q(123456.7S).to_dd.must_equal(-12.582416666666667)
284
- end
285
-
286
- it "must convert +7.1 DMS to DD" do
287
- %q(111°22'33.4"N).to_dd.must_equal 111.37594444444444
288
- %q(111°22'33.4").to_dd.must_equal 111.37594444444444
289
- %q(111 22 33.4).to_dd.must_equal 111.37594444444444
290
- %q(1112233.4N).to_dd.must_equal 111.37594444444444
291
- end
292
-
293
- it "must convert -7.1 DMS to DD" do
294
- %q(111°22'33.4"S).to_dd.must_equal(-111.37594444444444)
295
- %q(-111°22'33.4").to_dd.must_equal(-111.37594444444444)
296
- %q(-111 22 33.4).to_dd.must_equal(-111.37594444444444)
297
- %q(1112233.4S).to_dd.must_equal(-111.37594444444444)
298
- end
299
-
300
- it "must convert +6.0 DMS to DD" do
301
- %q(12°34'56"N).to_dd.must_equal 12.582222222222223
302
- %q(12°34'56").to_dd.must_equal 12.582222222222223
303
- %q(12 34 56).to_dd.must_equal 12.582222222222223
304
- %q(123456N).to_dd.must_equal 12.582222222222223
305
- end
306
-
307
- it "must convert -6.0 DMS to DD" do
308
- %q(12°34'56"S).to_dd.must_equal(-12.582222222222223)
309
- %q(-12°34'56").to_dd.must_equal(-12.582222222222223)
310
- %q(-12 34 56).to_dd.must_equal(-12.582222222222223)
311
- %q(123456S).to_dd.must_equal(-12.582222222222223)
312
- end
313
-
314
- it "must convert +7.0 DMS to DD" do
315
- %q(111°22'33"N).to_dd.must_equal 111.37583333333333
316
- %q(111°22'33").to_dd.must_equal 111.37583333333333
317
- %q(111 22 33).to_dd.must_equal 111.37583333333333
318
- %q(1112233N).to_dd.must_equal 111.37583333333333
319
- end
320
-
321
- it "must convert -7.0 DMS to DD" do
322
- %q(111°22'33"S).to_dd.must_equal(-111.37583333333333)
323
- %q(-111°22'33").to_dd.must_equal(-111.37583333333333)
324
- %q(-111 22 33).to_dd.must_equal(-111.37583333333333)
325
- %q(1112233S).to_dd.must_equal(-111.37583333333333)
326
- end
327
-
328
- it "must convert all cardinal directions to DD" do
329
- %q(111°22'33.44"N).to_dd.must_equal 111.37595555555555
330
- %q(111°22'33.44"E).to_dd.must_equal 111.37595555555555
331
- %q(111°22'33.44"S).to_dd.must_equal -111.37595555555555
332
- %q(111°22'33.44"W).to_dd.must_equal -111.37595555555555
333
- end
334
-
335
- it "must ignore minor typos when converting to DD" do
336
- %q(111°22'33,44"N).to_dd.must_equal 111.37595555555555
337
- %q(111°22'33.44"n).to_dd.must_equal 111.37595555555555
338
- %q(111°22"33.44"N).to_dd.must_equal 111.37595555555555
339
- %q(111°22'33.44'N).to_dd.must_equal 111.37595555555555
340
- %q(111°22'33.44" N).to_dd.must_equal 111.37595555555555
341
- %q(111° 22' 33.44" N).to_dd.must_equal 111.37595555555555
342
- %q(-111°22'33.44"S).to_dd.must_equal 111.37595555555555
343
- end
344
-
345
- it "must do all possible roundtrip conversions" do
346
- if ENV['SPEC_SCOPE'] == 'all'
347
- 2.times.with_index do |degrees|
348
- 60.times.with_index do |minutes|
349
- 60.times.with_index do |seconds|
350
- 100.times.with_index do |fractions|
351
- subject = %q(%03d°%02d'%02d.%02d") % [degrees, minutes, seconds, fractions]
352
- subject.to_dd.to_dms.must_equal subject
353
- end
354
- end
355
- end
356
- end
357
- else
358
- skip
359
- end
360
- end
361
- end
362
-
363
- describe :to_time do
364
- it "must convert valid dates and times" do
365
- subject = '2018-01-01 17:17 +00:00'
366
- subject.to_time.must_equal Time.parse(subject)
367
- end
368
-
369
- it "fails on invalid dates and times" do
370
- subject = '2018-01-77 17:17 +00:00'
371
- -> { subject.to_time }.must_raise ArgumentError
372
- end
373
- end
374
-
375
- describe :uptrans do
376
- it "must transliterate invalid characters" do
377
- 'DÉJÀ SCHÖN'.uptrans.must_equal 'DEJA SCHOEN'
378
- end
379
- end
380
- end
381
- end
@@ -1,7 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe AIXM do
4
- it "must be defined" do
5
- AIXM::VERSION.wont_be_nil
6
- end
7
- end
@@ -1,150 +0,0 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe AIXM::W do
4
- subject do
5
- AIXM::Factory.w
6
- end
7
-
8
- describe :wgt= do
9
- it "fails on invalid values" do
10
- [:foobar, -1].wont_be_written_to subject, :wgt
11
- end
12
-
13
- it "converts Numeric to Float" do
14
- subject.tap { |s| s.wgt = 5 }.wgt.must_equal 5.0
15
- end
16
- end
17
-
18
- describe :unit= do
19
- it "fails on invalid values" do
20
- [:foobar, 123].wont_be_written_to subject, :unit
21
- end
22
-
23
- it "symbolizes and downcases values" do
24
- subject.tap { |s| s.unit = "KG" }.unit.must_equal :kg
25
- end
26
- end
27
-
28
- describe :to_kg do
29
- it "leaves kilograms untouched" do
30
- subject = AIXM.w(2, :kg)
31
- subject.to_kg.must_be_same_as subject
32
- end
33
-
34
- it "converts metric tonnes to kilograms" do
35
- AIXM.w(0.5, :t).to_kg.must_equal AIXM.w(500, :kg)
36
- end
37
-
38
- it "converts pound to kilograms" do
39
- AIXM.w(200, :lb).to_kg.must_equal AIXM.w(90.718474, :kg)
40
- end
41
-
42
- it "converts US tons to kilograms" do
43
- AIXM.w(0.5, :ton).to_kg.must_equal AIXM.w(453.59237, :kg)
44
- end
45
- end
46
-
47
- describe :to_t do
48
- it "leaves metric tonnes untouched" do
49
- subject = AIXM.w(2, :t)
50
- subject.to_t.must_be_same_as subject
51
- end
52
-
53
- it "converts kilograms to metric tonnes" do
54
- AIXM.w(10_000, :kg).to_t.must_equal AIXM.w(10, :t)
55
- end
56
-
57
- it "converts pound to metric tonnes" do
58
- AIXM.w(1000, :lb).to_t.must_equal AIXM.w(0.45359237, :t)
59
- end
60
-
61
- it "converts US tons to metric tonnes" do
62
- AIXM.w(1, :ton).to_t.must_equal AIXM.w(0.90718474, :t)
63
- end
64
- end
65
-
66
- describe :to_lb do
67
- it "leaves pound untouched" do
68
- subject = AIXM.w(2, :lb)
69
- subject.to_lb.must_be_same_as subject
70
- end
71
-
72
- it "converts kilograms to pound" do
73
- AIXM.w(50, :kg).to_lb.must_equal AIXM.w(110.2311311, :lb)
74
- end
75
-
76
- it "converts metric tonnes to pound" do
77
- AIXM.w(0.5, :t).to_lb.must_equal AIXM.w(1102.311311, :lb)
78
- end
79
-
80
- it "converts US tons to pound" do
81
- AIXM.w(0.5, :ton).to_lb.must_equal AIXM.w(1000.00000007, :lb)
82
- end
83
- end
84
-
85
- describe :to_ton do
86
- it "leaves US tons untouched" do
87
- subject = AIXM.w(2, :ton)
88
- subject.to_ton.must_be_same_as subject
89
- end
90
-
91
- it "converts kilograms to US tons" do
92
- AIXM.w(1000, :kg).to_ton.must_equal AIXM.w(1.10231131, :ton)
93
- end
94
-
95
- it "converts metrical tons to US tons" do
96
- AIXM.w(0.5, :t).to_ton.must_equal AIXM.w(0.55115566, :ton)
97
- end
98
-
99
- it "converts pound to US tons" do
100
- AIXM.w(3000, :lb).to_ton.must_equal AIXM.w(1.5, :ton)
101
- end
102
- end
103
-
104
- describe :<=> do
105
- it "recognizes objects with identical unit and weight as equal" do
106
- a = AIXM.w(123, :kg)
107
- b = AIXM.w(123.0, 'KG')
108
- a.must_equal b
109
- end
110
-
111
- it "recognizes objects with different units and converted weight as equal" do
112
- a = AIXM.w(123, :kg)
113
- b = AIXM.w(271.16858251, 'LB')
114
- a.must_equal b
115
- end
116
-
117
- it "recognizes objects with different units and identical weight as unequal" do
118
- a = AIXM.w(123, :kg)
119
- b = AIXM.w(123, :lb)
120
- a.wont_equal b
121
- end
122
-
123
- it "recognizes objects of different class as unequal" do
124
- a = AIXM.w(123, :kg)
125
- b = :oggy
126
- a.wont_equal b
127
- end
128
- end
129
-
130
- describe :hash do
131
- it "returns an integer" do
132
- subject.hash.must_be_instance_of Integer
133
- end
134
-
135
- it "allows for the use of instances as hash keys" do
136
- dupe = subject.dup
137
- { subject => true }[dupe].must_equal true
138
- end
139
- end
140
-
141
- describe :zero? do
142
- it "returns true for zero weight" do
143
- subject.tap { |s| s.wgt = 0 }.must_be :zero?
144
- end
145
-
146
- it "returns false for non-zero weight" do
147
- subject.tap { |s| s.wgt = 1 }.wont_be :zero?
148
- end
149
- end
150
- end