|
22 | 22 | end |
23 | 23 | end |
24 | 24 |
|
| 25 | + its(:cost) {is_expected.to be (4+2+1)} |
| 26 | + |
25 | 27 | it "should not have variables" do |
26 | 28 | expect(subject.variables?).to be_falsey |
27 | 29 | expect(subject.variable_count).to eq 0 |
|
52 | 54 | let(:s) {RDF::Query::Variable.new(:s, true)} |
53 | 55 | subject {described_class.new(s)} |
54 | 56 |
|
55 | | - specify {expect(subject).not_to be_constant} |
56 | | - specify {expect(subject).to be_variable} |
57 | | - specify {expect(subject).to be_bound} |
| 57 | + specify {is_expected.not_to be_constant} |
| 58 | + specify {is_expected.to be_variable} |
| 59 | + specify {is_expected.to be_bound} |
| 60 | + |
| 61 | + its(:cost) {is_expected.to be (4+2+1)} |
58 | 62 |
|
59 | 63 | it "should have one variable" do |
60 | 64 | expect(subject).to be_variables |
|
73 | 77 | end |
74 | 78 |
|
75 | 79 | it "should be fully bound" do |
76 | | - expect(subject).not_to be_unbound |
77 | | - expect(subject).to be_bound |
| 80 | + is_expected.not_to be_unbound |
| 81 | + is_expected.to be_bound |
78 | 82 | end |
79 | 83 |
|
80 | 84 | it "should have one binding" do |
|
90 | 94 | let(:o) {RDF::Query::Variable.new(:o, true)} |
91 | 95 | subject {described_class.new(s, p, o)} |
92 | 96 |
|
93 | | - specify {expect(subject).not_to be_constant} |
94 | | - specify {expect(subject).to be_variable} |
95 | | - specify {expect(subject).to be_bound} |
| 97 | + specify {is_expected.not_to be_constant} |
| 98 | + specify {is_expected.to be_variable} |
| 99 | + specify {is_expected.to be_bound} |
| 100 | + |
| 101 | + its(:cost) {is_expected.to be (4+2+1)} |
96 | 102 |
|
97 | 103 | it "should have three variables" do |
98 | 104 | expect(subject).to be_variables |
|
111 | 117 | end |
112 | 118 |
|
113 | 119 | it "should be fully bound" do |
114 | | - expect(subject).not_to be_unbound |
115 | | - expect(subject).to be_bound |
| 120 | + is_expected.not_to be_unbound |
| 121 | + is_expected.to be_bound |
116 | 122 | end |
117 | 123 |
|
118 | 124 | it "should have three bindings" do |
|
122 | 128 | end |
123 | 129 | end |
124 | 130 |
|
| 131 | + context "with variable in different locations" do |
| 132 | + { |
| 133 | + "spog": [[RDF::URI("s"), RDF::URI("p"), RDF::URI("o"), graph_name: RDF::URI("g")], 0], |
| 134 | + "spo?": [[RDF::URI("s"), RDF::URI("p"), RDF::URI("o"), graph_name: :g], 8], |
| 135 | + "sp?g": [[RDF::URI("s"), RDF::URI("p"), :o, graph_name: RDF::URI("g")], 1], |
| 136 | + "s?og": [[RDF::URI("s"), :p, RDF::URI("o"), graph_name: RDF::URI("g")], 2], |
| 137 | + "?pog": [[:s, RDF::URI("p"), RDF::URI("o"), graph_name: RDF::URI("g")], 4], |
| 138 | + }.each do |name, (args, cost)| |
| 139 | + it "cost for #{name} should be #{cost}" do |
| 140 | + pattern = described_class.new(*args) |
| 141 | + expect(pattern.cost).to be cost |
| 142 | + end |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + context "#cost" do |
| 147 | + it "can be set separately" do |
| 148 | + expect(subject.cost).to be (4+2+1) |
| 149 | + subject.cost = 0 |
| 150 | + expect(subject.cost).to be 0 |
| 151 | + end |
| 152 | + end |
| 153 | + |
125 | 154 | context "with a graph_name" do |
126 | 155 | let(:s) {RDF::Query::Variable.new(:s, true)} |
127 | 156 | let(:p) {RDF::Query::Variable.new(:p, true)} |
128 | 157 | let(:o) {RDF::Query::Variable.new(:o, true)} |
| 158 | + subject {described_class.new(s, p, o, graph_name: :c)} |
| 159 | + |
129 | 160 | it "uses a variable for a symbol" do |
130 | | - pattern = described_class.new(s, p, o, graph_name: :c) |
131 | | - expect(pattern.graph_name).to eq RDF::Query::Variable.new(:c) |
| 161 | + expect(subject.graph_name).to eq RDF::Query::Variable.new(:c) |
132 | 162 | end |
133 | 163 |
|
| 164 | + its(:cost) {is_expected.to be (8+4+2+1)} |
| 165 | + |
134 | 166 | it "uses a constant for :default" do |
135 | 167 | pattern = described_class.new(s, p, o, graph_name: false) |
136 | 168 | expect(pattern.graph_name).to eq false |
| 169 | + expect(pattern.cost).to eq (4+2+1) |
137 | 170 | end |
138 | 171 | end |
139 | 172 |
|
|
143 | 176 | let(:o) {RDF::Query::Variable.new(:o)} |
144 | 177 | subject {described_class.new(s, p, o)} |
145 | 178 |
|
146 | | - specify {expect(subject).not_to be_constant} |
147 | | - specify {expect(subject).to be_variable} |
148 | | - specify {expect(subject).not_to be_bound} |
| 179 | + specify {is_expected.not_to be_constant} |
| 180 | + specify {is_expected.to be_variable} |
| 181 | + specify {is_expected.not_to be_bound} |
| 182 | + |
| 183 | + its(:cost) {is_expected.to be (4+2+1)} |
149 | 184 |
|
150 | 185 | describe "#bind" do |
151 | 186 | context "complete solution" do |
|
196 | 231 | let(:p) {RDF::Query::Variable.new(:p)} |
197 | 232 | subject {described_class.new(s, p)} |
198 | 233 |
|
199 | | - specify {expect(subject).not_to be_constant} |
200 | | - specify {expect(subject).to be_variable} |
201 | | - specify {expect(subject).not_to be_bound} |
| 234 | + specify {is_expected.not_to be_constant} |
| 235 | + specify {is_expected.to be_variable} |
| 236 | + specify {is_expected.not_to be_bound} |
| 237 | + |
| 238 | + its(:cost) {is_expected.to be (4+2+1)} |
202 | 239 |
|
203 | 240 | it "should have two variable" do |
204 | 241 | expect(subject).to be_variables |
|
218 | 255 | end |
219 | 256 |
|
220 | 257 | it "should not be fully bound" do |
221 | | - expect(subject).not_to be_unbound |
222 | | - expect(subject).not_to be_bound |
| 258 | + is_expected.not_to be_unbound |
| 259 | + is_expected.not_to be_bound |
223 | 260 | end |
224 | 261 |
|
225 | 262 | it "should have one binding" do |
|
249 | 286 |
|
250 | 287 | describe "#variable_terms" do |
251 | 288 | it "has term" do |
252 | | - expect(described_class.new(RDF::Node.new, :p, 123).variable_terms).to eq([:predicate]) |
| 289 | + expect(described_class.new(RDF::Node.new, :p, RDF::Literal(123)).variable_terms).to eq([:predicate]) |
253 | 290 | end |
254 | 291 | end |
255 | 292 |
|
|
0 commit comments