mesh-medical-subject-headings 1.3.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,152 +1,153 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  module MESH
4
- describe 'Testing MESH:Mesh core functions' do
4
+ class MeshCoreTest < Minitest::Test
5
5
 
6
- it 'should yield to a block for each' do
6
+ def test_yield_to_a_block_for_each
7
7
  block_called = false
8
- MESH::Mesh.each do |h|
8
+ @mesh_tree.each do |h|
9
9
  block_called = true
10
10
  break
11
11
  end
12
12
  assert block_called
13
13
  end
14
14
 
15
- it 'should not have nil headings' do
16
- MESH::Mesh.each do |h|
15
+ def test_not_have_nil_headings
16
+ @mesh_tree.each do |h|
17
17
  refute_nil h
18
18
  end
19
19
  end
20
20
 
21
- it 'should find by unique id' do
22
- mh = MESH::Mesh.find('D000001')
21
+ def test_find_by_unique_id
22
+ mh = @mesh_tree.find('D000001')
23
23
  refute_nil mh
24
24
  end
25
25
 
26
- it 'should find by tree number' do
27
- mh = MESH::Mesh.find_by_tree_number('G14.640.079')
26
+ def test_find_by_tree_number
27
+ mh = @mesh_tree.find_by_tree_number('G14.640.079')
28
28
  refute_nil mh
29
29
  assert_equal 'D000065', mh.unique_id
30
30
  end
31
31
 
32
- it 'should find by original heading' do
33
- mh = MESH::Mesh.find_by_original_heading('Allergens')
32
+ def test_find_by_original_heading
33
+ mh = @mesh_tree.find_by_original_heading('Allergens')
34
34
  refute_nil mh
35
35
  assert_equal 'D000485', mh.unique_id
36
36
  end
37
37
 
38
- it 'should not find original heading that doesnt exist' do
39
- mh = MESH::Mesh.find_by_original_heading('Lorem')
38
+ def test_not_find_original_heading_that_doesnt_exist
39
+ mh = @mesh_tree.find_by_original_heading('Lorem')
40
40
  assert_nil mh
41
41
  end
42
42
 
43
- it 'should have the correct unique id' do
44
- mh = MESH::Mesh.find('D000001')
43
+ def test_have_the_correct_unique_id
44
+ mh = @mesh_tree.find('D000001')
45
45
  assert_equal 'D000001', mh.unique_id
46
46
  end
47
47
 
48
- it 'should have the correct tree number' do
49
- mh = MESH::Mesh.find('D000001')
48
+ def test_have_the_correct_tree_number
49
+ mh = @mesh_tree.find('D000001')
50
50
  assert_equal 1, mh.tree_numbers.length
51
51
  assert_includes mh.tree_numbers, 'D03.438.221.173'
52
52
  end
53
53
 
54
- it 'should have the correct tree numbers' do
55
- mh = MESH::Mesh.find('D000224')
54
+ def test_have_the_correct_tree_numbers
55
+ mh = @mesh_tree.find('D000224')
56
56
  assert_equal 2, mh.tree_numbers.length
57
57
  assert_includes mh.tree_numbers, 'C19.053.500.263'
58
58
  assert_includes mh.tree_numbers, 'C20.111.163'
59
59
  end
60
60
 
61
- it 'should have the correct root letters' do
62
- mh = MESH::Mesh.find('D000224')
61
+ def test_have_the_correct_root_letters
62
+ mh = @mesh_tree.find('D000224')
63
63
  assert_equal ['C'], mh.roots
64
- mh = MESH::Mesh.find('D064946')
64
+ mh = @mesh_tree.find('D064946')
65
65
  assert_equal ['H', 'N'], mh.roots
66
66
  end
67
67
 
68
- it 'should have the correct descriptor class' do
69
- mh = MESH::Mesh.find('D000224')
68
+ def test_have_the_correct_descriptor_class
69
+ mh = @mesh_tree.find('D000224')
70
70
  assert_equal :topical_descriptor, mh.descriptor_class
71
- mh = MESH::Mesh.find('D005260')
71
+ mh = @mesh_tree.find('D005260')
72
72
  assert_equal :check_tag, mh.descriptor_class
73
73
  end
74
74
 
75
- it 'should have the correct original heading' do
76
- mh = MESH::Mesh.find('D000224')
75
+ def test_have_the_correct_original_heading
76
+ mh = @mesh_tree.find('D000224')
77
77
  assert_equal 'Addison Disease', mh.original_heading
78
- mh = MESH::Mesh.find('D000014')
78
+ mh = @mesh_tree.find('D000014')
79
79
  assert_equal 'Abnormalities, Drug-Induced', mh.original_heading
80
80
  end
81
81
 
82
- it 'should have anglicised original heading' do
83
- mh = MESH::Mesh.find('D001471')
82
+ def test_have_anglicised_original_heading
83
+ mh = @mesh_tree.find('D001471')
84
84
  assert_equal 'Barrett Esophagus', mh.original_heading
85
- assert_equal 'Barrett Oesophagus', mh.original_heading('en-GB')
85
+ assert_equal 'Barrett Oesophagus', mh.original_heading(:en_gb)
86
86
  end
87
87
 
88
- it 'should have natural language name' do
89
- mh = MESH::Mesh.find('D000224')
88
+ def test_have_natural_language_name
89
+ mh = @mesh_tree.find('D000224')
90
90
  assert_equal 'Addison Disease', mh.natural_language_name
91
- mh = MESH::Mesh.find('D000014')
91
+ mh = @mesh_tree.find('D000014')
92
92
  assert_equal 'Drug-Induced Abnormalities', mh.natural_language_name
93
93
  end
94
94
 
95
- it 'should have anglicised natural language name' do
96
- mh = MESH::Mesh.find('D001471')
95
+ def test_have_anglicised_natural_language_name
96
+ mh = @mesh_tree.find('D001471')
97
97
  assert_equal 'Barrett Esophagus', mh.natural_language_name
98
- assert_equal 'Barrett Oesophagus', mh.natural_language_name('en-GB')
98
+ assert_equal 'Barrett Oesophagus', mh.natural_language_name(:en_gb)
99
99
  end
100
100
 
101
- it 'should have the correct summary' do
102
- mh = MESH::Mesh.find('D000238')
101
+ def test_have_the_correct_summary
102
+ mh = @mesh_tree.find('D000238')
103
103
  assert_equal 'A benign tumor of the anterior pituitary in which the cells do not stain with acidic or basic dyes.', mh.summary
104
104
  end
105
105
 
106
- it 'should have anglicised summary' do
107
- mh = MESH::Mesh.find('D001471')
106
+ def test_have_anglicised_summary
107
+ mh = @mesh_tree.find('D001471')
108
108
  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
109
- 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')
109
+ 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)
110
110
  end
111
111
 
112
- it 'should have the correct entries' do
112
+ def test_have_the_correct_entries
113
113
  expected_entries = ['Activity Cycles', 'Ultradian Cycles', 'Activity Cycle', 'Cycle, Activity', 'Cycle, Ultradian', 'Cycles, Activity', 'Cycles, Ultradian', 'Ultradian Cycle']
114
114
  expected_entries.sort!
115
- mh = MESH::Mesh.find('D000204')
115
+ mh = @mesh_tree.find('D000204')
116
116
  assert_equal expected_entries, mh.entries
117
117
  end
118
118
 
119
- it 'should have anglicised entries' do
119
+ def test_have_anglicised_entries
120
120
  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']
121
121
  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']
122
+
122
123
  expected_entries.sort!
123
124
  expected_entries_en.sort!
124
- mh = MESH::Mesh.find('D001471')
125
- assert_equal expected_entries, mh.entries
126
- assert_equal expected_entries_en, mh.entries('en-GB')
125
+ mh = @mesh_tree.find('D001471')
126
+ assert_equal expected_entries.sort, mh.entries
127
+ assert_equal expected_entries_en.sort, mh.entries(:en_gb)
127
128
  end
128
129
 
129
- it 'should have the correct parent' do
130
- mh = MESH::Mesh.find('D000001')
130
+ def test_have_the_correct_parent
131
+ mh = @mesh_tree.find('D000001')
131
132
  assert_equal 1, mh.parents.length
132
133
  assert_equal 'D001583', mh.parents[0].unique_id
133
134
  end
134
135
 
135
- it 'should have the correct parents' do
136
- mh = MESH::Mesh.find('D000224')
137
- p1 = MESH::Mesh.find('D000309')
138
- p2 = MESH::Mesh.find('D001327')
136
+ def test_have_the_correct_parents
137
+ mh = @mesh_tree.find('D000224')
138
+ p1 = @mesh_tree.find('D000309')
139
+ p2 = @mesh_tree.find('D001327')
139
140
  assert_equal 2, mh.parents.length
140
141
  assert_includes mh.parents, p1
141
142
  assert_includes mh.parents, p2
142
143
  end
143
144
 
144
- it 'should have the correct children' do
145
- parent = MESH::Mesh.find_by_tree_number('C19.053.500')
146
- child1 = MESH::Mesh.find_by_tree_number('C19.053.500.263')
147
- child2 = MESH::Mesh.find_by_tree_number('C19.053.500.270')
148
- child3 = MESH::Mesh.find_by_tree_number('C19.053.500.480')
149
- child4 = MESH::Mesh.find_by_tree_number('C19.053.500.740')
145
+ def test_have_the_correct_children
146
+ parent = @mesh_tree.find_by_tree_number('C19.053.500')
147
+ child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
148
+ child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
149
+ child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
150
+ child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
150
151
 
151
152
  assert_equal 4, parent.children.length
152
153
  assert_includes parent.children, child1
@@ -155,41 +156,41 @@ module MESH
155
156
  assert_includes parent.children, child4
156
157
  end
157
158
 
158
- it 'should have the correct siblings' do
159
+ def test_have_the_correct_siblings
159
160
  skip
160
161
  end
161
162
 
162
- it 'should match on conditions for original_heading' do
163
- mh = MESH::Mesh.find('D001471')
163
+ def test_match_on_conditions_for_original_heading
164
+ mh = @mesh_tree.find('D001471')
164
165
  assert mh.matches(original_heading: /^Barrett Esophagus$/)
165
166
  end
166
167
 
167
- it 'should not match on incorrect condition for original_heading' do
168
- mh = MESH::Mesh.find('D001471')
168
+ def test_not_match_on_incorrect_condition_for_original_heading
169
+ mh = @mesh_tree.find('D001471')
169
170
  refute mh.matches(original_heading: /^Foo$/)
170
171
  end
171
172
 
172
- it 'should match on conditions for entries' do
173
- mh = MESH::Mesh.find('D001471')
173
+ def test_match_on_conditions_for_entries
174
+ mh = @mesh_tree.find('D001471')
174
175
  assert mh.matches(entries: /Metaplasia/)
175
176
  end
176
177
 
177
- it 'should not match on incorrect conditions for entries' do
178
- mh = MESH::Mesh.find('D001471')
178
+ def test_not_match_on_incorrect_conditions_for_entries
179
+ mh = @mesh_tree.find('D001471')
179
180
  refute mh.matches(entries: /Foo/)
180
181
  end
181
182
 
182
- it 'should match on descriptor class' do
183
- mh = MESH::Mesh.find('D000224')
183
+ def test_match_on_descriptor_class
184
+ mh = @mesh_tree.find('D000224')
184
185
  assert mh.matches(descriptor_class: :topical_descriptor)
185
186
  refute mh.matches(descriptor_class: :check_tag)
186
- mh = MESH::Mesh.find('D005260')
187
+ mh = @mesh_tree.find('D005260')
187
188
  assert mh.matches(descriptor_class: :check_tag)
188
189
  refute mh.matches(descriptor_class: :topical_descriptor)
189
190
  end
190
191
 
191
- it 'should match on conditions for tree numbers' do
192
- mh = MESH::Mesh.find('D001471')
192
+ def test_match_on_conditions_for_tree_numbers
193
+ mh = @mesh_tree.find('D001471')
193
194
  assert mh.matches(tree_numbers: /C06\.198\.102/)
194
195
  assert mh.matches(tree_numbers: /^C06\.198\.102$/)
195
196
  assert mh.matches(tree_numbers: /^C06/)
@@ -197,23 +198,23 @@ module MESH
197
198
  assert mh.matches(tree_numbers: /^C06\.405\.117\.102$/)
198
199
  end
199
200
 
200
- it 'should not match on incorrect conditions for tree numbers' do
201
- mh = MESH::Mesh.find('D001471')
201
+ def test_not_match_on_incorrect_conditions_for_tree_numbers
202
+ mh = @mesh_tree.find('D001471')
202
203
  refute mh.matches(tree_numbers: /Foo/)
203
204
  end
204
205
 
205
- it 'should match on conditions for summary' do
206
- mh = MESH::Mesh.find('D001471')
206
+ def test_match_on_conditions_for_summary
207
+ mh = @mesh_tree.find('D001471')
207
208
  assert mh.matches(summary: /the lower ESOPHAGUS resulting from chronic acid reflux \(ESOPHAGITIS, REFLUX\)\./)
208
209
  end
209
210
 
210
- it 'should not match on incorrect conditions for summary' do
211
- mh = MESH::Mesh.find('D001471')
211
+ def test_not_match_on_incorrect_conditions_for_summary
212
+ mh = @mesh_tree.find('D001471')
212
213
  refute mh.matches(summary: /Foo/)
213
214
  end
214
215
 
215
- it 'should match on conditions for useful' do
216
- mh = MESH::Mesh.find('D001471')
216
+ def test_match_on_conditions_for_useful
217
+ mh = @mesh_tree.find('D001471')
217
218
  begin
218
219
  mh.useful = true
219
220
  assert mh.matches(useful: true)
@@ -226,88 +227,88 @@ module MESH
226
227
  end
227
228
  end
228
229
 
229
- it 'should match on multiple conditions' do
230
- mh = MESH::Mesh.find('D001471')
230
+ def test_match_on_multiple_conditions
231
+ mh = @mesh_tree.find('D001471')
231
232
  assert mh.matches(original_heading: /^Barrett Esophagus$/, summary: /the lower ESOPHAGUS/)
232
233
  end
233
234
 
234
- it 'should not match on incorrect multiple conditions' do
235
- mh = MESH::Mesh.find('D001471')
235
+ def test_not_match_on_incorrect_multiple_conditions
236
+ mh = @mesh_tree.find('D001471')
236
237
  refute mh.matches(original_heading: /^Barrett Esophagus$/, summary: /Foo/)
237
238
  refute mh.matches(original_heading: /^Foo/, summary: /the lower ESOPHAGUS/)
238
239
  end
239
240
 
240
- it 'should match headings that occur in given text' do
241
+ def test_match_headings_that_occur_in_given_text
241
242
  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)
242
- expected = expected_ids.map { |id| MESH::Mesh.find(id) }
243
- matches = MESH::Mesh.match_in_text(@example_text)
243
+ expected = expected_ids.map { |id| @mesh_tree.find(id) }
244
+ matches = @mesh_tree.match_in_text(@example_text)
244
245
  actual = matches.map { |match| match[:heading] }.uniq
245
246
  assert_equal expected.sort, actual.sort
246
247
  end
247
248
 
248
- it 'should sort based on unique id' do
249
+ def test_sort_based_on_unique_id
249
250
  skip
250
251
  end
251
252
 
252
- it 'should only match the most specific matches in given text' do
253
- expected = MESH::Mesh.find('D054144')
254
- actual = MESH::Mesh.match_in_text('Diastolic Heart Failure')
253
+ def test_only_match_the_most_specific_matches_in_given_text
254
+ expected = @mesh_tree.find('D054144')
255
+ actual = @mesh_tree.match_in_text('Diastolic Heart Failure')
255
256
  assert_equal 1, actual.length
256
257
  assert_equal expected, actual.first[:heading]
257
258
  end
258
259
 
259
- it 'should only match useful headings that occur in given text' do
260
+ def test_only_match_useful_headings_that_occur_in_given_text
260
261
  expected_ids = %w(D001491 D001769 D001792 D001853 D002470 D002648 D002875 D002965 D003561 D003593 D003643 D004194 D004314 D004813 D004912 D005091 D005123 D005293 D005333 D005385 D005544 D005796 D006128 D006225 D006309 D006321 D006331 D006405 D007107 D007231 D007239 D007938 D007947 D008099 D008168 D008214 D008423 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 D015032 D015470 D015994 D015995 D016424 D017584 D017668 D018387 D018388 D019021 D019070 D019368 D019369 D032882 D036801 D038042 D041905 D052016 D054198)
261
262
 
262
263
  not_useful_ids = %w(D007246 D002477 D014960 D008533 D016433 D006664 D055016 D002999 D007223)
263
264
  begin
264
- not_useful_ids.each { |id| MESH::Mesh.find(id).useful = false }
265
+ not_useful_ids.each { |id| @mesh_tree.find(id).useful = false }
265
266
 
266
- expected = expected_ids.map { |id| MESH::Mesh.find(id) }
267
- matches = MESH::Mesh.match_in_text(@example_text)
267
+ expected = expected_ids.map { |id| @mesh_tree.find(id) }
268
+ matches = @mesh_tree.match_in_text(@example_text)
268
269
  actual = matches.map { |match| match[:heading] }.uniq
269
270
  assert_equal expected, actual
270
271
  ensure
271
- not_useful_ids.each { |id| MESH::Mesh.find(id).useful = true }
272
+ not_useful_ids.each { |id| @mesh_tree.find(id).useful = true }
272
273
  end
273
274
  end
274
275
 
275
- it 'should match headings at start of text' do
276
+ def test_match_headings_at_start_of_text
276
277
  text = 'Leukemia, lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium leo diam, quis adipiscing purus bibendum eu.'
277
- matches = MESH::Mesh.match_in_text(text)
278
+ matches = @mesh_tree.match_in_text(text)
278
279
  assert_equal 1, matches.length
279
- assert_equal MESH::Mesh.find('D007938'), matches[0][:heading]
280
+ assert_equal @mesh_tree.find('D007938'), matches[0][:heading]
280
281
  end
281
282
 
282
- it 'should match headings at end of text' do
283
+ def test_match_headings_at_end_of_text
283
284
  text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium leo diam, quis adipiscing purus bibendum eu leukemia'
284
- matches = MESH::Mesh.match_in_text(text)
285
+ matches = @mesh_tree.match_in_text(text)
285
286
  assert_equal 1, matches.length
286
- assert_equal MESH::Mesh.find('D007938'), matches[0][:heading]
287
+ assert_equal @mesh_tree.find('D007938'), matches[0][:heading]
287
288
  end
288
289
 
289
- it 'should return no matches when given nil text' do
290
- assert_equal [], MESH::Mesh.match_in_text(nil)
290
+ def test_return_no_matches_when_given_nil_text
291
+ assert_equal [], @mesh_tree.match_in_text(nil)
291
292
  end
292
293
 
293
- it 'should only match uppercase entries with uppercase text' do
294
+ def test_only_match_uppercase_entries_with_uppercase_text
294
295
  text = 'Lorem amet, consectetur adipiscing elit. Donec pretium ATP leo diam, quis adipiscing purus bibendum.'
295
- matches = MESH::Mesh.match_in_text(text)
296
+ matches = @mesh_tree.match_in_text(text)
296
297
  assert_equal 1, matches.length
297
- assert_equal MESH::Mesh.find('D000255'), matches[0][:heading]
298
+ assert_equal @mesh_tree.find('D000255'), matches[0][:heading]
298
299
  text = 'Lorem ipsum consectetur adipiscing elit. Donec pretium atp leo diam, quis adipiscing purus bibendum.'
299
- assert_equal [], MESH::Mesh.match_in_text(text)
300
+ assert_equal [], @mesh_tree.match_in_text(text)
300
301
  end
301
302
 
302
- it 'should match anglicised terms in text' do
303
+ def test_match_anglicised_terms_in_text
303
304
  text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium leo diam, quis adipiscing purus bibendum eu leukaemia'
304
- matches = MESH::Mesh.match_in_text(text)
305
+ matches = @mesh_tree.match_in_text(text)
305
306
  assert_equal 1, matches.length
306
- assert_equal MESH::Mesh.find('D007938'), matches[0][:heading]
307
+ assert_equal @mesh_tree.find('D007938'), matches[0][:heading]
307
308
  end
308
309
 
309
- it 'should allow headings to be marked as not useful' do
310
- mh = MESH::Mesh.find('D055550')
310
+ def test_allow_headings_to_be_marked_as_not_useful
311
+ mh = @mesh_tree.find('D055550')
311
312
  mh.useful = true
312
313
  assert mh.useful
313
314
  mh.useful = false
@@ -316,91 +317,91 @@ module MESH
316
317
  assert mh.useful
317
318
  end
318
319
 
319
- it 'should allow headings to be found with a where() match on original_heading' do
320
- expected = [MESH::Mesh.find('D003561'), MESH::Mesh.find('D016238')]
321
- actual = MESH::Mesh.where(original_heading: /^Cyta/)
320
+ def test_allow_headings_to_be_found_with_a_where_match_on_original_heading
321
+ expected = [@mesh_tree.find('D003561'), @mesh_tree.find('D016238')]
322
+ actual = @mesh_tree.where(original_heading: /^Cyta/)
322
323
  assert_equal expected, actual
323
324
  end
324
325
 
325
- it 'should match on entries in where()' do
326
+ def test_match_on_entries_in_where
326
327
  expected_ids = %w( D002397 D003064 D003400 D003532 D004284 D004289 D004555 D005412 D006054 D006196 D007059 D007497 D007695 D009990 D010473 D012091 D012487 D012758 D013215 D015027 D020410 D023721 D023761 D023781 D024541 D029961 D037401 D037462 D048251 D049832 D052656 D057096 )
327
- expected = expected_ids.map { |id| MESH::Mesh.find(id) }
328
- actual = MESH::Mesh.where(entries: /fish/)
328
+ expected = expected_ids.map { |id| @mesh_tree.find(id) }
329
+ actual = @mesh_tree.where(entries: /fish/)
329
330
  assert_equal expected, actual
330
331
  end
331
332
 
332
- it 'should match on tree numbers in where()' do
333
+ def test_match_on_tree_numbers_in_where
333
334
  expected_ids = %w( D000005 D001415 D010388 D013909 )
334
- expected = expected_ids.map { |id| MESH::Mesh.find(id) }
335
- actual = MESH::Mesh.where(tree_numbers: /^A01\.923\.[0-9]{3}$/)
335
+ expected = expected_ids.map { |id| @mesh_tree.find(id) }
336
+ actual = @mesh_tree.where(tree_numbers: /^A01\.923\.[0-9]{3}$/)
336
337
  assert_equal expected, actual
337
338
  end
338
339
 
339
- it 'should match on useful in where' do
340
- expected = [MESH::Mesh.find('D012000'), MESH::Mesh.find('D064906'), MESH::Mesh.find('D064966')]
340
+ def test_match_on_useful_in_where
341
+ expected = [@mesh_tree.find('D012000'), @mesh_tree.find('D064906'), @mesh_tree.find('D064966')]
341
342
  begin
342
343
  expected.each { |mh| mh.useful = false }
343
- actual = MESH::Mesh.where(useful: false)
344
+ actual = @mesh_tree.where(useful: false)
344
345
  assert_equal expected, actual
345
346
  ensure
346
347
  expected.each { |mh| mh.useful = true }
347
348
  end
348
349
  end
349
350
 
350
- it 'should match on descriptor class in where' do
351
- expected = [MESH::Mesh.find('D012000'), MESH::Mesh.find('D064906'), MESH::Mesh.find('D064966')]
351
+ def test_match_on_descriptor_class_in_where
352
+ expected = [@mesh_tree.find('D012000'), @mesh_tree.find('D064906'), @mesh_tree.find('D064966')]
352
353
  begin
353
354
  expected.each { |mh| mh.descriptor_class = :foo }
354
- actual = MESH::Mesh.where(descriptor_class: :foo)
355
+ actual = @mesh_tree.where(descriptor_class: :foo)
355
356
  assert_equal expected, actual
356
357
  ensure
357
358
  expected.each { |mh| mh.descriptor_class = :topical_descriptor }
358
359
  end
359
360
  end
360
361
 
361
- it 'should only include useful headings in .each' do
362
+ def test_only_include_useful_headings_in_each
362
363
  begin
363
- MESH::Mesh.each do |mh|
364
+ @mesh_tree.each do |mh|
364
365
  mh.useful = false
365
366
  end
366
- MESH::Mesh.where(unique_id: /^D0000/).each do |mh|
367
+ @mesh_tree.where(unique_id: /^D0000/).each do |mh|
367
368
  mh.useful = true
368
369
  end
369
370
  count = 0
370
- MESH::Mesh.each do |mh|
371
+ @mesh_tree.each do |mh|
371
372
  assert mh.useful
372
373
  count += 1
373
374
  end
374
375
  assert_equal 95, count
375
376
  ensure
376
- MESH::Mesh.where(useful: false).each do |mh|
377
+ @mesh_tree.where(useful: false).each do |mh|
377
378
  mh.useful = true
378
379
  end
379
380
  end
380
381
  end
381
382
 
382
- it 'should know its deepest position in the tree' do
383
+ def test_know_its_deepest_position_in_the_tree
383
384
  #single tree numbers
384
- assert_equal 1, MESH::Mesh.find('D002319').deepest_position
385
- assert_equal 2, MESH::Mesh.find('D001808').deepest_position
386
- assert_equal 3, MESH::Mesh.find('D001158').deepest_position
387
- assert_equal 4, MESH::Mesh.find('D001981').deepest_position
385
+ assert_equal 1, @mesh_tree.find('D002319').deepest_position
386
+ assert_equal 2, @mesh_tree.find('D001808').deepest_position
387
+ assert_equal 3, @mesh_tree.find('D001158').deepest_position
388
+ assert_equal 4, @mesh_tree.find('D001981').deepest_position
388
389
  end
389
390
 
390
- it 'should know its shallowest position in the tree' do
391
+ def test_know_its_shallowest_position_in_the_tree
391
392
  #single tree numbers
392
- assert_equal 1, MESH::Mesh.find('D002319').shallowest_position
393
- assert_equal 2, MESH::Mesh.find('D001808').shallowest_position
394
- assert_equal 3, MESH::Mesh.find('D001158').shallowest_position
395
- assert_equal 4, MESH::Mesh.find('D001981').shallowest_position
393
+ assert_equal 1, @mesh_tree.find('D002319').shallowest_position
394
+ assert_equal 2, @mesh_tree.find('D001808').shallowest_position
395
+ assert_equal 3, @mesh_tree.find('D001158').shallowest_position
396
+ assert_equal 4, @mesh_tree.find('D001981').shallowest_position
396
397
  end
397
398
 
398
- it 'should know if one heading is the descendant of another' do
399
- parent = MESH::Mesh.find('D002319')
400
- child = MESH::Mesh.find('D001808')
401
- grandchild = MESH::Mesh.find('D001158')
402
- great_grandchild = MESH::Mesh.find('D001981')
403
- unrelated = MESH::Mesh.find('D008091')
399
+ def test_know_if_one_heading_is_the_descendant_of_another
400
+ parent = @mesh_tree.find('D002319')
401
+ child = @mesh_tree.find('D001808')
402
+ grandchild = @mesh_tree.find('D001158')
403
+ great_grandchild = @mesh_tree.find('D001981')
404
+ unrelated = @mesh_tree.find('D008091')
404
405
 
405
406
  refute parent.has_descendant(parent), 'should not consider itself a desecendant'
406
407
  assert parent.has_descendant(child), "should consider child #{child.inspect} a descendant of #{parent.inspect} in #{parent.children}"
@@ -409,12 +410,12 @@ module MESH
409
410
  refute parent.has_descendant(unrelated), 'should not consider an unrelated heading a descendant'
410
411
  end
411
412
 
412
- it 'should know if one heading is the ancestor of another' do
413
- child = MESH::Mesh.find('D001981')
414
- parent = MESH::Mesh.find('D001158')
415
- grandparent = MESH::Mesh.find('D001808')
416
- great_grandparent = MESH::Mesh.find('D002319')
417
- unrelated = MESH::Mesh.find('D008091')
413
+ def test_know_if_one_heading_is_the_ancestor_of_another
414
+ child = @mesh_tree.find('D001981')
415
+ parent = @mesh_tree.find('D001158')
416
+ grandparent = @mesh_tree.find('D001808')
417
+ great_grandparent = @mesh_tree.find('D002319')
418
+ unrelated = @mesh_tree.find('D008091')
418
419
 
419
420
  refute child.has_ancestor(child), 'should not consider itself an ancestor'
420
421
  assert child.has_ancestor(parent), "should consider parent #{parent.inspect} an ancestor of #{child.inspect} in #{child.parents}"
@@ -423,13 +424,13 @@ module MESH
423
424
  refute child.has_ancestor(unrelated), 'should not consider an unrelated heading an ancestor'
424
425
  end
425
426
 
426
- it 'should know if headings are siblings at the same level below a common parent' do
427
- parent = MESH::Mesh.find_by_tree_number('C19.053.500')
428
- child1 = MESH::Mesh.find_by_tree_number('C19.053.500.263')
429
- child2 = MESH::Mesh.find_by_tree_number('C19.053.500.270')
430
- child3 = MESH::Mesh.find_by_tree_number('C19.053.500.480')
431
- child4 = MESH::Mesh.find_by_tree_number('C19.053.500.740')
432
- unrelated = MESH::Mesh.find('D008091')
427
+ def test_know_if_headings_are_siblings_at_the_same_level_below_a_common_parent
428
+ parent = @mesh_tree.find_by_tree_number('C19.053.500')
429
+ child1 = @mesh_tree.find_by_tree_number('C19.053.500.263')
430
+ child2 = @mesh_tree.find_by_tree_number('C19.053.500.270')
431
+ child3 = @mesh_tree.find_by_tree_number('C19.053.500.480')
432
+ child4 = @mesh_tree.find_by_tree_number('C19.053.500.740')
433
+ unrelated = @mesh_tree.find('D008091')
433
434
  children = [child1, child2, child3, child4]
434
435
 
435
436
  children.each { |c| refute parent.sibling?(c) }
@@ -442,15 +443,17 @@ module MESH
442
443
  children.each { |c| refute c.sibling?(unrelated) }
443
444
  end
444
445
 
445
- it 'should override inspect to prevent issues in test diagnostics' do
446
- mh = MESH::Mesh.find('D001471')
446
+ def test_override_inspect_to_prevent_issues_in_test_diagnostics
447
+ mh = @mesh_tree.find('D001471')
447
448
  expected = "#{mh.unique_id}, #{mh.original_heading}, [#{mh.tree_numbers.join(',')}]"
448
449
  assert_equal expected, mh.inspect
449
450
  end
450
451
 
451
- before do
452
-
453
- @example_text = 'Leukaemia in Downs Syndrome
452
+ def setup
453
+ @@mesh_tree ||= MESH::Tree.new
454
+ @@mesh_tree.load_translation(:en_gb)
455
+ @mesh_tree = @@mesh_tree
456
+ @example_text ||= 'Leukaemia in Downs Syndrome
454
457
  Overview
455
458
  Downs Syndrome Leukaemia The link between Downs Syndrome and Leukaemia
456
459
  Epidemiology
@@ -619,9 +622,6 @@ why are GATA1 mutations so relatively common in children with DS It has been po
619
622
  thirdly, what is the second-hit We know that there must be a second genetic event, with GATA1 mutation being the first, but we do not know what this is yet.NB: GATA1 mutation is the first mutation for DS-AMKL.AML failure of treatment usually due to toxicity due to mucositis and infection. Resistant disease and relapse are rare.
620
623
  ALL there is no increased sensitivity to treatment, but there is increased risk of toxicity. Cannot reduce the dose because of the high risk of relapse and so the emphasis is now on improving supportive care.
621
624
  '
622
-
623
625
  end
624
-
625
-
626
626
  end
627
627
  end