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.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +1 -19
  5. data/Gemfile-java +3 -0
  6. data/README.markdown +88 -34
  7. data/Rakefile +16 -15
  8. data/TODO +4 -0
  9. data/lib/linkage/comparator.rb +139 -144
  10. data/lib/linkage/comparators/compare.rb +236 -29
  11. data/lib/linkage/comparators/strcompare.rb +85 -0
  12. data/lib/linkage/comparators/within.rb +24 -20
  13. data/lib/linkage/configuration.rb +44 -466
  14. data/lib/linkage/dataset.rb +28 -127
  15. data/lib/linkage/exceptions.rb +5 -0
  16. data/lib/linkage/field.rb +6 -37
  17. data/lib/linkage/field_set.rb +3 -3
  18. data/lib/linkage/match_recorder.rb +22 -0
  19. data/lib/linkage/match_set.rb +34 -0
  20. data/lib/linkage/match_sets/csv.rb +39 -0
  21. data/lib/linkage/match_sets/database.rb +45 -0
  22. data/lib/linkage/matcher.rb +30 -0
  23. data/lib/linkage/result_set.rb +25 -110
  24. data/lib/linkage/result_sets/csv.rb +54 -0
  25. data/lib/linkage/result_sets/database.rb +42 -0
  26. data/lib/linkage/runner.rb +57 -16
  27. data/lib/linkage/score_recorder.rb +30 -0
  28. data/lib/linkage/score_set.rb +49 -0
  29. data/lib/linkage/score_sets/csv.rb +64 -0
  30. data/lib/linkage/score_sets/database.rb +77 -0
  31. data/lib/linkage/version.rb +1 -1
  32. data/lib/linkage.rb +14 -17
  33. data/linkage.gemspec +13 -1
  34. data/linkage.gemspec-java +32 -0
  35. data/test/helper.rb +30 -23
  36. data/test/integration/test_cross_linkage.rb +46 -25
  37. data/test/integration/test_database_result_set.rb +55 -0
  38. data/test/integration/test_dual_linkage.rb +19 -94
  39. data/test/integration/test_self_linkage.rb +100 -203
  40. data/test/integration/test_within_comparator.rb +24 -77
  41. data/test/unit/comparators/test_compare.rb +254 -50
  42. data/test/unit/comparators/test_strcompare.rb +45 -0
  43. data/test/unit/comparators/test_within.rb +14 -26
  44. data/test/unit/match_sets/test_csv.rb +78 -0
  45. data/test/unit/match_sets/test_database.rb +63 -0
  46. data/test/unit/result_sets/test_csv.rb +111 -0
  47. data/test/unit/result_sets/test_database.rb +68 -0
  48. data/test/unit/score_sets/test_csv.rb +151 -0
  49. data/test/unit/score_sets/test_database.rb +149 -0
  50. data/test/unit/test_comparator.rb +46 -83
  51. data/test/unit/test_comparators.rb +4 -0
  52. data/test/unit/test_configuration.rb +99 -145
  53. data/test/unit/test_dataset.rb +52 -73
  54. data/test/unit/test_field.rb +4 -55
  55. data/test/unit/test_field_set.rb +6 -6
  56. data/test/unit/test_match_recorder.rb +23 -0
  57. data/test/unit/test_match_set.rb +23 -0
  58. data/test/unit/test_match_sets.rb +4 -0
  59. data/test/unit/test_matcher.rb +44 -0
  60. data/test/unit/test_result_set.rb +24 -223
  61. data/test/unit/test_result_sets.rb +4 -0
  62. data/test/unit/test_runner.rb +122 -17
  63. data/test/unit/test_runners.rb +4 -0
  64. data/test/unit/test_score_recorder.rb +25 -0
  65. data/test/unit/test_score_set.rb +37 -0
  66. data/test/unit/test_score_sets.rb +4 -0
  67. metadata +183 -90
  68. data/Gemfile.lock +0 -92
  69. data/lib/linkage/comparators/binary.rb +0 -12
  70. data/lib/linkage/data.rb +0 -175
  71. data/lib/linkage/decollation.rb +0 -93
  72. data/lib/linkage/expectation.rb +0 -21
  73. data/lib/linkage/expectations/exhaustive.rb +0 -63
  74. data/lib/linkage/expectations/simple.rb +0 -168
  75. data/lib/linkage/function.rb +0 -148
  76. data/lib/linkage/functions/binary.rb +0 -30
  77. data/lib/linkage/functions/cast.rb +0 -54
  78. data/lib/linkage/functions/length.rb +0 -29
  79. data/lib/linkage/functions/strftime.rb +0 -33
  80. data/lib/linkage/functions/trim.rb +0 -30
  81. data/lib/linkage/group.rb +0 -55
  82. data/lib/linkage/meta_object.rb +0 -139
  83. data/lib/linkage/runner/single_threaded.rb +0 -187
  84. data/lib/linkage/utils.rb +0 -164
  85. data/lib/linkage/warnings.rb +0 -5
  86. data/test/integration/test_collation.rb +0 -45
  87. data/test/integration/test_configuration.rb +0 -268
  88. data/test/integration/test_dataset.rb +0 -116
  89. data/test/integration/test_functions.rb +0 -88
  90. data/test/integration/test_result_set.rb +0 -85
  91. data/test/integration/test_scoring.rb +0 -84
  92. data/test/unit/expectations/test_exhaustive.rb +0 -111
  93. data/test/unit/expectations/test_simple.rb +0 -303
  94. data/test/unit/functions/test_binary.rb +0 -54
  95. data/test/unit/functions/test_cast.rb +0 -98
  96. data/test/unit/functions/test_length.rb +0 -52
  97. data/test/unit/functions/test_strftime.rb +0 -60
  98. data/test/unit/functions/test_trim.rb +0 -43
  99. data/test/unit/runner/test_single_threaded.rb +0 -12
  100. data/test/unit/test_data.rb +0 -445
  101. data/test/unit/test_decollation.rb +0 -201
  102. data/test/unit/test_function.rb +0 -233
  103. data/test/unit/test_group.rb +0 -38
  104. data/test/unit/test_meta_object.rb +0 -208
  105. 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
- def setup
5
- @config = stub('configuration', {
6
- :results_uri => 'foo://bar',
7
- :results_uri_options => {:blah => 'junk'},
8
- :decollation_needed? => true,
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 "creating a result set with a configuration" do
19
- result_set = Linkage::ResultSet.new(@config)
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 '#add_group creates two copies when decollation is needed' do
23
- result_set = Linkage::ResultSet.new(@config)
24
-
25
- group = stub('group', {
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 "#add_score uses custom table name" do
207
- @config.stubs(:scores_table_name).returns(:foo_scores)
208
- result_set = Linkage::ResultSet.new(@config)
209
- scores_dataset = stub('scores dataset')
210
- @database.stubs(:[]).with(:foo_scores).returns(scores_dataset)
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 "#add_match uses custom table name" do
223
- @config.stubs(:matches_table_name).returns(:foo_matches)
224
- result_set = Linkage::ResultSet.new(@config)
225
- matches_dataset = stub('matches dataset')
226
- @database.stubs(:[]).with(:foo_matches).returns(matches_dataset)
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
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ module UnitTests::TestResultSets
4
+ end
@@ -2,28 +2,133 @@ require 'helper'
2
2
 
3
3
  class UnitTests::TestRunner < Test::Unit::TestCase
4
4
  def setup
5
- @result_set = stub("result set")
6
- @config = stub("configuration", :result_set => @result_set)
5
+ @score_recorder = stub('score recorder')
6
+ @matcher = stub('matcher')
7
+ @match_recorder = stub('match recorder')
7
8
  end
8
9
 
9
- test "initialization creates a result set" do
10
- runner = Linkage::Runner.new(@config)
11
- end
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
- test "initialization with deprecated uri and options" do
14
- @config.expects(:save_results_in).with("foo:/results", {:foo => 'bar'})
15
- Linkage::Runner.any_instance.expects(:warn)
16
- runner = Linkage::Runner.new(@config, "foo:/results", {:foo => 'bar'})
17
- end
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
- test "execute raises error" do
20
- runner = Linkage::Runner.new(@config)
21
- assert_raise_kind_of(NotImplementedError) { runner.execute }
72
+ @runner.match_records
73
+ end
22
74
  end
23
75
 
24
- test "result_set gets ResultSet from config" do
25
- runner = Linkage::Runner.new(@config)
26
- @config.expects(:result_set).returns(@result_set)
27
- assert_equal @result_set, runner.result_set
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,4 @@
1
+ require 'helper'
2
+
3
+ module UnitTests::TestRunners
4
+ 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
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ module UnitTests::TestScoreSets
4
+ end