linkage 0.0.8 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/Gemfile +1 -19
- data/Gemfile-java +3 -0
- data/README.markdown +88 -34
- data/Rakefile +16 -15
- data/TODO +4 -0
- data/lib/linkage/comparator.rb +139 -144
- data/lib/linkage/comparators/compare.rb +236 -29
- data/lib/linkage/comparators/strcompare.rb +85 -0
- data/lib/linkage/comparators/within.rb +24 -20
- data/lib/linkage/configuration.rb +44 -466
- data/lib/linkage/dataset.rb +28 -127
- data/lib/linkage/exceptions.rb +5 -0
- data/lib/linkage/field.rb +6 -37
- data/lib/linkage/field_set.rb +3 -3
- data/lib/linkage/match_recorder.rb +22 -0
- data/lib/linkage/match_set.rb +34 -0
- data/lib/linkage/match_sets/csv.rb +39 -0
- data/lib/linkage/match_sets/database.rb +45 -0
- data/lib/linkage/matcher.rb +30 -0
- data/lib/linkage/result_set.rb +25 -110
- data/lib/linkage/result_sets/csv.rb +54 -0
- data/lib/linkage/result_sets/database.rb +42 -0
- data/lib/linkage/runner.rb +57 -16
- data/lib/linkage/score_recorder.rb +30 -0
- data/lib/linkage/score_set.rb +49 -0
- data/lib/linkage/score_sets/csv.rb +64 -0
- data/lib/linkage/score_sets/database.rb +77 -0
- data/lib/linkage/version.rb +1 -1
- data/lib/linkage.rb +14 -17
- data/linkage.gemspec +13 -1
- data/linkage.gemspec-java +32 -0
- data/test/helper.rb +30 -23
- data/test/integration/test_cross_linkage.rb +46 -25
- data/test/integration/test_database_result_set.rb +55 -0
- data/test/integration/test_dual_linkage.rb +19 -94
- data/test/integration/test_self_linkage.rb +100 -203
- data/test/integration/test_within_comparator.rb +24 -77
- data/test/unit/comparators/test_compare.rb +254 -50
- data/test/unit/comparators/test_strcompare.rb +45 -0
- data/test/unit/comparators/test_within.rb +14 -26
- data/test/unit/match_sets/test_csv.rb +78 -0
- data/test/unit/match_sets/test_database.rb +63 -0
- data/test/unit/result_sets/test_csv.rb +111 -0
- data/test/unit/result_sets/test_database.rb +68 -0
- data/test/unit/score_sets/test_csv.rb +151 -0
- data/test/unit/score_sets/test_database.rb +149 -0
- data/test/unit/test_comparator.rb +46 -83
- data/test/unit/test_comparators.rb +4 -0
- data/test/unit/test_configuration.rb +99 -145
- data/test/unit/test_dataset.rb +52 -73
- data/test/unit/test_field.rb +4 -55
- data/test/unit/test_field_set.rb +6 -6
- data/test/unit/test_match_recorder.rb +23 -0
- data/test/unit/test_match_set.rb +23 -0
- data/test/unit/test_match_sets.rb +4 -0
- data/test/unit/test_matcher.rb +44 -0
- data/test/unit/test_result_set.rb +24 -223
- data/test/unit/test_result_sets.rb +4 -0
- data/test/unit/test_runner.rb +122 -17
- data/test/unit/test_runners.rb +4 -0
- data/test/unit/test_score_recorder.rb +25 -0
- data/test/unit/test_score_set.rb +37 -0
- data/test/unit/test_score_sets.rb +4 -0
- metadata +183 -90
- data/Gemfile.lock +0 -92
- data/lib/linkage/comparators/binary.rb +0 -12
- data/lib/linkage/data.rb +0 -175
- data/lib/linkage/decollation.rb +0 -93
- data/lib/linkage/expectation.rb +0 -21
- data/lib/linkage/expectations/exhaustive.rb +0 -63
- data/lib/linkage/expectations/simple.rb +0 -168
- data/lib/linkage/function.rb +0 -148
- data/lib/linkage/functions/binary.rb +0 -30
- data/lib/linkage/functions/cast.rb +0 -54
- data/lib/linkage/functions/length.rb +0 -29
- data/lib/linkage/functions/strftime.rb +0 -33
- data/lib/linkage/functions/trim.rb +0 -30
- data/lib/linkage/group.rb +0 -55
- data/lib/linkage/meta_object.rb +0 -139
- data/lib/linkage/runner/single_threaded.rb +0 -187
- data/lib/linkage/utils.rb +0 -164
- data/lib/linkage/warnings.rb +0 -5
- data/test/integration/test_collation.rb +0 -45
- data/test/integration/test_configuration.rb +0 -268
- data/test/integration/test_dataset.rb +0 -116
- data/test/integration/test_functions.rb +0 -88
- data/test/integration/test_result_set.rb +0 -85
- data/test/integration/test_scoring.rb +0 -84
- data/test/unit/expectations/test_exhaustive.rb +0 -111
- data/test/unit/expectations/test_simple.rb +0 -303
- data/test/unit/functions/test_binary.rb +0 -54
- data/test/unit/functions/test_cast.rb +0 -98
- data/test/unit/functions/test_length.rb +0 -52
- data/test/unit/functions/test_strftime.rb +0 -60
- data/test/unit/functions/test_trim.rb +0 -43
- data/test/unit/runner/test_single_threaded.rb +0 -12
- data/test/unit/test_data.rb +0 -445
- data/test/unit/test_decollation.rb +0 -201
- data/test/unit/test_function.rb +0 -233
- data/test/unit/test_group.rb +0 -38
- data/test/unit/test_meta_object.rb +0 -208
- data/test/unit/test_utils.rb +0 -341
@@ -1,236 +1,37 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestResultSet < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:groups_table_name => :groups,
|
10
|
-
:original_groups_table_name => :original_groups,
|
11
|
-
:scores_table_name => :scores,
|
12
|
-
:matches_table_name => :matches
|
13
|
-
})
|
14
|
-
@database = stub('database')
|
15
|
-
Sequel.stubs(:connect).with('foo://bar', :blah => 'junk').returns(@database)
|
4
|
+
test "score_set raises NotImplementedError" do
|
5
|
+
result_set = Linkage::ResultSet.new
|
6
|
+
assert_raises(NotImplementedError) do
|
7
|
+
result_set.score_set
|
8
|
+
end
|
16
9
|
end
|
17
10
|
|
18
|
-
test "
|
19
|
-
result_set = Linkage::ResultSet.new
|
11
|
+
test "match_set raises NotImplementedError" do
|
12
|
+
result_set = Linkage::ResultSet.new
|
13
|
+
assert_raises(NotImplementedError) do
|
14
|
+
result_set.match_set
|
15
|
+
end
|
20
16
|
end
|
21
17
|
|
22
|
-
test
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
:values => {:foo => 'bar '},
|
27
|
-
:decollated_values => {:foo => 'BAR'}
|
28
|
-
})
|
29
|
-
|
30
|
-
groups_import_buffer = stub('groups import buffer')
|
31
|
-
groups_dataset = stub('groups dataset')
|
32
|
-
@database.stubs(:[]).with(:groups).returns(groups_dataset)
|
33
|
-
Linkage::ImportBuffer.stubs(:new).with(groups_dataset, [:id, :foo]).
|
34
|
-
returns(groups_import_buffer)
|
35
|
-
|
36
|
-
original_groups_import_buffer = stub('original groups import buffer')
|
37
|
-
original_groups_dataset = stub('original groups dataset')
|
38
|
-
@database.stubs(:[]).with(:original_groups).returns(original_groups_dataset)
|
39
|
-
Linkage::ImportBuffer.stubs(:new).with(original_groups_dataset, [:id, :foo]).
|
40
|
-
returns(original_groups_import_buffer)
|
41
|
-
|
42
|
-
groups_import_buffer.expects(:add).with([1, 'BAR'])
|
43
|
-
original_groups_import_buffer.expects(:add).with([1, 'bar '])
|
44
|
-
result_set.add_group(group)
|
45
|
-
end
|
46
|
-
|
47
|
-
test "#flush! flushes groups dataset" do
|
48
|
-
result_set = Linkage::ResultSet.new(@config)
|
49
|
-
|
50
|
-
group = stub('group', {
|
51
|
-
:values => {:foo => 'bar '},
|
52
|
-
:decollated_values => {:foo => 'BAR'}
|
53
|
-
})
|
54
|
-
|
55
|
-
groups_import_buffer = stub('groups import buffer')
|
56
|
-
groups_dataset = stub('groups dataset')
|
57
|
-
@database.stubs(:[]).with(:groups).returns(groups_dataset)
|
58
|
-
Linkage::ImportBuffer.stubs(:new).with(groups_dataset, [:id, :foo]).
|
59
|
-
returns(groups_import_buffer)
|
60
|
-
|
61
|
-
original_groups_import_buffer = stub('original groups import buffer')
|
62
|
-
original_groups_dataset = stub('original groups dataset')
|
63
|
-
@database.stubs(:[]).with(:original_groups).returns(original_groups_dataset)
|
64
|
-
Linkage::ImportBuffer.stubs(:new).with(original_groups_dataset, [:id, :foo]).
|
65
|
-
returns(original_groups_import_buffer)
|
66
|
-
|
67
|
-
groups_import_buffer.stubs(:add)
|
68
|
-
original_groups_import_buffer.stubs(:add)
|
69
|
-
result_set.add_group(group)
|
70
|
-
|
71
|
-
groups_import_buffer.expects(:flush)
|
72
|
-
original_groups_import_buffer.expects(:flush)
|
73
|
-
result_set.flush!
|
74
|
-
end
|
75
|
-
|
76
|
-
test "#add_group doesn't create copies when decollation is not needed" do
|
77
|
-
@config.stubs(:decollation_needed?).returns(false)
|
78
|
-
result_set = Linkage::ResultSet.new(@config)
|
79
|
-
|
80
|
-
group = stub('group', :values => {:foo => 'bar '})
|
81
|
-
|
82
|
-
groups_import_buffer = stub('groups import buffer')
|
83
|
-
groups_dataset = stub('groups dataset', :first_source_table => :groups, :db => @database)
|
84
|
-
@database.stubs(:[]).with(:groups).returns(groups_dataset)
|
85
|
-
Linkage::ImportBuffer.stubs(:new).with(groups_dataset, [:id, :foo]).
|
86
|
-
returns(groups_import_buffer)
|
87
|
-
|
88
|
-
original_groups_dataset = stub('original groups dataset', :first_source_table => :original_groups, :db => @database)
|
89
|
-
@database.stubs(:[]).with(:original_groups).returns(original_groups_dataset)
|
90
|
-
Linkage::ImportBuffer.expects(:new).with(original_groups_dataset, [:id, :foo]).never
|
91
|
-
|
92
|
-
groups_import_buffer.expects(:add).with([1, 'bar '])
|
93
|
-
result_set.add_group(group)
|
94
|
-
end
|
95
|
-
|
96
|
-
test "#add_score adds to score buffer" do
|
97
|
-
result_set = Linkage::ResultSet.new(@config)
|
98
|
-
scores_dataset = stub('scores dataset')
|
99
|
-
@database.stubs(:[]).with(:scores).returns(scores_dataset)
|
100
|
-
scores_import_buffer = stub('scores import buffer')
|
101
|
-
Linkage::ImportBuffer.expects(:new).
|
102
|
-
with(scores_dataset, [:comparator_id, :record_1_id, :record_2_id, :score]).
|
103
|
-
returns(scores_import_buffer)
|
104
|
-
scores_import_buffer.expects(:add).with([0, 1, 2, 123])
|
105
|
-
scores_import_buffer.expects(:add).with([1, 1, 2, 456])
|
106
|
-
result_set.add_score(0, 1, 2, 123)
|
107
|
-
result_set.add_score(1, 1, 2, 456)
|
108
|
-
end
|
109
|
-
|
110
|
-
test "#flush! flushes score buffer" do
|
111
|
-
result_set = Linkage::ResultSet.new(@config)
|
112
|
-
scores_dataset = stub('scores dataset')
|
113
|
-
@database.stubs(:[]).with(:scores).returns(scores_dataset)
|
114
|
-
scores_import_buffer = stub('scores import buffer')
|
115
|
-
Linkage::ImportBuffer.stubs(:new).
|
116
|
-
with(scores_dataset, [:comparator_id, :record_1_id, :record_2_id, :score]).
|
117
|
-
returns(scores_import_buffer)
|
118
|
-
scores_import_buffer.stubs(:add)
|
119
|
-
result_set.add_score(0, 1, 2, 123)
|
120
|
-
|
121
|
-
scores_import_buffer.expects(:flush)
|
122
|
-
result_set.flush!
|
123
|
-
end
|
124
|
-
|
125
|
-
test "#add_match adds to match buffer" do
|
126
|
-
result_set = Linkage::ResultSet.new(@config)
|
127
|
-
matches_dataset = stub('matches dataset')
|
128
|
-
@database.stubs(:[]).with(:matches).returns(matches_dataset)
|
129
|
-
matches_import_buffer = stub('matches import buffer')
|
130
|
-
Linkage::ImportBuffer.expects(:new).
|
131
|
-
with(matches_dataset, [:record_1_id, :record_2_id, :total_score]).
|
132
|
-
returns(matches_import_buffer)
|
133
|
-
matches_import_buffer.expects(:add).with([1, 2, 123])
|
134
|
-
matches_import_buffer.expects(:add).with([2, 3, 456])
|
135
|
-
result_set.add_match(1, 2, 123)
|
136
|
-
result_set.add_match(2, 3, 456)
|
137
|
-
end
|
138
|
-
|
139
|
-
test "#flush! flushes match buffer" do
|
140
|
-
result_set = Linkage::ResultSet.new(@config)
|
141
|
-
matches_dataset = stub('matches dataset')
|
142
|
-
@database.stubs(:[]).with(:matches).returns(matches_dataset)
|
143
|
-
matches_import_buffer = stub('matches import buffer')
|
144
|
-
Linkage::ImportBuffer.stubs(:new).
|
145
|
-
with(matches_dataset, [:record_1_id, :record_2_id, :total_score]).
|
146
|
-
returns(matches_import_buffer)
|
147
|
-
matches_import_buffer.stubs(:add)
|
148
|
-
result_set.add_match(1, 2, 123)
|
149
|
-
|
150
|
-
matches_import_buffer.expects(:flush)
|
151
|
-
result_set.flush!
|
152
|
-
end
|
153
|
-
|
154
|
-
test "#create_tables! uses custom table names" do
|
155
|
-
@config.stubs({
|
156
|
-
:groups_table_name => :foo_groups,
|
157
|
-
:original_groups_table_name => :foo_original_groups,
|
158
|
-
:scores_table_name => :foo_scores,
|
159
|
-
:matches_table_name => :foo_matches,
|
160
|
-
:groups_table_needed? => true,
|
161
|
-
:decollation_needed? => true,
|
162
|
-
:scores_table_needed? => true,
|
163
|
-
:groups_table_schema => [],
|
164
|
-
:scores_table_schema => [],
|
165
|
-
:matches_table_schema => []
|
166
|
-
})
|
167
|
-
result_set = Linkage::ResultSet.new(@config)
|
168
|
-
@database.expects(:create_table).with(:foo_groups)
|
169
|
-
@database.expects(:create_table).with(:foo_original_groups)
|
170
|
-
@database.expects(:create_table).with(:foo_scores)
|
171
|
-
@database.expects(:create_table).with(:foo_matches)
|
172
|
-
result_set.create_tables!
|
173
|
-
end
|
174
|
-
|
175
|
-
test "#add_group uses custom table names" do
|
176
|
-
@config.stubs({
|
177
|
-
:groups_table_name => :foo_groups,
|
178
|
-
:original_groups_table_name => :foo_original_groups
|
179
|
-
})
|
180
|
-
result_set = Linkage::ResultSet.new(@config)
|
181
|
-
|
182
|
-
group = stub('group', {
|
183
|
-
:values => {:foo => 'bar '},
|
184
|
-
:decollated_values => {:foo => 'BAR'}
|
185
|
-
})
|
186
|
-
|
187
|
-
groups_import_buffer = stub('groups import buffer')
|
188
|
-
groups_dataset = stub('groups dataset')
|
189
|
-
@database.stubs(:[]).with(:foo_groups).returns(groups_dataset)
|
190
|
-
Linkage::ImportBuffer.stubs(:new).with(groups_dataset, [:id, :foo]).
|
191
|
-
returns(groups_import_buffer)
|
192
|
-
|
193
|
-
original_groups_import_buffer = stub('original groups import buffer')
|
194
|
-
original_groups_dataset = stub('original groups dataset')
|
195
|
-
@database.stubs(:[]).with(:foo_original_groups).
|
196
|
-
returns(original_groups_dataset)
|
197
|
-
Linkage::ImportBuffer.stubs(:new).
|
198
|
-
with(original_groups_dataset, [:id, :foo]).
|
199
|
-
returns(original_groups_import_buffer)
|
200
|
-
|
201
|
-
groups_import_buffer.expects(:add).with([1, 'BAR'])
|
202
|
-
original_groups_import_buffer.expects(:add).with([1, 'bar '])
|
203
|
-
result_set.add_group(group)
|
18
|
+
test "getting a registered class" do
|
19
|
+
klass = new_result_set
|
20
|
+
Linkage::ResultSet.register('foo', klass)
|
21
|
+
assert_equal klass, Linkage::ResultSet['foo']
|
204
22
|
end
|
205
23
|
|
206
|
-
test "
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
scores_import_buffer = stub('scores import buffer')
|
212
|
-
Linkage::ImportBuffer.expects(:new).
|
213
|
-
with(scores_dataset,
|
214
|
-
[:comparator_id, :record_1_id, :record_2_id, :score]).
|
215
|
-
returns(scores_import_buffer)
|
216
|
-
scores_import_buffer.expects(:add).with([0, 1, 2, 123])
|
217
|
-
scores_import_buffer.expects(:add).with([1, 1, 2, 456])
|
218
|
-
result_set.add_score(0, 1, 2, 123)
|
219
|
-
result_set.add_score(1, 1, 2, 456)
|
24
|
+
test "registered classes required to define score_set" do
|
25
|
+
klass = new_result_set do
|
26
|
+
remove_method :score_set
|
27
|
+
end
|
28
|
+
assert_raises(ArgumentError) { Linkage::ResultSet.register('foo', klass) }
|
220
29
|
end
|
221
30
|
|
222
|
-
test "
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
matches_import_buffer = stub('matches import buffer')
|
228
|
-
Linkage::ImportBuffer.expects(:new).
|
229
|
-
with(matches_dataset, [:record_1_id, :record_2_id, :total_score]).
|
230
|
-
returns(matches_import_buffer)
|
231
|
-
matches_import_buffer.expects(:add).with([1, 2, 123])
|
232
|
-
matches_import_buffer.expects(:add).with([2, 3, 456])
|
233
|
-
result_set.add_match(1, 2, 123)
|
234
|
-
result_set.add_match(2, 3, 456)
|
31
|
+
test "registered classes required to define match_set" do
|
32
|
+
klass = new_result_set do
|
33
|
+
remove_method :match_set
|
34
|
+
end
|
35
|
+
assert_raises(ArgumentError) { Linkage::ResultSet.register('foo', klass) }
|
235
36
|
end
|
236
37
|
end
|
data/test/unit/test_runner.rb
CHANGED
@@ -2,28 +2,133 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class UnitTests::TestRunner < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@
|
6
|
-
@
|
5
|
+
@score_recorder = stub('score recorder')
|
6
|
+
@matcher = stub('matcher')
|
7
|
+
@match_recorder = stub('match recorder')
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
sub_test_case('two datasets') do
|
11
|
+
def setup
|
12
|
+
super
|
13
|
+
@dataset_1 = stub('dataset 1')
|
14
|
+
@dataset_2 = stub('dataset 2')
|
15
|
+
@config = stub('config', {
|
16
|
+
:dataset_1 => @dataset_1, :dataset_2 => @dataset_2,
|
17
|
+
:score_recorder => @score_recorder, :match_recorder => @match_recorder,
|
18
|
+
:matcher => @matcher
|
19
|
+
})
|
20
|
+
@runner = Linkage::Runner.new(@config)
|
21
|
+
end
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
test "score records with simple comparisons" do
|
24
|
+
comparator_1 = stub('comparator 1', :type => :simple)
|
25
|
+
comparator_2 = stub('comparator 2', :type => :simple)
|
26
|
+
@config.stubs(:comparators).returns([comparator_1, comparator_2])
|
27
|
+
@score_recorder.expects(:start)
|
28
|
+
|
29
|
+
@dataset_1.expects(:each).multiple_yields(
|
30
|
+
[(record_1_1 = {:id => 1, :foo => 123})],
|
31
|
+
[(record_1_2 = {:id => 2, :foo => 456})]
|
32
|
+
)
|
33
|
+
@dataset_2.expects(:each).twice.multiple_yields(
|
34
|
+
[(record_2_1 = {:id => 100, :foo => 123})],
|
35
|
+
[(record_2_2 = {:id => 101, :foo => 456})]
|
36
|
+
)
|
37
|
+
|
38
|
+
comparator_1.expects(:score_and_notify).with(record_1_1, record_2_1)
|
39
|
+
comparator_2.expects(:score_and_notify).with(record_1_1, record_2_1)
|
40
|
+
comparator_1.expects(:score_and_notify).with(record_1_1, record_2_2)
|
41
|
+
comparator_2.expects(:score_and_notify).with(record_1_1, record_2_2)
|
42
|
+
comparator_1.expects(:score_and_notify).with(record_1_2, record_2_1)
|
43
|
+
comparator_2.expects(:score_and_notify).with(record_1_2, record_2_1)
|
44
|
+
comparator_1.expects(:score_and_notify).with(record_1_2, record_2_2)
|
45
|
+
comparator_2.expects(:score_and_notify).with(record_1_2, record_2_2)
|
46
|
+
|
47
|
+
@score_recorder.expects(:stop)
|
48
|
+
|
49
|
+
@runner.score_records
|
50
|
+
end
|
51
|
+
|
52
|
+
test "score records with advanced comparisons" do
|
53
|
+
comparator_1 = stub('comparator 1', :type => :advanced)
|
54
|
+
comparator_2 = stub('comparator 2', :type => :advanced)
|
55
|
+
@config.stubs(:comparators).returns([comparator_1, comparator_2])
|
56
|
+
@score_recorder.expects(:start)
|
57
|
+
|
58
|
+
comparator_1.expects(:score_datasets).with(@dataset_1, @dataset_2)
|
59
|
+
comparator_2.expects(:score_datasets).with(@dataset_1, @dataset_2)
|
60
|
+
@score_recorder.expects(:stop)
|
61
|
+
|
62
|
+
@runner.score_records
|
63
|
+
end
|
64
|
+
|
65
|
+
test "match records" do
|
66
|
+
@config.expects(:matcher).returns(@matcher)
|
67
|
+
@config.expects(:match_recorder).with(@matcher).returns(@match_recorder)
|
68
|
+
@match_recorder.expects(:start)
|
69
|
+
@matcher.expects(:run)
|
70
|
+
@match_recorder.expects(:stop)
|
18
71
|
|
19
|
-
|
20
|
-
|
21
|
-
assert_raise_kind_of(NotImplementedError) { runner.execute }
|
72
|
+
@runner.match_records
|
73
|
+
end
|
22
74
|
end
|
23
75
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
76
|
+
sub_test_case('one dataset') do
|
77
|
+
def setup
|
78
|
+
super
|
79
|
+
@dataset = stub('dataset')
|
80
|
+
@config = stub('config', {
|
81
|
+
:dataset_1 => @dataset, :dataset_2 => nil,
|
82
|
+
:score_recorder => @score_recorder, :match_recorder => @match_recorder,
|
83
|
+
:matcher => @matcher
|
84
|
+
})
|
85
|
+
@runner = Linkage::Runner.new(@config)
|
86
|
+
end
|
87
|
+
|
88
|
+
test "score records with simple comparisons" do
|
89
|
+
comparator_1 = stub('comparator 1', :type => :simple)
|
90
|
+
comparator_2 = stub('comparator 2', :type => :simple)
|
91
|
+
@config.stubs(:comparators).returns([comparator_1, comparator_2])
|
92
|
+
@score_recorder.expects(:start)
|
93
|
+
|
94
|
+
@dataset.expects(:all).returns([
|
95
|
+
(record_1 = {:id => 1, :foo => 123}),
|
96
|
+
(record_2 = {:id => 2, :foo => 456}),
|
97
|
+
(record_3 = {:id => 3, :foo => 456})
|
98
|
+
])
|
99
|
+
|
100
|
+
comparator_1.expects(:score_and_notify).with(record_1, record_2)
|
101
|
+
comparator_2.expects(:score_and_notify).with(record_1, record_2)
|
102
|
+
comparator_1.expects(:score_and_notify).with(record_1, record_3)
|
103
|
+
comparator_2.expects(:score_and_notify).with(record_1, record_3)
|
104
|
+
comparator_1.expects(:score_and_notify).with(record_2, record_3)
|
105
|
+
comparator_2.expects(:score_and_notify).with(record_2, record_3)
|
106
|
+
@score_recorder.expects(:stop)
|
107
|
+
|
108
|
+
@runner.score_records
|
109
|
+
end
|
110
|
+
|
111
|
+
test "score records with advanced comparisons" do
|
112
|
+
comparator_1 = stub('comparator 1', :type => :advanced)
|
113
|
+
comparator_2 = stub('comparator 2', :type => :advanced)
|
114
|
+
@config.stubs(:comparators).returns([comparator_1, comparator_2])
|
115
|
+
@score_recorder.expects(:start)
|
116
|
+
|
117
|
+
comparator_1.expects(:score_dataset).with(@dataset)
|
118
|
+
comparator_2.expects(:score_dataset).with(@dataset)
|
119
|
+
@score_recorder.expects(:stop)
|
120
|
+
|
121
|
+
@runner.score_records
|
122
|
+
end
|
123
|
+
|
124
|
+
test "match records" do
|
125
|
+
@config.expects(:matcher).returns(@matcher)
|
126
|
+
@config.expects(:match_recorder).with(@matcher).returns(@match_recorder)
|
127
|
+
@match_recorder.expects(:start)
|
128
|
+
@matcher.expects(:run)
|
129
|
+
@match_recorder.expects(:stop)
|
130
|
+
|
131
|
+
@runner.match_records
|
132
|
+
end
|
28
133
|
end
|
29
134
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class UnitTests::TestScoreRecorder < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@score_set = stub('score set')
|
6
|
+
end
|
7
|
+
|
8
|
+
test "recording events from comparators" do
|
9
|
+
comparator = stub('comparator')
|
10
|
+
score_recorder = Linkage::ScoreRecorder.new([comparator], @score_set, [:id_1, :id_2])
|
11
|
+
|
12
|
+
comparator.expects(:add_observer).with(score_recorder)
|
13
|
+
@score_set.expects(:open_for_writing)
|
14
|
+
score_recorder.start
|
15
|
+
|
16
|
+
@score_set.expects(:add_score).with(1, 123, 456, 1)
|
17
|
+
record_1 = { :id_1 => 123 }
|
18
|
+
record_2 = { :id_2 => 456 }
|
19
|
+
score_recorder.update(comparator, record_1, record_2, 1)
|
20
|
+
|
21
|
+
comparator.expects(:delete_observer).with(score_recorder)
|
22
|
+
@score_set.expects(:close)
|
23
|
+
score_recorder.stop
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestScoreSet < Test::Unit::TestCase
|
4
|
+
test "add_score raises NotImplementedError" do
|
5
|
+
score_set = Linkage::ScoreSet.new
|
6
|
+
assert_raises(NotImplementedError) do
|
7
|
+
score_set.add_score('foo', 'bar', 'baz', 'qux')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
test "each_pair raises NotImplementedError" do
|
12
|
+
score_set = Linkage::ScoreSet.new
|
13
|
+
assert_raises(NotImplementedError) do
|
14
|
+
score_set.each_pair { |x| }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "getting a registered class" do
|
19
|
+
klass = new_score_set
|
20
|
+
Linkage::ScoreSet.register('foo', klass)
|
21
|
+
assert_equal klass, Linkage::ScoreSet['foo']
|
22
|
+
end
|
23
|
+
|
24
|
+
test "registered classes required to define add_score" do
|
25
|
+
klass = new_score_set do
|
26
|
+
remove_method :add_score
|
27
|
+
end
|
28
|
+
assert_raises(ArgumentError) { Linkage::ScoreSet.register('foo', klass) }
|
29
|
+
end
|
30
|
+
|
31
|
+
test "registered classes required to define each_pair" do
|
32
|
+
klass = new_score_set do
|
33
|
+
remove_method :each_pair
|
34
|
+
end
|
35
|
+
assert_raises(ArgumentError) { Linkage::ScoreSet.register('foo', klass) }
|
36
|
+
end
|
37
|
+
end
|