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,111 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestExhaustive < Test::Unit::TestCase
|
4
|
-
test "initialize with comparator, threshold, and mode" do
|
5
|
-
comparator = stub('comparator')
|
6
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
7
|
-
assert_equal comparator, exp.comparator
|
8
|
-
assert_equal 100, exp.threshold
|
9
|
-
assert_equal :min, exp.mode
|
10
|
-
end
|
11
|
-
|
12
|
-
test "kind is :self when comparator has same args on both sides" do
|
13
|
-
meta_object_1 = stub('meta object 1')
|
14
|
-
meta_object_2 = stub('meta object 2')
|
15
|
-
meta_object_1.expects(:objects_equal?).with(meta_object_2).returns(true)
|
16
|
-
comparator = stub('comparator', {
|
17
|
-
:lhs_args => [meta_object_1], :rhs_args => [meta_object_2]
|
18
|
-
})
|
19
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
20
|
-
assert_equal :self, exp.kind
|
21
|
-
end
|
22
|
-
|
23
|
-
test "kind is :cross when comparator has args with same dataset but different number of args" do
|
24
|
-
meta_object_1 = stub('meta object 1')
|
25
|
-
meta_object_2 = stub('meta object 2')
|
26
|
-
meta_object_3 = stub('meta object 3')
|
27
|
-
meta_object_1.expects(:datasets_equal?).with(meta_object_2).returns(true)
|
28
|
-
comparator = stub('comparator', {
|
29
|
-
:lhs_args => [meta_object_1], :rhs_args => [meta_object_2, meta_object_3]
|
30
|
-
})
|
31
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
32
|
-
assert_equal :cross, exp.kind
|
33
|
-
end
|
34
|
-
|
35
|
-
test "kind is :cross when comparator has args with same dataset but different objects" do
|
36
|
-
meta_object_1 = stub('meta object 1')
|
37
|
-
meta_object_2 = stub('meta object 2')
|
38
|
-
meta_object_1.expects(:objects_equal?).with(meta_object_2).returns(false)
|
39
|
-
meta_object_1.expects(:datasets_equal?).with(meta_object_2).returns(true)
|
40
|
-
comparator = stub('comparator', {
|
41
|
-
:lhs_args => [meta_object_1], :rhs_args => [meta_object_2]
|
42
|
-
})
|
43
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
44
|
-
assert_equal :cross, exp.kind
|
45
|
-
end
|
46
|
-
|
47
|
-
test "kind is :dual when comparator has args with different datasets and different number of args" do
|
48
|
-
meta_object_1 = stub('meta object 1')
|
49
|
-
meta_object_2 = stub('meta object 2')
|
50
|
-
meta_object_3 = stub('meta object 3')
|
51
|
-
meta_object_1.expects(:datasets_equal?).with(meta_object_2).returns(false)
|
52
|
-
comparator = stub('comparator', {
|
53
|
-
:lhs_args => [meta_object_1], :rhs_args => [meta_object_2, meta_object_3]
|
54
|
-
})
|
55
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
56
|
-
assert_equal :dual, exp.kind
|
57
|
-
end
|
58
|
-
|
59
|
-
test "kind is :dual when comparator has args with different datasets" do
|
60
|
-
meta_object_1 = stub('meta object 1')
|
61
|
-
meta_object_2 = stub('meta object 2')
|
62
|
-
meta_object_1.expects(:objects_equal?).with(meta_object_2).returns(false)
|
63
|
-
meta_object_1.expects(:datasets_equal?).with(meta_object_2).returns(false)
|
64
|
-
comparator = stub('comparator', {
|
65
|
-
:lhs_args => [meta_object_1], :rhs_args => [meta_object_2]
|
66
|
-
})
|
67
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
68
|
-
assert_equal :dual, exp.kind
|
69
|
-
end
|
70
|
-
|
71
|
-
test "apply_to lhs dataset" do
|
72
|
-
dataset = stub('dataset')
|
73
|
-
new_dataset = stub('new dataset')
|
74
|
-
meta_object_1 = stub('meta object 1', :name => :foo, :to_expr => :foo)
|
75
|
-
meta_object_2 = stub('meta object 2', :name => :bar, :to_expr => :bar)
|
76
|
-
comparator = stub('comparator', :lhs_args => [meta_object_1], :rhs_args => [meta_object_2])
|
77
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
78
|
-
dataset.expects(:select_more).with(:foo.as(:foo)).returns(new_dataset)
|
79
|
-
assert_equal new_dataset, exp.apply_to(dataset, :lhs)
|
80
|
-
end
|
81
|
-
|
82
|
-
test "apply_to rhs dataset" do
|
83
|
-
dataset = stub('dataset')
|
84
|
-
new_dataset = stub('new dataset')
|
85
|
-
meta_object_1 = stub('meta object 1', :name => :foo, :to_expr => :foo)
|
86
|
-
meta_object_2 = stub('meta object 2', :name => :bar, :to_expr => :bar)
|
87
|
-
comparator = stub('comparator', :lhs_args => [meta_object_1], :rhs_args => [meta_object_2])
|
88
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 100, :min)
|
89
|
-
dataset.expects(:select_more).with(:bar.as(:bar)).returns(new_dataset)
|
90
|
-
assert_equal new_dataset, exp.apply_to(dataset, :rhs)
|
91
|
-
end
|
92
|
-
|
93
|
-
test "satisfied? with :equal mode" do
|
94
|
-
meta_object_1 = stub('meta object 1')
|
95
|
-
meta_object_2 = stub('meta object 2')
|
96
|
-
comparator = stub('comparator', :lhs_args => [meta_object_1], :rhs_args => [meta_object_2])
|
97
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 50, :equal)
|
98
|
-
assert exp.satisfied?(50)
|
99
|
-
assert !exp.satisfied?(123)
|
100
|
-
end
|
101
|
-
|
102
|
-
test "satisfied? with :min mode" do
|
103
|
-
meta_object_1 = stub('meta object 1')
|
104
|
-
meta_object_2 = stub('meta object 2')
|
105
|
-
comparator = stub('comparator', :lhs_args => [meta_object_1], :rhs_args => [meta_object_2])
|
106
|
-
exp = Linkage::Expectations::Exhaustive.new(comparator, 50, :min)
|
107
|
-
assert exp.satisfied?(50)
|
108
|
-
assert exp.satisfied?(55)
|
109
|
-
assert !exp.satisfied?(45)
|
110
|
-
end
|
111
|
-
end
|
@@ -1,303 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestSimple < Test::Unit::TestCase
|
4
|
-
test "initialize with invalid operator" do
|
5
|
-
assert_raises(ArgumentError) do
|
6
|
-
Linkage::Expectations::Simple.new(stub(), stub(), :foo)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
test "creating filter expectation from a dynamic object and a static object" do
|
11
|
-
field = stub('meta field', :static? => false, :side => :lhs)
|
12
|
-
object = stub('meta object', :static? => true)
|
13
|
-
exp = Linkage::Expectations::Simple.create(field, object, :==)
|
14
|
-
assert_kind_of Linkage::Expectations::Filter, exp
|
15
|
-
assert_equal :lhs, exp.side
|
16
|
-
end
|
17
|
-
|
18
|
-
test "creating expectation from two static objects raises error" do
|
19
|
-
object_1 = stub('meta object 1', :static? => true)
|
20
|
-
object_2 = stub('meta object 2', :static? => true)
|
21
|
-
assert_raises(ArgumentError) do
|
22
|
-
Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test "creating filter expectation from two dynamic objects with the same side" do
|
27
|
-
field_1 = stub('meta field 1', :static? => false, :side => :lhs)
|
28
|
-
field_2 = stub('meta field 2', :static? => false, :side => :lhs)
|
29
|
-
field_1.expects(:datasets_equal?).with(field_2).returns(true)
|
30
|
-
exp = Linkage::Expectations::Simple.create(field_1, field_2, :==)
|
31
|
-
assert_kind_of Linkage::Expectations::Filter, exp
|
32
|
-
assert_equal :lhs, exp.side
|
33
|
-
end
|
34
|
-
|
35
|
-
test "creating filter expectation from two dynamic objects with the same side but different datasets raises error" do
|
36
|
-
field_1 = stub('meta field 1', :static? => false, :side => :lhs)
|
37
|
-
field_2 = stub('meta field 2', :static? => false, :side => :lhs)
|
38
|
-
field_1.expects(:datasets_equal?).with(field_2).returns(false)
|
39
|
-
assert_raises(ArgumentError) do
|
40
|
-
Linkage::Expectations::Simple.create(field_1, field_2, :==)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
test "creating self expectation from two dynamic objects with different sides" do
|
45
|
-
object_1 = stub('meta object 1', :static? => false, :side => :lhs)
|
46
|
-
object_2 = stub('meta object 2', :static? => false, :side => :rhs)
|
47
|
-
object_1.expects(:objects_equal?).with(object_2).returns(true)
|
48
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
49
|
-
assert_kind_of Linkage::Expectations::Self, exp
|
50
|
-
end
|
51
|
-
|
52
|
-
test "creating cross expectation from two dynamic objects with different sides but same dataset" do
|
53
|
-
object_1 = stub('meta object 1', :static? => false, :side => :lhs)
|
54
|
-
object_2 = stub('meta object 2', :static? => false, :side => :rhs)
|
55
|
-
object_1.expects(:objects_equal?).with(object_2).returns(false)
|
56
|
-
object_1.expects(:datasets_equal?).with(object_2).returns(true)
|
57
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
58
|
-
assert_kind_of Linkage::Expectations::Cross, exp
|
59
|
-
end
|
60
|
-
|
61
|
-
test "creating dual expectation from two dynamic objects with different sides and datasets" do
|
62
|
-
object_1 = stub('meta object 1', :static? => false, :side => :lhs)
|
63
|
-
object_2 = stub('meta object 2', :static? => false, :side => :rhs)
|
64
|
-
object_1.expects(:objects_equal?).with(object_2).returns(false)
|
65
|
-
object_1.expects(:datasets_equal?).with(object_2).returns(false)
|
66
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
67
|
-
assert_kind_of Linkage::Expectations::Dual, exp
|
68
|
-
end
|
69
|
-
|
70
|
-
test "apply_to with filter expectation (== operator)" do
|
71
|
-
dataset = stub('dataset')
|
72
|
-
meta_field_1 = stub('meta field 1', :static? => false, :side => :lhs)
|
73
|
-
meta_field_2 = stub('meta field 2', :static? => false, :side => :lhs)
|
74
|
-
meta_field_1.stubs(:datasets_equal?).with(meta_field_2).returns(true)
|
75
|
-
|
76
|
-
exp = Linkage::Expectations::Simple.create(meta_field_1, meta_field_2, :==)
|
77
|
-
meta_field_1.expects(:to_expr).returns(:foo)
|
78
|
-
meta_field_2.expects(:to_expr).returns(:bar)
|
79
|
-
dataset.expects(:filter).with({:foo => :bar}).returns(dataset)
|
80
|
-
assert_equal dataset, exp.apply_to(dataset, :lhs)
|
81
|
-
|
82
|
-
dataset.expects(:filter).never
|
83
|
-
assert_equal dataset, exp.apply_to(dataset, :rhs)
|
84
|
-
end
|
85
|
-
|
86
|
-
test "apply_to with filter expectation (!= operator)" do
|
87
|
-
dataset = stub('dataset')
|
88
|
-
meta_field_1 = stub('meta field 1', :static? => false, :side => :lhs)
|
89
|
-
meta_field_2 = stub('meta field 2', :static? => false, :side => :lhs)
|
90
|
-
meta_field_1.stubs(:datasets_equal?).with(meta_field_2).returns(true)
|
91
|
-
|
92
|
-
exp = Linkage::Expectations::Simple.create(meta_field_1, meta_field_2, :'!=')
|
93
|
-
meta_field_1.expects(:to_expr).returns(:foo)
|
94
|
-
meta_field_2.expects(:to_expr).returns(:bar)
|
95
|
-
dataset.expects(:filter).with(~{:foo => :bar}).returns(dataset)
|
96
|
-
assert_equal dataset, exp.apply_to(dataset, :lhs)
|
97
|
-
|
98
|
-
dataset.expects(:filter).never
|
99
|
-
assert_equal dataset, exp.apply_to(dataset, :rhs)
|
100
|
-
end
|
101
|
-
|
102
|
-
test "apply_to with filter expectation (> operator)" do
|
103
|
-
dataset = stub('dataset')
|
104
|
-
meta_field_1 = stub('meta field 1', :static? => false, :side => :lhs)
|
105
|
-
meta_field_2 = stub('meta field 2', :static? => false, :side => :lhs)
|
106
|
-
meta_field_1.stubs(:datasets_equal?).with(meta_field_2).returns(true)
|
107
|
-
exp = Linkage::Expectations::Simple.create(meta_field_1, meta_field_2, :>)
|
108
|
-
|
109
|
-
identifier_1 = Sequel::SQL::Identifier.new(:foo)
|
110
|
-
meta_field_1.expects(:to_identifier).returns(identifier_1)
|
111
|
-
identifier_2 = Sequel::SQL::Identifier.new(:bar)
|
112
|
-
meta_field_2.expects(:to_identifier).returns(identifier_2)
|
113
|
-
expected = Sequel::SQL::BooleanExpression.new(:>, identifier_1, identifier_2)
|
114
|
-
|
115
|
-
dataset.expects(:filter).with(expected).returns(dataset)
|
116
|
-
assert_equal dataset, exp.apply_to(dataset, :lhs)
|
117
|
-
|
118
|
-
dataset.expects(:filter).never
|
119
|
-
assert_equal dataset, exp.apply_to(dataset, :rhs)
|
120
|
-
end
|
121
|
-
|
122
|
-
test "apply_to with self expectation" do
|
123
|
-
dataset = stub('dataset')
|
124
|
-
object_1 = stub('meta object 1', {
|
125
|
-
:static? => false, :side => :lhs, :dataset => dataset,
|
126
|
-
:to_expr => :foo
|
127
|
-
})
|
128
|
-
object_2 = stub('meta object 2', {
|
129
|
-
:static? => false, :side => :rhs, :dataset => dataset,
|
130
|
-
:to_expr => :foo
|
131
|
-
})
|
132
|
-
object_1.expects(:objects_equal?).with(object_2).returns(true)
|
133
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
134
|
-
|
135
|
-
merged_field = stub('merged field', :name => :foo)
|
136
|
-
object_1.expects(:merge).with(object_2).returns(merged_field)
|
137
|
-
dataset.expects(:group_match_more).with({:meta_object => object_1, :alias => :foo}).returns(dataset)
|
138
|
-
assert_equal dataset, exp.apply_to(dataset, :lhs)
|
139
|
-
|
140
|
-
dataset.expects(:group_match_more).with({:meta_object => object_2, :alias => :foo}).returns(dataset)
|
141
|
-
assert_equal dataset, exp.apply_to(dataset, :rhs)
|
142
|
-
end
|
143
|
-
|
144
|
-
test "apply_to with cross expectation" do
|
145
|
-
dataset = stub('dataset')
|
146
|
-
object_1 = stub('meta object 1', {
|
147
|
-
:static? => false, :side => :lhs, :dataset => dataset,
|
148
|
-
:to_expr => :foo
|
149
|
-
})
|
150
|
-
object_2 = stub('meta object 2', {
|
151
|
-
:static? => false, :side => :rhs, :dataset => dataset,
|
152
|
-
:to_expr => :bar
|
153
|
-
})
|
154
|
-
object_1.stubs(:objects_equal?).with(object_2).returns(false)
|
155
|
-
object_1.stubs(:datasets_equal?).with(object_2).returns(true)
|
156
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
157
|
-
|
158
|
-
merged_field = stub('merged field', :name => :foo_bar)
|
159
|
-
object_1.expects(:merge).with(object_2).returns(merged_field)
|
160
|
-
dataset.expects(:group_match_more).with({:meta_object => object_1, :alias => :foo_bar}).returns(dataset)
|
161
|
-
assert_equal dataset, exp.apply_to(dataset, :lhs)
|
162
|
-
|
163
|
-
dataset.expects(:group_match_more).with({:meta_object => object_2, :alias => :foo_bar}).returns(dataset)
|
164
|
-
assert_equal dataset, exp.apply_to(dataset, :rhs)
|
165
|
-
end
|
166
|
-
|
167
|
-
test "apply_to with dual expectation" do
|
168
|
-
dataset_1 = stub('dataset 1')
|
169
|
-
object_1 = stub('meta object 1', {
|
170
|
-
:static? => false, :side => :lhs, :dataset => dataset_1,
|
171
|
-
:to_expr => :foo
|
172
|
-
})
|
173
|
-
dataset_2 = stub('dataset 2')
|
174
|
-
object_2 = stub('meta object 2', {
|
175
|
-
:static? => false, :side => :rhs, :dataset => dataset_2,
|
176
|
-
:to_expr => :foo
|
177
|
-
})
|
178
|
-
object_1.stubs(:objects_equal?).with(object_2).returns(false)
|
179
|
-
object_1.stubs(:datasets_equal?).with(object_2).returns(false)
|
180
|
-
exp = Linkage::Expectations::Simple.create(object_1, object_2, :==)
|
181
|
-
|
182
|
-
merged_field = stub('merged field', :name => :foo)
|
183
|
-
object_1.expects(:merge).with(object_2).returns(merged_field)
|
184
|
-
dataset_1.expects(:group_match_more).with({:meta_object => object_1, :alias => :foo}).returns(dataset_1)
|
185
|
-
assert_equal dataset_1, exp.apply_to(dataset_1, :lhs)
|
186
|
-
|
187
|
-
dataset_2.expects(:group_match_more).with({:meta_object => object_2, :alias => :foo}).returns(dataset_2)
|
188
|
-
assert_equal dataset_2, exp.apply_to(dataset_2, :rhs)
|
189
|
-
end
|
190
|
-
|
191
|
-
test "exactly! wraps each side inside the binary function" do
|
192
|
-
dataset_1 = stub('dataset 1')
|
193
|
-
field_1 = stub_field('field 1', :dataset => dataset_1)
|
194
|
-
meta_object_1 = stub('meta object 1', :static? => false, :side => :lhs,
|
195
|
-
:object => field_1, :dataset => dataset_1)
|
196
|
-
|
197
|
-
dataset_2 = stub('dataset 2')
|
198
|
-
field_2 = stub_field('field 2', :dataset => dataset_2)
|
199
|
-
meta_object_2 = stub('meta object 2', :static? => false, :side => :rhs,
|
200
|
-
:object => field_2, :dataset => dataset_2)
|
201
|
-
meta_object_1.stubs(:objects_equal?).with(meta_object_2).returns(true)
|
202
|
-
|
203
|
-
exp = Linkage::Expectations::Simple.create(meta_object_1, meta_object_2, :==)
|
204
|
-
|
205
|
-
klass = Linkage::Functions::Binary
|
206
|
-
func_1 = stub('binary function 1')
|
207
|
-
klass.expects(:new).with(field_1, :dataset => dataset_1).returns(func_1)
|
208
|
-
func_2 = stub('binary function 2')
|
209
|
-
klass.expects(:new).with(field_2, :dataset => dataset_2).returns(func_2)
|
210
|
-
|
211
|
-
new_meta_object_1 = stub('new meta object 1')
|
212
|
-
Linkage::MetaObject.expects(:new).with(func_1, :lhs).returns(new_meta_object_1)
|
213
|
-
new_meta_object_2 = stub('new meta object 2')
|
214
|
-
Linkage::MetaObject.expects(:new).with(func_2, :rhs).returns(new_meta_object_2)
|
215
|
-
|
216
|
-
exp.exactly!
|
217
|
-
# LAZY: assume the expectation set its meta objects appropriately
|
218
|
-
end
|
219
|
-
|
220
|
-
test "#same_except_side with two filter expectations" do
|
221
|
-
field = stub_field('foo')
|
222
|
-
meta_object_1 = stub('meta field 1', {
|
223
|
-
:static? => false, :side => :lhs, :object => field
|
224
|
-
})
|
225
|
-
meta_object_2 = stub('meta object', :static? => true)
|
226
|
-
meta_object_3 = stub('meta field 2', {
|
227
|
-
:static? => false, :side => :rhs, :object => field
|
228
|
-
})
|
229
|
-
|
230
|
-
exp_1 = Linkage::Expectations::Simple.create(meta_object_1, meta_object_2, :==)
|
231
|
-
exp_2 = Linkage::Expectations::Simple.create(meta_object_3, meta_object_2, :==)
|
232
|
-
|
233
|
-
meta_object_1.expects(:objects_equal?).with(meta_object_3).returns(true)
|
234
|
-
meta_object_2.expects(:objects_equal?).with(meta_object_2).returns(true)
|
235
|
-
assert exp_1.same_except_side?(exp_2)
|
236
|
-
end
|
237
|
-
|
238
|
-
test "#decollation_needed? is false when comparing non-string objects" do
|
239
|
-
dataset_1 = stub('dataset 1')
|
240
|
-
object_1 = stub('meta object 1', {
|
241
|
-
:static? => false, :side => :lhs, :dataset => dataset_1,
|
242
|
-
})
|
243
|
-
dataset_2 = stub('dataset 2')
|
244
|
-
object_2 = stub('meta object 2', {
|
245
|
-
:static? => false, :side => :rhs, :dataset => dataset_2,
|
246
|
-
})
|
247
|
-
merged_field = stub('merged field', :ruby_type => {:type => Fixnum})
|
248
|
-
object_1.stubs(:merge).with(object_2).returns(merged_field)
|
249
|
-
exp = Linkage::Expectations::Dual.new(object_1, object_2, :==)
|
250
|
-
assert !exp.decollation_needed?
|
251
|
-
end
|
252
|
-
|
253
|
-
test "#decollation_needed? is false when comparing two dynamic string objects with the same database type and same collation" do
|
254
|
-
dataset_1 = stub('dataset 1')
|
255
|
-
object_1 = stub('meta object 1', {
|
256
|
-
:static? => false, :side => :lhs, :dataset => dataset_1,
|
257
|
-
:collation => 'foo', :database_type => :mysql
|
258
|
-
})
|
259
|
-
dataset_2 = stub('dataset 2')
|
260
|
-
object_2 = stub('meta object 2', {
|
261
|
-
:static? => false, :side => :rhs, :dataset => dataset_2,
|
262
|
-
:collation => 'foo', :database_type => :mysql
|
263
|
-
})
|
264
|
-
merged_field = stub('merged field', :ruby_type => {:type => String})
|
265
|
-
object_1.stubs(:merge).with(object_2).returns(merged_field)
|
266
|
-
exp = Linkage::Expectations::Dual.new(object_1, object_2, :==)
|
267
|
-
assert !exp.decollation_needed?
|
268
|
-
end
|
269
|
-
|
270
|
-
test "#decollation_needed? is true when comparing two dynamic string objects with the same database type but different collations" do
|
271
|
-
dataset_1 = stub('dataset 1')
|
272
|
-
object_1 = stub('meta object 1', {
|
273
|
-
:static? => false, :side => :lhs, :dataset => dataset_1,
|
274
|
-
:collation => 'foo', :database_type => :mysql
|
275
|
-
})
|
276
|
-
dataset_2 = stub('dataset 2')
|
277
|
-
object_2 = stub('meta object 2', {
|
278
|
-
:static? => false, :side => :rhs, :dataset => dataset_2,
|
279
|
-
:collation => 'bar', :database_type => :mysql
|
280
|
-
})
|
281
|
-
merged_field = stub('merged field', :ruby_type => {:type => String})
|
282
|
-
object_1.stubs(:merge).with(object_2).returns(merged_field)
|
283
|
-
exp = Linkage::Expectations::Dual.new(object_1, object_2, :==)
|
284
|
-
assert exp.decollation_needed?
|
285
|
-
end
|
286
|
-
|
287
|
-
test "#decollation_needed? is true when comparing two dynamic string objects with same collation but different database types" do
|
288
|
-
dataset_1 = stub('dataset 1')
|
289
|
-
object_1 = stub('meta object 1', {
|
290
|
-
:static? => false, :side => :lhs, :dataset => dataset_1,
|
291
|
-
:collation => 'foo', :database_type => :foo
|
292
|
-
})
|
293
|
-
dataset_2 = stub('dataset 2')
|
294
|
-
object_2 = stub('meta object 2', {
|
295
|
-
:static? => false, :side => :rhs, :dataset => dataset_2,
|
296
|
-
:collation => 'foo', :database_type => :bar
|
297
|
-
})
|
298
|
-
merged_field = stub('merged field', :ruby_type => {:type => String})
|
299
|
-
object_1.stubs(:merge).with(object_2).returns(merged_field)
|
300
|
-
exp = Linkage::Expectations::Dual.new(object_1, object_2, :==)
|
301
|
-
assert exp.decollation_needed?
|
302
|
-
end
|
303
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestBinary < Test::Unit::TestCase
|
4
|
-
def self.const_missing(name)
|
5
|
-
if Linkage::Functions.const_defined?(name)
|
6
|
-
Linkage::Functions.const_get(name)
|
7
|
-
else
|
8
|
-
super
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
test "subclass of Function" do
|
13
|
-
assert_equal Linkage::Function, Linkage::Functions::Binary.superclass
|
14
|
-
end
|
15
|
-
|
16
|
-
test "ruby_type" do
|
17
|
-
expected = {:type => File}
|
18
|
-
assert_equal(expected, Linkage::Functions::Binary.new("foo", :dataset => stub('dataset')).ruby_type)
|
19
|
-
field = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
20
|
-
assert_equal(expected, Linkage::Functions::Binary.new(field).ruby_type)
|
21
|
-
end
|
22
|
-
|
23
|
-
test "parameters" do
|
24
|
-
assert_equal [[String]], Linkage::Functions::Binary.parameters
|
25
|
-
end
|
26
|
-
|
27
|
-
test "name" do
|
28
|
-
assert_equal "binary", Linkage::Functions::Binary.function_name
|
29
|
-
end
|
30
|
-
|
31
|
-
test "registers itself" do
|
32
|
-
assert_equal Linkage::Function["binary"], Linkage::Functions::Binary
|
33
|
-
end
|
34
|
-
|
35
|
-
test "requires dataset" do
|
36
|
-
func = Binary.new("foo")
|
37
|
-
assert_raises(RuntimeError) { func.to_expr }
|
38
|
-
end
|
39
|
-
|
40
|
-
test "to_expr for sqlite" do
|
41
|
-
func = Binary.new("foo", :dataset => stub('dataset', :database_type => :sqlite))
|
42
|
-
assert_equal "foo".cast(:blob), func.to_expr
|
43
|
-
end
|
44
|
-
|
45
|
-
test "to_expr for mysql" do
|
46
|
-
func = Binary.new("foo", :dataset => stub('dataset', :database_type => :mysql))
|
47
|
-
assert_equal "foo".cast(:binary), func.to_expr
|
48
|
-
end
|
49
|
-
|
50
|
-
test "to_expr for postgresql" do
|
51
|
-
func = Binary.new("foo", :dataset => stub('dataset', :database_type => :postgres))
|
52
|
-
assert_equal "foo".cast(:bytea), func.to_expr
|
53
|
-
end
|
54
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestCast < Test::Unit::TestCase
|
4
|
-
def self.const_missing(name)
|
5
|
-
if Linkage::Functions.const_defined?(name)
|
6
|
-
Linkage::Functions.const_get(name)
|
7
|
-
else
|
8
|
-
super
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
test "subclass of Function" do
|
13
|
-
assert_equal Linkage::Function, Linkage::Functions::Cast.superclass
|
14
|
-
end
|
15
|
-
|
16
|
-
test "parameters" do
|
17
|
-
assert_equal [[:any], [String]], Linkage::Functions::Cast.parameters
|
18
|
-
end
|
19
|
-
|
20
|
-
test "name" do
|
21
|
-
assert_equal "cast", Linkage::Functions::Cast.function_name
|
22
|
-
end
|
23
|
-
|
24
|
-
test "ruby_type when casting to (signed) integer" do
|
25
|
-
expected = {:type => Fixnum}
|
26
|
-
assert_equal(expected, Linkage::Functions::Cast.new('123', 'integer', :dataset => stub('dataset')).ruby_type)
|
27
|
-
field = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
28
|
-
assert_equal(expected, Linkage::Functions::Cast.new(field, 'integer').ruby_type)
|
29
|
-
end
|
30
|
-
|
31
|
-
test "ruby_type when casting to binary" do
|
32
|
-
expected = {:type => File}
|
33
|
-
assert_equal(expected, Linkage::Functions::Cast.new('123', 'binary', :dataset => stub('dataset')).ruby_type)
|
34
|
-
field = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
35
|
-
assert_equal(expected, Linkage::Functions::Cast.new(field, 'binary').ruby_type)
|
36
|
-
end
|
37
|
-
|
38
|
-
test "registers itself" do
|
39
|
-
assert_equal Linkage::Function["cast"], Linkage::Functions::Cast
|
40
|
-
end
|
41
|
-
|
42
|
-
test "to_expr for integer (sqlite)" do
|
43
|
-
func = Cast.new('foo', 'integer', :dataset => stub('dataset', :database_type => :sqlite))
|
44
|
-
assert_equal 'foo'.cast(:integer), func.to_expr
|
45
|
-
end
|
46
|
-
|
47
|
-
test "to_expr for integer (mysql)" do
|
48
|
-
func = Cast.new('foo', 'integer', :dataset => stub('dataset', :database_type => :mysql))
|
49
|
-
assert_equal 'foo'.cast(:signed), func.to_expr
|
50
|
-
end
|
51
|
-
|
52
|
-
test "to_expr for integer (postgres)" do
|
53
|
-
func = Cast.new('foo', 'integer', :dataset => stub('dataset', :database_type => :postgres))
|
54
|
-
assert_equal 'foo'.cast(:integer), func.to_expr
|
55
|
-
end
|
56
|
-
|
57
|
-
test "to_expr for integer (h2)" do
|
58
|
-
func = Cast.new('foo', 'integer', :dataset => stub('dataset', :database_type => :h2))
|
59
|
-
assert_equal 'foo'.cast(:integer), func.to_expr
|
60
|
-
end
|
61
|
-
|
62
|
-
test "to_expr for binary (sqlite)" do
|
63
|
-
func = Cast.new('foo', 'binary', :dataset => stub('dataset', :database_type => :sqlite))
|
64
|
-
assert_equal 'foo'.cast(:blob), func.to_expr
|
65
|
-
end
|
66
|
-
|
67
|
-
test "to_expr for binary (mysql)" do
|
68
|
-
func = Cast.new('foo', 'binary', :dataset => stub('dataset', :database_type => :mysql))
|
69
|
-
assert_equal 'foo'.cast(:binary), func.to_expr
|
70
|
-
end
|
71
|
-
|
72
|
-
test "to_expr for binary (postgres)" do
|
73
|
-
func = Cast.new('foo', 'binary', :dataset => stub('dataset', :database_type => :postgres))
|
74
|
-
assert_equal 'foo'.cast(:bytea), func.to_expr
|
75
|
-
end
|
76
|
-
|
77
|
-
test "to_expr for binary (h2)" do
|
78
|
-
func = Cast.new('foo', 'binary', :dataset => stub('dataset', :database_type => :h2))
|
79
|
-
assert_equal 'foo'.cast(:binary), func.to_expr
|
80
|
-
end
|
81
|
-
|
82
|
-
=begin
|
83
|
-
test "to_expr for sqlite" do
|
84
|
-
func = Cast.new("foo", :dataset => stub('dataset', :database_type => :sqlite))
|
85
|
-
assert_equal "foo".cast(:blob), func.to_expr
|
86
|
-
end
|
87
|
-
|
88
|
-
test "to_expr for mysql" do
|
89
|
-
func = Cast.new("foo", :dataset => stub('dataset', :database_type => :mysql))
|
90
|
-
assert_equal "foo".cast(:binary), func.to_expr
|
91
|
-
end
|
92
|
-
|
93
|
-
test "to_expr for postgresql" do
|
94
|
-
func = Cast.new("foo", :dataset => stub('dataset', :database_type => :postgres))
|
95
|
-
assert_equal "foo".cast(:bytea), func.to_expr
|
96
|
-
end
|
97
|
-
=end
|
98
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestLength < Test::Unit::TestCase
|
4
|
-
test "subclass of Function" do
|
5
|
-
assert_equal Linkage::Function, Linkage::Functions::Length.superclass
|
6
|
-
end
|
7
|
-
|
8
|
-
test "ruby_type for string literal" do
|
9
|
-
length = Linkage::Functions::Length.new("foo", :dataset => stub('dataset'))
|
10
|
-
assert_equal({:type => Fixnum}, length.ruby_type)
|
11
|
-
end
|
12
|
-
|
13
|
-
test "ruby_type for string field" do
|
14
|
-
field_1 = stub_field('field 1', :name => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
15
|
-
assert_equal({:type => Fixnum}, Linkage::Functions::Length.new(field_1).ruby_type)
|
16
|
-
|
17
|
-
field_2 = stub_field('field 2', :name => :bar, :ruby_type => {:type => String, :opts => {:size => 123}}, :dataset => stub('dataset'))
|
18
|
-
assert_equal({:type => Fixnum}, Linkage::Functions::Length.new(field_2).ruby_type)
|
19
|
-
end
|
20
|
-
|
21
|
-
test "ruby_type for string function" do
|
22
|
-
func = new_function('foo', {:type => String, :opts => {:junk => '123'}})
|
23
|
-
assert_equal({:type => Fixnum}, Linkage::Functions::Length.new(func.new(:dataset => stub('dataset'))).ruby_type)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "parameters" do
|
27
|
-
assert_equal [[String]], Linkage::Functions::Length.parameters
|
28
|
-
end
|
29
|
-
|
30
|
-
test "name" do
|
31
|
-
assert_equal "length", Linkage::Functions::Length.function_name
|
32
|
-
end
|
33
|
-
|
34
|
-
test "to_expr for sqlite" do
|
35
|
-
func = Linkage::Functions::Length.new("foo bar", :dataset => stub('dataset', :database_type => :sqlite))
|
36
|
-
assert_equal :length.sql_function("foo bar"), func.to_expr
|
37
|
-
end
|
38
|
-
|
39
|
-
test "to_expr for mysql" do
|
40
|
-
func = Linkage::Functions::Length.new("foo bar", :dataset => stub('dataset', :database_type => :mysql))
|
41
|
-
assert_equal :char_length.sql_function("foo bar"), func.to_expr
|
42
|
-
end
|
43
|
-
|
44
|
-
test "to_expr for postgresql" do
|
45
|
-
func = Linkage::Functions::Length.new("foo bar", :dataset => stub('dataset', :database_type => :postgres))
|
46
|
-
assert_equal :char_length.sql_function("foo bar"), func.to_expr
|
47
|
-
end
|
48
|
-
|
49
|
-
test "registers itself" do
|
50
|
-
assert_equal Linkage::Function["length"], Linkage::Functions::Length
|
51
|
-
end
|
52
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestStrftime < Test::Unit::TestCase
|
4
|
-
def self.const_missing(name)
|
5
|
-
if Linkage::Functions.const_defined?(name)
|
6
|
-
Linkage::Functions.const_get(name)
|
7
|
-
else
|
8
|
-
super
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
test "subclass of Function" do
|
13
|
-
assert_equal Linkage::Function, Linkage::Functions::Strftime.superclass
|
14
|
-
end
|
15
|
-
|
16
|
-
test "ruby_type" do
|
17
|
-
expected = {:type => String}
|
18
|
-
format = "%Y-%m-%d"
|
19
|
-
assert_equal(expected, Linkage::Functions::Strftime.new(Time.now, format, :dataset => stub('dataset')).ruby_type)
|
20
|
-
field = stub_field('field 1', :name => :bar, :ruby_type => {:type => Time})
|
21
|
-
assert_equal(expected, Linkage::Functions::Strftime.new(field, format, :dataset => stub('dataset')).ruby_type)
|
22
|
-
func = new_function('foo', {:type => Time, :opts => {:junk => '123'}})
|
23
|
-
assert_equal(expected, Linkage::Functions::Strftime.new(func.new(:dataset => stub('dataset')), format).ruby_type)
|
24
|
-
end
|
25
|
-
|
26
|
-
test "parameters" do
|
27
|
-
assert_equal [[Date, Time, DateTime], [String]], Linkage::Functions::Strftime.parameters
|
28
|
-
end
|
29
|
-
|
30
|
-
test "name" do
|
31
|
-
assert_equal "strftime", Linkage::Functions::Strftime.function_name
|
32
|
-
end
|
33
|
-
|
34
|
-
test "registers itself" do
|
35
|
-
assert_equal Linkage::Function["strftime"], Linkage::Functions::Strftime
|
36
|
-
end
|
37
|
-
|
38
|
-
test "requires dataset" do
|
39
|
-
func = Strftime.new(Time.now, "%Y-%m-%d")
|
40
|
-
assert_raises(RuntimeError) { func.to_expr }
|
41
|
-
end
|
42
|
-
|
43
|
-
test "to_expr for sqlite" do
|
44
|
-
now = Time.now
|
45
|
-
func = Strftime.new(now, "%Y-%m-%d", :dataset => stub('dataset', :database_type => :sqlite))
|
46
|
-
assert_equal :strftime.sql_function("%Y-%m-%d", now), func.to_expr
|
47
|
-
end
|
48
|
-
|
49
|
-
test "to_expr for mysql" do
|
50
|
-
now = Time.now
|
51
|
-
func = Strftime.new(now, "%Y-%m-%d", :dataset => stub('dataset', :database_type => :mysql))
|
52
|
-
assert_equal :date_format.sql_function(now, "%Y-%m-%d"), func.to_expr
|
53
|
-
end
|
54
|
-
|
55
|
-
test "to_expr for postgresql" do
|
56
|
-
now = Time.now
|
57
|
-
func = Strftime.new(now, "%Y-%m-%d", :dataset => stub('dataset', :database_type => :postgres))
|
58
|
-
assert_equal :to_char.sql_function(now, "%Y-%m-%d"), func.to_expr
|
59
|
-
end
|
60
|
-
end
|