This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_tests.rb
103 lines (85 loc) · 2.23 KB
/
string_tests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'pp'
full_search = lambda {
@found = []
@found_a = []
OmniSearch::Search::Strategy.run(@term).each do |set|
set.results.each do |result|
@found << result.value.downcase
@found_a << "#{result.value.downcase} #{result.score}"
end
end
}
test_search = lambda {
@found = []
@found_a = []
OmniSearch::Engines::StringDistance.score(@search_index, @term, @cutoff).each {|result|
@found << result.value.downcase
@found_a << "#{result.value.downcase} #{result.score}"
}
}
@search = test_search
runner = lambda do
@missing = {}
@overage = {}
def given(*args)
@search_index = []
args.each do |item|
@search_index << {value: item, label: item}
end
end
def my_search(term)
@term = term
@search.call
@found
end
def has(result)
unless @found.include?(result) == true
p "missing #{result}"
@missing[@term] ||= []
@missing[@term] << result
end
end
def has_no(result)
where = @found.index(result)
if where
p "shouldn't have #{result}"
@overage[@term] ||= []
@overage[@term] << @found_a[where]
end
end
@search = test_search
given 'primary care', 'mary rose'
my_search 'mary'
has 'mary rose'
has_no 'primary care'
given 'mary rose'
my_search 'mari rose'
has 'mary rose'
given 'Robert Marsan', 'Marianne Rochester', 'marianne rose'
my_search 'mary'
has_no 'robert marsan'
given 'primary care', 'cancer care', 'Preschooler test or procedure preparation', 'palliative care'
my_search 'primary care'
has_no 'cancer care'
has_no 'Preschooler test or procedure preparation'
has_no 'palliative care'
given 'robert marsan', 'marianne rochester', 'marianne rose', "blood and marrow transplantation", "del mar"
my_search 'mary rose'
has_no 'del_mar'
has_no 'blood and marrow transplantation'
given 'recognizing medical emergencies', "medical records"
my_search 'medical records'
has 'medical records'
has_no 'recognizing medical emergencies'
if OmniSearch::Indexes.list != []
@search = full_search
my_search 'mari rose'
has 'mary rose'
end
puts "Missing: "
pp @missing
puts "Overage: "
pp @overage
end
@cutoff = 0.55
runner.call