mesh-medical-subject-headings 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_base.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'test_helper'
2
+
3
+ module MESH
4
+ class TestBase < Minitest::Test
5
+
6
+ def initialize arg
7
+ super
8
+ @@mesh_tree ||= MESH::Tree.new
9
+ @@mesh_tree.load_translation(:en_gb)
10
+ @@mesh_tree.load_wikipedia
11
+ end
12
+
13
+ end
14
+ end
data/test/test_helper.rb CHANGED
@@ -7,7 +7,8 @@ require "mocha/setup"
7
7
  lib = File.expand_path('../../lib', __FILE__)
8
8
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
9
 
10
- require "MESH"
10
+ require 'MESH'
11
+ require_relative 'test_base'
11
12
 
12
13
  # puts 'Configuring MESH::Mesh — this may take up to 10 seconds.'
13
14
  # start = Time.now
@@ -1,7 +1,7 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  module MESH
4
- class MeshCoreTest < Minitest::Test
4
+ class TreeTest < TestBase
5
5
 
6
6
  def test_yield_to_a_block_for_each
7
7
  block_called = false
@@ -73,130 +73,6 @@ module MESH
73
73
  assert_nil @mesh_tree.find_by_entry('foo')
74
74
  end
75
75
 
76
- def test_have_the_correct_unique_id
77
- mh = @mesh_tree.find('D000001')
78
- assert_equal 'D000001', mh.unique_id
79
- end
80
-
81
- def test_have_the_correct_tree_number
82
- mh = @mesh_tree.find('D000001')
83
- assert_equal 1, mh.tree_numbers.length
84
- assert_includes mh.tree_numbers, 'D03.438.221.173'
85
- end
86
-
87
- def test_have_the_correct_tree_numbers
88
- mh = @mesh_tree.find('D000224')
89
- assert_equal 2, mh.tree_numbers.length
90
- assert_includes mh.tree_numbers, 'C19.053.500.263'
91
- assert_includes mh.tree_numbers, 'C20.111.163'
92
- end
93
-
94
- def test_have_the_correct_root_letters
95
- mh = @mesh_tree.find('D000224')
96
- assert_equal ['C'], mh.roots
97
- mh = @mesh_tree.find('D064946')
98
- assert_equal ['H', 'N'], mh.roots
99
- end
100
-
101
- def test_have_the_correct_descriptor_class
102
- mh = @mesh_tree.find('D000224')
103
- assert_equal :topical_descriptor, mh.descriptor_class
104
- mh = @mesh_tree.find('D005260')
105
- assert_equal :check_tag, mh.descriptor_class
106
- end
107
-
108
- def test_have_the_correct_semantic_type
109
- mh = @mesh_tree.find('D000224')
110
- assert_equal ['Disease or Syndrome'], mh.semantic_types
111
- mh = @mesh_tree.find('D005260')
112
- assert_equal ['Organism Attribute'], mh.semantic_types
113
- mh = @mesh_tree.find('D014148')
114
- assert_equal ['Organic Chemical', 'Pharmacologic Substance'], mh.semantic_types
115
-
116
- end
117
-
118
- def test_have_the_correct_original_heading
119
- mh = @mesh_tree.find('D000224')
120
- assert_equal 'Addison Disease', mh.original_heading
121
- mh = @mesh_tree.find('D000014')
122
- assert_equal 'Abnormalities, Drug-Induced', mh.original_heading
123
- end
124
-
125
- def test_have_anglicised_original_heading
126
- mh = @mesh_tree.find('D001471')
127
- assert_equal 'Barrett Esophagus', mh.original_heading
128
- assert_equal 'Barrett Oesophagus', mh.original_heading(:en_gb)
129
- end
130
-
131
- def test_have_natural_language_name
132
- mh = @mesh_tree.find('D000224')
133
- assert_equal 'Addison Disease', mh.natural_language_name
134
- mh = @mesh_tree.find('D000014')
135
- assert_equal 'Drug-Induced Abnormalities', mh.natural_language_name
136
- end
137
-
138
- def test_have_anglicised_natural_language_name
139
- mh = @mesh_tree.find('D001471')
140
- assert_equal 'Barrett Esophagus', mh.natural_language_name
141
- assert_equal 'Barrett Oesophagus', mh.natural_language_name(:en_gb)
142
- end
143
-
144
- def test_have_the_correct_summary
145
- mh = @mesh_tree.find('D000238')
146
- assert_equal 'A benign tumor of the anterior pituitary in which the cells do not stain with acidic or basic dyes.', mh.summary
147
- end
148
-
149
- def test_have_anglicised_summary
150
- mh = @mesh_tree.find('D001471')
151
- assert_equal 'A condition with damage to the lining of the lower ESOPHAGUS resulting from chronic acid reflux (ESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the esophagus.', mh.summary
152
- assert_equal 'A condition with damage to the lining of the lower OESOPHAGUS resulting from chronic acid reflux (OESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the oesophagus.', mh.summary(:en_gb)
153
- end
154
-
155
- def test_linkify_summary
156
- mh = @mesh_tree.find('D001471')
157
- original_summary = 'A condition with damage to the lining of the lower ESOPHAGUS resulting from chronic acid reflux (ESOPHAGITIS, REFLUX). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the INTESTINE or the salmon-pink mucosa of the STOMACH. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to ADENOCARCINOMA of the esophagus.'
158
- assert_equal original_summary, mh.summary
159
-
160
- found = {
161
- 'ESOPHAGUS' => false,
162
- 'ESOPHAGITIS, REFLUX' => false,
163
- 'INTESTINE' => false,
164
- 'STOMACH' => false,
165
- 'ADENOCARCINOMA' => false
166
- }
167
-
168
- linkified_summary = mh.linkify_summary do |text, heading|
169
- found[text] = true unless heading.nil?
170
- "<foo>#{text.downcase}</foo>"
171
- end
172
-
173
- assert_equal 5, found.length
174
- assert found['ESOPHAGUS']
175
- assert found['ESOPHAGITIS, REFLUX']
176
- assert found['INTESTINE']
177
- assert found['STOMACH']
178
- assert found['ADENOCARCINOMA']
179
-
180
- assert_equal original_summary, mh.summary
181
- assert_equal 'A condition with damage to the lining of the lower <foo>esophagus</foo> resulting from chronic acid reflux (<foo>esophagitis, reflux</foo>). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the <foo>intestine</foo> or the salmon-pink mucosa of the <foo>stomach</foo>. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to <foo>adenocarcinoma</foo> of the esophagus.', linkified_summary
182
-
183
- end
184
-
185
- def test_linkifies_another_summary
186
- mh = @mesh_tree.find_by_original_heading('Diabetic Nephropathies')
187
- linkified_summary = mh.linkify_summary do |text, heading|
188
- "<linky href=\"#{heading.unique_id}\">#{text.downcase}</linky>"
189
- end
190
-
191
- expected_summary = 'KIDNEY injuries associated with diabetes mellitus and affecting KIDNEY GLOMERULUS; ARTERIOLES; KIDNEY TUBULES; and the interstitium. Clinical signs include persistent PROTEINURIA, from microalbuminuria progressing to ALBUMINURIA of greater than 300 mg/24 h, leading to reduced GLOMERULAR FILTRATION RATE and END-STAGE RENAL DISEASE.'
192
-
193
- expected_linkified = '<linky href="D007668">kidney</linky> injuries associated with diabetes mellitus and affecting <linky href="D007678">kidney glomerulus</linky>; <linky href="D001160">arterioles</linky>; <linky href="D007684">kidney tubules</linky>; and the interstitium. Clinical signs include persistent <linky href="D011507">proteinuria</linky>, from microalbuminuria progressing to <linky href="D000419">albuminuria</linky> of greater than 300 mg/24 h, leading to reduced <linky href="D005919">glomerular filtration rate</linky> and <linky href="D007676">end-stage renal disease</linky>.'
194
-
195
-
196
- assert_equal expected_summary, mh.summary
197
- assert_equal expected_linkified, linkified_summary
198
- end
199
-
200
76
  def test_linkifies_all_summaries
201
77
  mesh = MESH::Tree.new
202
78
  mesh.linkify_summaries do |text, heading|
@@ -206,263 +82,6 @@ module MESH
206
82
  assert_equal 'A condition with damage to the lining of the lower <bar>esophagus</bar> resulting from chronic acid reflux (<bar>esophagitis, reflux</bar>). Through the process of metaplasia, the squamous cells are replaced by a columnar epithelium with cells resembling those of the <bar>intestine</bar> or the salmon-pink mucosa of the <bar>stomach</bar>. Barrett\'s columnar epithelium is a marker for severe reflux and precursor to <bar>adenocarcinoma</bar> of the esophagus.', mh.linkified_summary
207
83
  end
208
84
 
209
- def test_to_s
210
- mh = @mesh_tree.find('D001471')
211
- assert_equal 'D001471, Barrett Esophagus, [C06.198.102,C06.405.117.102]', mh.to_s
212
- end
213
-
214
- def test_have_the_correct_entries
215
- expected_entries = ['Activity Cycles', 'Ultradian Cycles', 'Activity Cycle', 'Cycle, Activity', 'Cycle, Ultradian', 'Cycles, Activity', 'Cycles, Ultradian', 'Ultradian Cycle']
216
- expected_entries.sort!
217
- mh = @mesh_tree.find('D000204')
218
- assert_equal expected_entries, mh.entries
219
- end
220
-
221
- def test_have_anglicised_entries
222
- expected_entries = ['Barrett Esophagus', 'Barrett Syndrome', 'Esophagus, Barrett', 'Barrett Epithelium', 'Barrett Metaplasia', 'Barrett\'s Esophagus', 'Barrett\'s Syndrome', 'Barretts Esophagus', 'Barretts Syndrome', 'Epithelium, Barrett', 'Esophagus, Barrett\'s', 'Syndrome, Barrett', 'Syndrome, Barrett\'s']
223
- expected_entries_en = ['Barrett Oesophagus', 'Barrett Syndrome', 'Oesophagus, Barrett', 'Barrett Epithelium', 'Barrett Metaplasia', 'Barrett\'s Oesophagus', 'Barrett\'s Syndrome', 'Barretts Oesophagus', 'Barretts Syndrome', 'Epithelium, Barrett', 'Oesophagus, Barrett\'s', 'Syndrome, Barrett', 'Syndrome, Barrett\'s']
224
-
225
- expected_entries.sort!
226
- expected_entries_en.sort!
227
- mh = @mesh_tree.find('D001471')
228
- assert_equal expected_entries.sort, mh.entries
229
- assert_equal expected_entries_en.sort, mh.entries(:en_gb)
230
- end
231
-
232
- def test_have_a_single_wikipedia_link
233
-
234
- expected = {
235
- 'D000001' => 'http://en.wikipedia.org/wiki/A23187',
236
- 'D000005' => 'http://en.wikipedia.org/wiki/Abdomen',
237
- 'D000082' => 'http://en.wikipedia.org/wiki/Paracetamol'
238
- }
239
-
240
- expected.each do |id, expected_link|
241
- mh = @mesh_tree.find(id)
242
- assert_equal 1, mh.wikipedia_links.length
243
- assert_equal expected_link, mh.wikipedia_links[0][:link]
244
- end
245
-
246
- end
247
-
248
- def test_have_a_single_wikipedia_score
249
- expected = {
250
- 'D000001' => 0.5,
251
- 'D000005' => 1.0,
252
- 'D000082' => 0.35
253
- }
254
-
255
- expected.each do |id, expected_score|
256
- mh = @mesh_tree.find(id)
257
- assert_equal 1, mh.wikipedia_links.length
258
- assert_equal expected_score, mh.wikipedia_links[0][:score]
259
- end
260
-
261
- end
262
-
263
- def test_have_a_single_wikipedia_image
264
- expected = {
265
- 'D000001' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/1/17/A23187.png/220px-A23187.png',
266
- 'D000005' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Abdomen_%28PSF%29.jpg/250px-Abdomen_%28PSF%29.jpg',
267
- 'D000082' => 'http://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Paracetamol-skeletal.svg/150px-Paracetamol-skeletal.svg.png'
268
- }
269
-
270
- expected.each do |id, expected_image|
271
- mh = @mesh_tree.find(id)
272
- assert_equal 1, mh.wikipedia_links.length
273
- assert_equal expected_image, mh.wikipedia_links[0][:image]
274
- end
275
- end
276
-
277
- def test_have_a_single_wikipedia_abstract
278
- expected = {
279
- 'D000001' => '| CAS_number = 52665-69-7',
280
- 'D000005' => 'The abdomen (less formally called the belly, stomach, or tummy), in vertebrates such as mammals, constitutes the part of the body between the thorax (chest) and pelvis. The region enclosed by the abdomen is termed the abdominal cavity.',
281
- 'D000082' => '| MedlinePlus = a681004'
282
- }
283
-
284
- expected.each do |id, expected_abstract|
285
- mh = @mesh_tree.find(id)
286
- assert_equal 1, mh.wikipedia_links.length
287
- assert_equal expected_abstract, mh.wikipedia_links[0][:abstract]
288
- end
289
- end
290
-
291
- def test_have_more_than_one_wikipedia_link
292
- mh = @mesh_tree.find('D000100')
293
- expected = %w(
294
- http://en.wikipedia.org/wiki/Sodium_acetrizoate
295
- http://en.wikipedia.org/wiki/Acetrizoic_acid
296
- )
297
- assert_equal expected, mh.wikipedia_links.map { |l| l[:link] }
298
- end
299
-
300
- def test_have_more_than_one_wikipedia_score
301
- mh = @mesh_tree.find('D000100')
302
- expected = [0.09, 0.09]
303
- assert_equal expected, mh.wikipedia_links.map { |l| l[:score] }
304
- end
305
-
306
- def test_have_more_than_one_wikipedia_image
307
- mh = @mesh_tree.find('D000100')
308
- expected = %w(
309
- http://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Sodium_acetrizoate.svg/150px-Sodium_acetrizoate.svg.png
310
- http://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Acetrizoic_acid.png/220px-Acetrizoic_acid.png
311
- )
312
- assert_equal expected, mh.wikipedia_links.map { |l| l[:image] }
313
- end
314
-
315
- def test_have_more_than_one_wikipedia_abstract
316
- mh = @mesh_tree.find('D000100')
317
- expected = ['| CAS_number = 129-63-5', '| CAS_number = 85-36-9']
318
- assert_equal expected, mh.wikipedia_links.map { |l| l[:abstract] }
319
- end
320
-
321
- def test_have_the_correct_parent
322
- mh = @mesh_tree.find('D000001')
323
- assert_equal 1, mh.parents.length
324
- assert_equal 'D001583', mh.parents[0].unique_id
325
- end
326
-
327
- def test_have_the_correct_parents
328
- mh = @mesh_tree.find('D000224')
329
- p1 = @mesh_tree.find('D000309')
330
- p2 = @mesh_tree.find('D001327')
331
- assert_equal 2, mh.parents.length
332
- assert_includes mh.parents, p1
333
- assert_includes mh.parents, p2
334
- end
335
-
336
- def test_have_the_correct_parents_again
337
- child = @mesh_tree.find_by_original_heading('Questionnaires')
338
- assert_equal 1, child.parents.length
339
- expected_parent = @mesh_tree.find_by_original_heading('Data Collection')
340
- assert_includes child.parents, expected_parent
341
- end
342
-
343
- def test_have_the_correct_children
344
- parent = @mesh_tree.find_by_tree_number('C19.053.500')
345
- child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
346
- child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
347
- child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
348
- child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
349
-
350
- assert_equal 4, parent.children.length
351
- assert_includes parent.children, child1
352
- assert_includes parent.children, child2
353
- assert_includes parent.children, child3
354
- assert_includes parent.children, child4
355
- end
356
-
357
- def test_have_the_correct_children_again
358
- parent = @mesh_tree.find_by_original_heading('Data Collection')
359
-
360
- expected_children = [
361
- 'Health Surveys',
362
- 'Interviews as Topic',
363
- 'Questionnaires',
364
- 'Records as Topic',
365
- 'Registries',
366
- 'Vital Statistics',
367
- 'Geriatric Assessment',
368
- 'Nutrition Assessment',
369
- 'Health Care Surveys',
370
- 'Narration',
371
- 'Lot Quality Assurance Sampling',
372
- 'Checklist',
373
- 'Health Impact Assessment',
374
- 'Crowdsourcing'
375
- ].map { |oh| @mesh_tree.find_by_original_heading(oh) }
376
-
377
-
378
- assert_equal expected_children.length, parent.children.length
379
- expected_children.each do |ec|
380
- assert_includes parent.children, ec
381
- end
382
- end
383
-
384
- def test_have_the_correct_siblings
385
- skip
386
- end
387
-
388
- def test_match_on_conditions_for_original_heading
389
- mh = @mesh_tree.find('D001471')
390
- assert mh.matches(original_heading: /^Barrett Esophagus$/)
391
- end
392
-
393
- def test_not_match_on_incorrect_condition_for_original_heading
394
- mh = @mesh_tree.find('D001471')
395
- refute mh.matches(original_heading: /^Foo$/)
396
- end
397
-
398
- def test_match_on_conditions_for_entries
399
- mh = @mesh_tree.find('D001471')
400
- assert mh.matches(entries: /Metaplasia/)
401
- end
402
-
403
- def test_not_match_on_incorrect_conditions_for_entries
404
- mh = @mesh_tree.find('D001471')
405
- refute mh.matches(entries: /Foo/)
406
- end
407
-
408
- def test_match_on_descriptor_class
409
- mh = @mesh_tree.find('D000224')
410
- assert mh.matches(descriptor_class: :topical_descriptor)
411
- refute mh.matches(descriptor_class: :check_tag)
412
- mh = @mesh_tree.find('D005260')
413
- assert mh.matches(descriptor_class: :check_tag)
414
- refute mh.matches(descriptor_class: :topical_descriptor)
415
- end
416
-
417
- def test_match_on_conditions_for_tree_numbers
418
- mh = @mesh_tree.find('D001471')
419
- assert mh.matches(tree_numbers: /C06\.198\.102/)
420
- assert mh.matches(tree_numbers: /^C06\.198\.102$/)
421
- assert mh.matches(tree_numbers: /^C06/)
422
- assert mh.matches(tree_numbers: /\.198\./)
423
- assert mh.matches(tree_numbers: /^C06\.405\.117\.102$/)
424
- end
425
-
426
- def test_not_match_on_incorrect_conditions_for_tree_numbers
427
- mh = @mesh_tree.find('D001471')
428
- refute mh.matches(tree_numbers: /Foo/)
429
- end
430
-
431
- def test_match_on_conditions_for_summary
432
- mh = @mesh_tree.find('D001471')
433
- assert mh.matches(summary: /the lower ESOPHAGUS resulting from chronic acid reflux \(ESOPHAGITIS, REFLUX\)\./)
434
- end
435
-
436
- def test_not_match_on_incorrect_conditions_for_summary
437
- mh = @mesh_tree.find('D001471')
438
- refute mh.matches(summary: /Foo/)
439
- end
440
-
441
- def test_match_on_conditions_for_useful
442
- mh = @mesh_tree.find('D001471')
443
- begin
444
- mh.useful = true
445
- assert mh.matches(useful: true)
446
- refute mh.matches(useful: false)
447
- mh.useful = false
448
- assert mh.matches(useful: false)
449
- refute mh.matches(useful: true)
450
- ensure
451
- mh.useful = true
452
- end
453
- end
454
-
455
- def test_match_on_multiple_conditions
456
- mh = @mesh_tree.find('D001471')
457
- assert mh.matches(original_heading: /^Barrett Esophagus$/, summary: /the lower ESOPHAGUS/)
458
- end
459
-
460
- def test_not_match_on_incorrect_multiple_conditions
461
- mh = @mesh_tree.find('D001471')
462
- refute mh.matches(original_heading: /^Barrett Esophagus$/, summary: /Foo/)
463
- refute mh.matches(original_heading: /^Foo/, summary: /the lower ESOPHAGUS/)
464
- end
465
-
466
85
  def test_match_headings_that_occur_in_given_text
467
86
  expected_ids = %w(D001491 D001769 D001792 D001853 D002470 D002477 D002648 D002965 D002999 D003561 D003593 D003643 D004194 D004314 D004813 D004912 D005091 D005123 D005293 D005333 D005385 D005544 D005796 D006128 D006225 D006309 D006321 D006331 D006405 D007107 D007223 D007231 D007239 D007246 D007938 D007947 D008099 D008168 D008214 D008423 D008533 D008607 D008722 D009035 D009055 D009132 D009154 D009190 D009196 D009369 D009666 D010372 D010641 D011153 D012008 D012106 D012146 D012306 D012307 D012380 D012680 D012867 D013534 D013601 D013812 D013921 D013961 D014034 D014157 D014171 D014960 D015032 D015470 D015994 D015995 D016424 D016433 D017584 D017668 D018387 D018388 D019021 D019070 D019368 D019369 D032882 D036801 D038042 D041905 D052016 D054198 D055016)
468
87
  expected = expected_ids.map { |id| @mesh_tree.find(id) }
@@ -471,10 +90,6 @@ module MESH
471
90
  assert_equal expected.sort, actual.sort
472
91
  end
473
92
 
474
- def test_sort_based_on_unique_id
475
- skip
476
- end
477
-
478
93
  def test_only_match_the_most_specific_matches_in_given_text
479
94
  expected = @mesh_tree.find('D054144')
480
95
  actual = @mesh_tree.match_in_text('Diastolic Heart Failure')
@@ -532,16 +147,6 @@ module MESH
532
147
  assert_equal @mesh_tree.find('D007938'), matches[0][:heading]
533
148
  end
534
149
 
535
- def test_allow_headings_to_be_marked_as_not_useful
536
- mh = @mesh_tree.find('D055550')
537
- mh.useful = true
538
- assert mh.useful
539
- mh.useful = false
540
- refute mh.useful
541
- mh.useful = true
542
- assert mh.useful
543
- end
544
-
545
150
  def test_allow_headings_to_be_found_with_a_where_match_on_original_heading
546
151
  expected = [@mesh_tree.find('D003561'), @mesh_tree.find('D016238')]
547
152
  actual = @mesh_tree.where(original_heading: /^Cyta/)
@@ -605,79 +210,10 @@ module MESH
605
210
  end
606
211
  end
607
212
 
608
- def test_know_its_deepest_position_in_the_tree
609
- #single tree numbers
610
- assert_equal 1, @mesh_tree.find('D002319').deepest_position
611
- assert_equal 2, @mesh_tree.find('D001808').deepest_position
612
- assert_equal 3, @mesh_tree.find('D001158').deepest_position
613
- assert_equal 4, @mesh_tree.find('D001981').deepest_position
614
- end
615
-
616
- def test_know_its_shallowest_position_in_the_tree
617
- #single tree numbers
618
- assert_equal 1, @mesh_tree.find('D002319').shallowest_position
619
- assert_equal 2, @mesh_tree.find('D001808').shallowest_position
620
- assert_equal 3, @mesh_tree.find('D001158').shallowest_position
621
- assert_equal 4, @mesh_tree.find('D001981').shallowest_position
622
- end
623
-
624
- def test_know_if_one_heading_is_the_descendant_of_another
625
- parent = @mesh_tree.find('D002319')
626
- child = @mesh_tree.find('D001808')
627
- grandchild = @mesh_tree.find('D001158')
628
- great_grandchild = @mesh_tree.find('D001981')
629
- unrelated = @mesh_tree.find('D008091')
630
-
631
- refute parent.has_descendant(parent), 'should not consider itself a desecendant'
632
- assert parent.has_descendant(child), "should consider child #{child.inspect} a descendant of #{parent.inspect} in #{parent.children}"
633
- assert parent.has_descendant(grandchild), "should consider grandchild #{grandchild.inspect} a descendant #{parent.inspect}"
634
- assert parent.has_descendant(great_grandchild), "should consider great grandchild #{great_grandchild.inspect} a descendant #{parent.inspect}"
635
- refute parent.has_descendant(unrelated), 'should not consider an unrelated heading a descendant'
636
- end
637
-
638
- def test_know_if_one_heading_is_the_ancestor_of_another
639
- child = @mesh_tree.find('D001981')
640
- parent = @mesh_tree.find('D001158')
641
- grandparent = @mesh_tree.find('D001808')
642
- great_grandparent = @mesh_tree.find('D002319')
643
- unrelated = @mesh_tree.find('D008091')
644
-
645
- refute child.has_ancestor(child), 'should not consider itself an ancestor'
646
- assert child.has_ancestor(parent), "should consider parent #{parent.inspect} an ancestor of #{child.inspect} in #{child.parents}"
647
- assert child.has_ancestor(grandparent), "should consider grandparent #{grandparent.inspect} an ancestor #{child.inspect}"
648
- assert child.has_ancestor(great_grandparent), "should consider great grandparent #{great_grandparent.inspect} an ancestor #{child.inspect}"
649
- refute child.has_ancestor(unrelated), 'should not consider an unrelated heading an ancestor'
650
- end
651
-
652
- def test_know_if_headings_are_siblings_at_the_same_level_below_a_common_parent
653
- parent = @mesh_tree.find_by_tree_number('C19.053.500')
654
- child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
655
- child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
656
- child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
657
- child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
658
- unrelated = @mesh_tree.find('D008091')
659
- children = [child1, child2, child3, child4]
660
-
661
- children.each { |c| refute parent.sibling?(c) }
662
- children.each { |c| refute c.sibling?(parent) }
663
-
664
- children.each { |c| assert child1.sibling?(c) unless c == child1 }
665
- children.each { |c| assert c.sibling?(child1) unless c == child1 }
666
-
667
- children.each { |c| refute unrelated.sibling?(c) }
668
- children.each { |c| refute c.sibling?(unrelated) }
669
- end
670
-
671
- def test_override_inspect_to_prevent_issues_in_test_diagnostics
672
- mh = @mesh_tree.find('D001471')
673
- expected = "#{mh.unique_id}, #{mh.original_heading}, [#{mh.tree_numbers.join(',')}]"
674
- assert_equal expected, mh.inspect
675
- end
676
-
677
213
  def setup
678
- @@mesh_tree ||= MESH::Tree.new
679
- @@mesh_tree.load_translation(:en_gb)
680
- @@mesh_tree.load_wikipedia
214
+ # @@mesh_tree ||= MESH::Tree.new
215
+ # @@mesh_tree.load_translation(:en_gb)
216
+ # @@mesh_tree.load_wikipedia
681
217
  @mesh_tree = @@mesh_tree
682
218
  @example_text ||= 'Leukaemia in Downs Syndrome
683
219
  Overview