test/tree_test.rb in mesh-medical-subject-headings-2.2.1 vs test/tree_test.rb in mesh-medical-subject-headings-2.3.0

- old
+ new

@@ -41,23 +41,23 @@ end def test_find_by_entry expected_entries = [ - 'Adult Reye Syndrome', - 'Adult Reye\'s Syndrome', - 'Fatty Liver with Encephalopathy', - 'Reye Johnson Syndrome', - 'Reye Like Syndrome', - 'Reye Syndrome', - 'Reye Syndrome, Adult', - 'Reye\'s Like Syndrome', - 'Reye\'s Syndrome', - 'Reye\'s Syndrome, Adult', - 'Reye\'s-Like Syndrome', - 'Reye-Johnson Syndrome', - 'Reye-Like Syndrome' + 'Adult Reye Syndrome', + 'Adult Reye\'s Syndrome', + 'Fatty Liver with Encephalopathy', + 'Reye Johnson Syndrome', + 'Reye Like Syndrome', + 'Reye Syndrome', + 'Reye Syndrome, Adult', + 'Reye\'s Like Syndrome', + 'Reye\'s Syndrome', + 'Reye\'s Syndrome, Adult', + 'Reye\'s-Like Syndrome', + 'Reye-Johnson Syndrome', + 'Reye-Like Syndrome' ] entries_to_test = expected_entries.flat_map do |e| [e, e.upcase, e.downcase, " #{e.downcase} ", "\n\n\t #{e.downcase}\t "] end @@ -71,10 +71,32 @@ def test_find_by_entry_doesnt_match assert_nil @mesh_tree.find_by_entry('foo') end + def test_find_by_entry_word + expected_ids = %w(D000003) + actual = @mesh_tree.find_by_entry_word('abattoir') + actual_ids = actual.map { |mh| mh.unique_id } + assert_equal expected_ids, actual_ids, 'Should return all headings with this word in any entry' + end + + def test_find_by_entry_word_case_insensitive + skip 'find by word does not support case insensitive searches' + # expected_ids = %w(D000003) + # actual = @mesh_tree.find_by_entry_word('AbaTToir') + # actual_ids = actual.map { |mh| mh.unique_id } + # assert_equal expected_ids, actual_ids, 'Should return all headings with this word in any entry' + end + + def test_find_by_anglicised_entry_word + expected_ids = %w(D001471 D004938 D004947 D015154) + actual = @mesh_tree.find_by_entry_word('oesophagus') + actual_ids = actual.map { |mh| mh.unique_id } + assert_equal expected_ids, actual_ids, 'Should return all headings with this word in any entry' + end + def test_linkifies_all_summaries mesh = MESH::Tree.new mesh.linkify_summaries do |text, heading| "<bar>#{text.downcase}</bar>" end @@ -105,10 +127,10 @@ not_useful_ids.each { |id| @mesh_tree.find(id).useful = false } expected = expected_ids.map { |id| @mesh_tree.find(id) } matches = @mesh_tree.match_in_text(@example_text) actual = matches.map { |match| match[:heading] }.uniq - assert_equal expected, actual + assert_equal expected.sort, actual.sort ensure not_useful_ids.each { |id| @mesh_tree.find(id).useful = true } end end