qti 2.29.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76e0ccb82cec45bc227f147d2b1d505b4117131e1aa6fbc166553efbbb4e248e
4
- data.tar.gz: 180bb912b8a0d53b398ac62fab21922ae4da140817e86c27abb4783bd843f6ba
3
+ metadata.gz: a08fc96f6a77de2160651785437e8ae12448f4b727daddccd06128715c51e5a8
4
+ data.tar.gz: 8893790e36626b9f29c743d6f48c313b8c77f9294117686dadaec8c085755751
5
5
  SHA512:
6
- metadata.gz: 8c51e5b108c05d11ec919a5118de0e9d5fdcfed4403defecc353f6d93bb083fb6f281db0fd74d1ff636fafda4982981b47ba618198068a933f5991ffac3ec923
7
- data.tar.gz: 55a94df5be4713653c8db8965ada79ea5daee2f1c0c9fe69a92558be7f6a080e3136ee3f6dc5d193d6dc730b6d2235dabb07135ec1e6d19f6311cfe8675baba1
6
+ metadata.gz: df3ce562a0617d78c4f34d12d4682743dfb06d409283d6e88a01fb46278d8f815a8820082717da308521c01ba836bf26a98ec7ab73973080ac17ec7fd8ebaa49
7
+ data.tar.gz: d3fe2fd6a969a72af91ebd5942a3d715075ed9439fefb157a2d791ac7923779fee38a980fdf1624cd3a83efb53cb092b86672c04f4a8b6628931908b217caaa9
@@ -76,9 +76,7 @@ module Qti
76
76
  end
77
77
 
78
78
  def answer_feedback
79
- path = './/xmlns:respcondition//xmlns:displayfeedback/../' \
80
- 'xmlns:conditionvar/xmlns:varequal[@respident]/../../' \
81
- 'xmlns:displayfeedback/..'
79
+ path = './/xmlns:respcondition[xmlns:displayfeedback][.//xmlns:varequal[@respident]]'
82
80
  answers = node.xpath(path).map do |entry|
83
81
  answer_feedback_entry(entry)
84
82
  end.compact
@@ -88,17 +86,30 @@ module Qti
88
86
  private
89
87
 
90
88
  def answer_feedback_entry(entry)
91
- ve = entry.xpath('.//xmlns:varequal').first
89
+ ve = entry.xpath('.//xmlns:varequal[@respident]').first
90
+ return nil unless ve
92
91
  refid = entry.xpath('./xmlns:displayfeedback[not (@linkrefid="correct_fb" or ' \
93
92
  '@linkrefid="general_incorrect_fb" or @linkrefid="general_fb")]').first&.[](:linkrefid)
94
93
  feedback = get_feedback(refid)
95
94
  return nil unless feedback
96
- {
95
+ answer = {
97
96
  response_id: ve[:respident],
98
97
  response_value: ve.text,
99
98
  texttype: feedback&.[](:texttype),
100
99
  feedback: feedback&.text
101
100
  }
101
+ answer[:negated] = true if negated_condition?(ve)
102
+ answer
103
+ end
104
+
105
+ # Matching is the one Canvas type whose comment is shown when the
106
+ # student did *not* pick that match, so its `varequal` sits inside a
107
+ # `not`. Report that, rather than making the consumer infer it from
108
+ # the question type -- third party QTI may emit either form for any
109
+ # type. Only set when true, so every other type keeps its old shape.
110
+ def negated_condition?(varequal)
111
+ varequal.ancestors.take_while { |a| a.name != 'respcondition' }
112
+ .count { |a| a.name == 'not' }.odd?
102
113
  end
103
114
 
104
115
  def get_feedback(ident)
@@ -29,8 +29,35 @@ module Qti
29
29
  end
30
30
  end
31
31
 
32
+ # Numeric answers cannot be paired with their comment through a
33
+ # `varequal`, the way the base implementation does it: exact and
34
+ # precision answers nest it inside an `or`, and range answers have no
35
+ # single value to emit one for. Canvas instead puts each answer's
36
+ # `displayfeedback` in the same `respcondition` that carries its
37
+ # `setvar SCORE`, so pair them by that node and key the result on the
38
+ # position within `answer_nodes` -- the same list, in the same order,
39
+ # that `scoring_data_structs` is built from.
40
+ def answer_feedback
41
+ answers = answer_nodes.filter_map.with_index do |answer_node, index|
42
+ numeric_answer_feedback_entry(answer_node, index)
43
+ end
44
+ answers unless answers.empty?
45
+ end
46
+
32
47
  private
33
48
 
49
+ def numeric_answer_feedback_entry(answer_node, index)
50
+ refid = answer_node.xpath('./xmlns:displayfeedback[not (@linkrefid="correct_fb" or ' \
51
+ '@linkrefid="general_incorrect_fb" or @linkrefid="general_fb")]').first&.[](:linkrefid)
52
+ feedback = get_feedback(refid)
53
+ return nil unless feedback
54
+ {
55
+ response_index: index,
56
+ texttype: feedback[:texttype],
57
+ feedback: feedback.text
58
+ }
59
+ end
60
+
34
61
  def answer_nodes
35
62
  @node.xpath('.//xmlns:respcondition/xmlns:setvar[@varname="SCORE"]/..')
36
63
  end
data/lib/qti/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qti
2
- VERSION = '2.29.0'.freeze
2
+ VERSION = '2.31.0'.freeze
3
3
  end
@@ -0,0 +1,189 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ Numeric per-answer feedback fixture. Question1 covers all four numeric answer
4
+ types (exact, precision, margin of error, range) plus item level feedback that
5
+ must be ignored; Question2 has comments on only the first and third of three
6
+ answers, covering index alignment with scoring_data_structs.
7
+ -->
8
+ <questestinterop xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/ims_qtiasiv1p2 http://www.imsglobal.org/xsd/ims_qtiasiv1p2p1.xsd">
9
+ <assessment ident="i98661073a66c6b2567c8f9b1a22c2989" title="Numeric feedback">
10
+ <section ident="root_section">
11
+ <item ident="ia63b6a115fa68a555398a58626a62f82" title="Question1">
12
+ <presentation>
13
+ <material>
14
+ <mattext texttype="text/html">&lt;div&gt;&lt;p&gt;question 1&lt;/p&gt;&lt;/div&gt;</mattext>
15
+ </material>
16
+ <response_str ident="response1" rcardinality="Single">
17
+ <render_fib fibtype="Decimal">
18
+ <response_label ident="answer1"/>
19
+ </render_fib>
20
+ </response_str>
21
+ </presentation>
22
+ <resprocessing>
23
+ <outcomes>
24
+ <decvar maxvalue="100" minvalue="0" varname="SCORE" vartype="Decimal"/>
25
+ </outcomes>
26
+ <respcondition continue="No">
27
+ <conditionvar>
28
+ <or>
29
+ <varequal respident="response1">42.0</varequal>
30
+ <and>
31
+ <vargte respident="response1">42.0</vargte>
32
+ <varlte respident="response1">42.0</varlte>
33
+ </and>
34
+ </or>
35
+ </conditionvar>
36
+ <setvar action="Set" varname="SCORE">100</setvar>
37
+ <displayfeedback feedbacktype="Response" linkrefid="1001_fb"/>
38
+ <displayfeedback feedbacktype="Response" linkrefid="correct_fb"/>
39
+ </respcondition>
40
+ <respcondition continue="No">
41
+ <conditionvar>
42
+ <or>
43
+ <varequal respident="response1">1000.00</varequal>
44
+ <and>
45
+ <vargt respident="response1">999.995</vargt>
46
+ <varlte respident="response1">1000.005</varlte>
47
+ </and>
48
+ </or>
49
+ </conditionvar>
50
+ <setvar action="Set" varname="SCORE">100</setvar>
51
+ <displayfeedback feedbacktype="Response" linkrefid="1002_fb"/>
52
+ </respcondition>
53
+ <respcondition continue="No">
54
+ <conditionvar>
55
+ <or>
56
+ <varequal respident="response1">77.0</varequal>
57
+ <and>
58
+ <vargte respident="response1">70.0</vargte>
59
+ <varlte respident="response1">84.0</varlte>
60
+ </and>
61
+ </or>
62
+ </conditionvar>
63
+ <setvar action="Set" varname="SCORE">100</setvar>
64
+ <displayfeedback feedbacktype="Response" linkrefid="1003_fb"/>
65
+ </respcondition>
66
+ <respcondition continue="No">
67
+ <conditionvar>
68
+ <vargte respident="response1">3.9</vargte>
69
+ <varlte respident="response1">4.1</varlte>
70
+ </conditionvar>
71
+ <setvar action="Set" varname="SCORE">100</setvar>
72
+ <displayfeedback feedbacktype="Response" linkrefid="1004_fb"/>
73
+ </respcondition>
74
+ </resprocessing>
75
+ <itemfeedback ident="1001_fb">
76
+ <flow_mat>
77
+ <material>
78
+ <mattext texttype="text/html">&lt;p&gt;Exact answer comment&lt;/p&gt;</mattext>
79
+ </material>
80
+ </flow_mat>
81
+ </itemfeedback>
82
+ <itemfeedback ident="1002_fb">
83
+ <flow_mat>
84
+ <material>
85
+ <mattext texttype="text/html">&lt;p&gt;Precision answer comment&lt;/p&gt;</mattext>
86
+ </material>
87
+ </flow_mat>
88
+ </itemfeedback>
89
+ <itemfeedback ident="1003_fb">
90
+ <flow_mat>
91
+ <material>
92
+ <mattext texttype="text/html">&lt;p&gt;Margin of error answer comment&lt;/p&gt;</mattext>
93
+ </material>
94
+ </flow_mat>
95
+ </itemfeedback>
96
+ <itemfeedback ident="1004_fb">
97
+ <flow_mat>
98
+ <material>
99
+ <mattext texttype="text/html">&lt;p&gt;Range answer comment&lt;/p&gt;</mattext>
100
+ </material>
101
+ </flow_mat>
102
+ </itemfeedback>
103
+ <itemfeedback ident="correct_fb">
104
+ <flow_mat>
105
+ <material>
106
+ <mattext texttype="text/html">&lt;p&gt;General Correct Feedback&lt;/p&gt;</mattext>
107
+ </material>
108
+ </flow_mat>
109
+ </itemfeedback>
110
+ <itemfeedback ident="general_fb">
111
+ <flow_mat>
112
+ <material>
113
+ <mattext texttype="text/html">&lt;p&gt;General Feedback&lt;/p&gt;</mattext>
114
+ </material>
115
+ </flow_mat>
116
+ </itemfeedback>
117
+ </item>
118
+ <item ident="ia63b6a115fa68a555398a58626a62f83" title="Question2">
119
+ <presentation>
120
+ <material>
121
+ <mattext texttype="text/html">&lt;div&gt;&lt;p&gt;question 2&lt;/p&gt;&lt;/div&gt;</mattext>
122
+ </material>
123
+ <response_str ident="response1" rcardinality="Single">
124
+ <render_fib fibtype="Decimal">
125
+ <response_label ident="answer1"/>
126
+ </render_fib>
127
+ </response_str>
128
+ </presentation>
129
+ <resprocessing>
130
+ <outcomes>
131
+ <decvar maxvalue="100" minvalue="0" varname="SCORE" vartype="Decimal"/>
132
+ </outcomes>
133
+ <respcondition continue="No">
134
+ <conditionvar>
135
+ <or>
136
+ <varequal respident="response1">10.0</varequal>
137
+ <and>
138
+ <vargte respident="response1">10.0</vargte>
139
+ <varlte respident="response1">10.0</varlte>
140
+ </and>
141
+ </or>
142
+ </conditionvar>
143
+ <setvar action="Set" varname="SCORE">100</setvar>
144
+ <displayfeedback feedbacktype="Response" linkrefid="2001_fb"/>
145
+ </respcondition>
146
+ <respcondition continue="No">
147
+ <conditionvar>
148
+ <or>
149
+ <varequal respident="response1">20.0</varequal>
150
+ <and>
151
+ <vargte respident="response1">20.0</vargte>
152
+ <varlte respident="response1">20.0</varlte>
153
+ </and>
154
+ </or>
155
+ </conditionvar>
156
+ <setvar action="Set" varname="SCORE">100</setvar>
157
+ </respcondition>
158
+ <respcondition continue="No">
159
+ <conditionvar>
160
+ <or>
161
+ <varequal respident="response1">30.0</varequal>
162
+ <and>
163
+ <vargte respident="response1">30.0</vargte>
164
+ <varlte respident="response1">30.0</varlte>
165
+ </and>
166
+ </or>
167
+ </conditionvar>
168
+ <setvar action="Set" varname="SCORE">100</setvar>
169
+ <displayfeedback feedbacktype="Response" linkrefid="2003_fb"/>
170
+ </respcondition>
171
+ </resprocessing>
172
+ <itemfeedback ident="2001_fb">
173
+ <flow_mat>
174
+ <material>
175
+ <mattext texttype="text/html">&lt;p&gt;First answer comment&lt;/p&gt;</mattext>
176
+ </material>
177
+ </flow_mat>
178
+ </itemfeedback>
179
+ <itemfeedback ident="2003_fb">
180
+ <flow_mat>
181
+ <material>
182
+ <mattext texttype="text/html">&lt;p&gt;Third answer comment&lt;/p&gt;</mattext>
183
+ </material>
184
+ </flow_mat>
185
+ </itemfeedback>
186
+ </item>
187
+ </section>
188
+ </assessment>
189
+ </questestinterop>
@@ -110,4 +110,266 @@ describe Qti::V1::Models::Interactions::BaseInteraction do
110
110
  expect(Qti::V1::Models::Interactions::BaseInteraction.new_quizzes_fib?(assessment_item_refs.first)).to eq false
111
111
  end
112
112
  end
113
+
114
+ # The respcondition lookup in #answer_feedback is shared by every v1
115
+ # interaction, so relaxing it to reach matching's negated varequal has to
116
+ # leave the other types untouched. This fixture carries one question of each
117
+ # Canvas type, all of them fully commented.
118
+ context 'all_canvas_simple_1.2.xml' do
119
+ let(:file_path) { File.join('spec', 'fixtures', 'all_canvas_simple_1.2.xml') }
120
+
121
+ def answer_feedback_for(index)
122
+ described_class.new(assessment_item_refs[index], test_object).answer_feedback&.map do |fb|
123
+ [fb[:response_id], fb[:response_value], fb[:negated], fb[:feedback]]
124
+ end
125
+ end
126
+
127
+ it 'extracts multiple choice feedback per chosen answer' do
128
+ expect(answer_feedback_for(0)).to eq(
129
+ [
130
+ ['response1', '2799', nil, '<p>Answer feedback for C, correct</p>'],
131
+ ['response1', '9607', nil, '<p>Answer feedback for A, incorrect</p>'],
132
+ ['response1', '599', nil, '<p>Answer feedback for B, incorrect</p>'],
133
+ ['response1', '5711', nil, '<p>Answer feedback for D, incorrect</p>']
134
+ ]
135
+ )
136
+ end
137
+
138
+ it 'extracts true/false feedback per chosen answer' do
139
+ expect(answer_feedback_for(1)).to eq(
140
+ [
141
+ ['response1', '919', nil, '<p>Answer Feedback, True, Correct</p>'],
142
+ ['response1', '2680', nil, '<p>Answer Feedback, False, Incorrect</p>']
143
+ ]
144
+ )
145
+ end
146
+
147
+ it 'extracts short answer feedback per chosen answer' do
148
+ expect(answer_feedback_for(2)).to eq(
149
+ [
150
+ ['response1', 'Blank', nil, '<p>Answer Feedback, Correct, Blank</p>'],
151
+ ['response1', 'blank', nil, '<p>Answer Feedback, Correct, blank</p>']
152
+ ]
153
+ )
154
+ end
155
+
156
+ it 'extracts fill in multiple blanks feedback per blank and chosen answer' do
157
+ expect(answer_feedback_for(3)).to eq(
158
+ [
159
+ ['response_Multiple', '832', nil, '<p>Answer Feedback, correct, Multiple</p>'],
160
+ ['response_Multiple', '2173', nil, '<p>Answer Feedback, correct, multiple</p>'],
161
+ ['response_Blanks', '9226', nil, '<p>Answer Feedback, correct, Blanks</p>'],
162
+ ['response_Blanks', '1700', nil, '<p>Answer Feedback, correct, blanks</p>']
163
+ ]
164
+ )
165
+ end
166
+
167
+ it 'extracts multiple answers feedback per chosen answer' do
168
+ expect(answer_feedback_for(4)).to eq(
169
+ [
170
+ ['response1', '4094', nil, '<p>Answer Feedback, correct, A</p>'],
171
+ ['response1', '8128', nil, '<p>Answer Feedback, correct, B</p>'],
172
+ ['response1', '1582', nil, '<p>Answer Feedback, correct, C</p>'],
173
+ ['response1', '7498', nil, '<p>Answer Feedback, incorrect, D</p>'],
174
+ ['response1', '141', nil, '<p>Answer Feedback, incorrect, E</p>'],
175
+ ['response1', '3202', nil, '<p>Answer Feedback, incorrect, F</p>']
176
+ ]
177
+ )
178
+ end
179
+
180
+ it 'extracts multiple dropdowns feedback per chosen answer' do
181
+ expect(answer_feedback_for(5)).to eq(
182
+ [
183
+ ['response_C', '520', nil, '<p>Answer Feedback, correct, C</p>'],
184
+ ['response_C', '9701', nil, '<p>Answer Feedback, incorrect, D</p>']
185
+ ]
186
+ )
187
+ end
188
+
189
+ it 'extracts matching feedback per left hand item, marked as negated' do
190
+ expect(answer_feedback_for(6)).to eq(
191
+ [
192
+ ['response_2030', '6823', true, '<p>Answer Feedback, A:1 Chosen</p>'],
193
+ ['response_1293', '4469', true, '<p>Answer Feedback, B:2 Chosen</p>']
194
+ ]
195
+ )
196
+ end
197
+
198
+ it 'returns nil for the types that carry no answer level feedback' do
199
+ expect(answer_feedback_for(8)).to be_nil
200
+ expect(answer_feedback_for(9)).to be_nil
201
+ end
202
+
203
+ # The flag is additive: an entry that is not negated keeps exactly the keys
204
+ # it had before matching was supported, so a consumer pinned to an older
205
+ # gem sees no change.
206
+ it 'only adds the negated key to the negated entries' do
207
+ keys_by_item = (0..7).map do |index|
208
+ entries = described_class.new(assessment_item_refs[index], test_object).answer_feedback || []
209
+ entries.map(&:keys).uniq
210
+ end
211
+ expect(keys_by_item).to eq(
212
+ [
213
+ [%i[response_id response_value texttype feedback]],
214
+ [%i[response_id response_value texttype feedback]],
215
+ [%i[response_id response_value texttype feedback]],
216
+ [%i[response_id response_value texttype feedback]],
217
+ [%i[response_id response_value texttype feedback]],
218
+ [%i[response_id response_value texttype feedback]],
219
+ [%i[response_id response_value texttype feedback negated]],
220
+ [%i[response_id response_value texttype feedback]]
221
+ ]
222
+ )
223
+ end
224
+ end
225
+
226
+ # Question 4 has no question_type metadata and more than one response_lid, so
227
+ # it dispatches to MatchInteraction while actually being fill in multiple
228
+ # blanks -- and its feedback is on the chosen answer, not a wrong pairing.
229
+ # Deriving negated per entry rather than per question type is what keeps this
230
+ # one, and third party packages like it, correct.
231
+ context 'interaction_checks_1.2.xml' do
232
+ let(:file_path) { File.join('spec', 'fixtures', 'interaction_checks_1.2.xml') }
233
+
234
+ it 'does not mark a non-negated question as negated, whatever it dispatches to' do
235
+ item = assessment_item_refs[3]
236
+ expect(Qti::V1::Models::AssessmentItem.new(item).interaction_model)
237
+ .to be_a(Qti::V1::Models::Interactions::MatchInteraction)
238
+ expect(described_class.new(item, test_object).answer_feedback.map { |fb| fb[:negated] })
239
+ .to all(be_nil)
240
+ end
241
+
242
+ it 'still marks the genuine matching question as negated' do
243
+ expect(described_class.new(assessment_item_refs[6], test_object).answer_feedback.map { |fb| fb[:negated] })
244
+ .to all(be true)
245
+ end
246
+ end
247
+
248
+ # NumericInteraction overrides #answer_feedback entirely (it pairs answers by
249
+ # setvar SCORE, not by varequal), so it never reaches the negated flag. Its
250
+ # entries are keyed on response_index and carry no negated key at all, which
251
+ # reads the same as not negated.
252
+ context 'numeric_answer_feedback.xml' do
253
+ let(:file_path) { File.join(fixtures_path, 'numeric_answer_feedback.xml') }
254
+
255
+ it 'does not report negated for numeric, which pairs answers differently' do
256
+ entries = Qti::V1::Models::AssessmentItem.new(assessment_item_refs.first).answer_feedback
257
+ expect(entries.map(&:keys).uniq).to eq([%i[response_index texttype feedback]])
258
+ expect(entries.map { |fb| fb[:negated] }).to all(be_nil)
259
+ end
260
+ end
261
+
262
+ # Ordering emits one respcondition holding a varequal per position, with a
263
+ # single comment for the whole correct sequence. It has always been reported
264
+ # through the first varequal and no spec covered it, so the relaxed xpath
265
+ # could have changed it unnoticed.
266
+ context 'ordering.xml' do
267
+ let(:file_path) { File.join(fixtures_path, 'ordering.xml') }
268
+
269
+ it 'keeps reporting the comment on the correct sequence through its first position' do
270
+ expect(loaded_class.answer_feedback).to eq(
271
+ [{ response_id: 'OB01', response_value: 'A',
272
+ texttype: nil, feedback: 'Yes, the correct order.' }]
273
+ )
274
+ end
275
+ end
276
+
277
+ # Codifies the corpus wide check behind the xpath relaxation: matching is the
278
+ # only shape in the whole fixture corpus that yields a negated entry. Guards
279
+ # against a future xpath change quietly pulling in another type.
280
+ context 'the whole fixture corpus' do
281
+ it 'only ever reports negated entries for matching questions' do
282
+ negated = Dir.glob(File.join('spec', 'fixtures', '**', '*.xml')).sort.filter_map do |path|
283
+ assessment = begin
284
+ Qti::V1::Models::Assessment.from_path!(path)
285
+ rescue StandardError
286
+ next
287
+ end
288
+ items = assessment.assessment_items
289
+ next if items.nil?
290
+
291
+ found = items.each_with_index.select do |item, _index|
292
+ entries = begin
293
+ described_class.new(item, assessment).answer_feedback
294
+ rescue StandardError
295
+ nil
296
+ end
297
+ entries&.any? { |fb| fb[:negated] }
298
+ end
299
+ next if found.empty?
300
+
301
+ [path.sub("spec#{File::SEPARATOR}fixtures#{File::SEPARATOR}", ''), found.map(&:last)]
302
+ end
303
+
304
+ expect(negated.to_h).to eq(
305
+ 'all_canvas_simple_1.2.xml' => [6],
306
+ 'interaction_checks_1.2.xml' => [6],
307
+ "items_1.2#{File::SEPARATOR}matching_feedback.xml" => [0]
308
+ )
309
+ end
310
+ end
311
+
312
+ # Shapes the relaxed xpath newly reaches. None occur in a Canvas export, but
313
+ # third party QTI 1.2 imports through the same code path.
314
+ context 'unusual respcondition shapes' do
315
+ let(:assessment) { double(path: 'dummy/blah', package_root: 'dummy') }
316
+
317
+ def interaction_for(conditionvar)
318
+ item = <<~XML
319
+ <questestinterop xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2">
320
+ <item ident="i1" title="Question">
321
+ <resprocessing>
322
+ <respcondition>
323
+ <conditionvar>#{conditionvar}</conditionvar>
324
+ <displayfeedback feedbacktype="Response" linkrefid="99_fb"/>
325
+ </respcondition>
326
+ </resprocessing>
327
+ <itemfeedback ident="99_fb">
328
+ <flow_mat>
329
+ <material><mattext texttype="text/html">&lt;p&gt;Comment&lt;/p&gt;</mattext></material>
330
+ </flow_mat>
331
+ </itemfeedback>
332
+ </item>
333
+ </questestinterop>
334
+ XML
335
+ described_class.new(Nokogiri.XML(item, &:noblanks).at_xpath('//xmlns:item'), assessment)
336
+ end
337
+
338
+ # A compound condition is reported through its first answer only. That is
339
+ # pre-existing behaviour -- ordering questions comment a whole correct
340
+ # sequence this way -- so it is pinned here rather than changed, and the
341
+ # negated flag follows the same first varequal.
342
+ it 'reports a compound condition through its first answer' do
343
+ interaction = interaction_for(
344
+ '<and><varequal respident="response1">111</varequal>' \
345
+ '<not><varequal respident="response1">222</varequal></not></and>'
346
+ )
347
+ expect(interaction.answer_feedback).to eq(
348
+ [{ response_id: 'response1', response_value: '111',
349
+ texttype: 'text/html', feedback: '<p>Comment</p>' }]
350
+ )
351
+ end
352
+
353
+ it 'ignores a varequal without a respident when picking the answer' do
354
+ interaction = interaction_for(
355
+ '<or><varequal>raw</varequal><varequal respident="response1">111</varequal></or>'
356
+ )
357
+ expect(interaction.answer_feedback).to eq(
358
+ [{ response_id: 'response1', response_value: '111',
359
+ texttype: 'text/html', feedback: '<p>Comment</p>' }]
360
+ )
361
+ end
362
+
363
+ it 'treats a doubly negated condition as not negated' do
364
+ interaction = interaction_for(
365
+ '<not><not><varequal respident="response1">111</varequal></not></not>'
366
+ )
367
+ expect(interaction.answer_feedback.first).not_to have_key(:negated)
368
+ end
369
+
370
+ it 'marks a singly negated condition as negated' do
371
+ interaction = interaction_for('<not><varequal respident="response1">111</varequal></not>')
372
+ expect(interaction.answer_feedback.first[:negated]).to be true
373
+ end
374
+ end
113
375
  end
@@ -96,5 +96,45 @@ describe Qti::V1::Models::Interactions::MatchInteraction do
96
96
  it 'does not have any scoring algorithm' do
97
97
  expect(subject.scoring_algorithm).to eq nil
98
98
  end
99
+
100
+ describe '#answer_feedback' do
101
+ it 'returns one entry per commented left hand item, keyed on its response id' do
102
+ expect(subject.answer_feedback).to eq(
103
+ [
104
+ { response_id: 'response_6831', response_value: '6753', negated: true,
105
+ texttype: 'text/html', feedback: '<p>A:1</p>' },
106
+ { response_id: 'response_6259', response_value: '7138', negated: true,
107
+ texttype: 'text/html', feedback: '<p>B:2</p>' }
108
+ ]
109
+ )
110
+ end
111
+
112
+ it 'marks the entries as negated, since Classic shows them on a wrong pairing' do
113
+ expect(subject.answer_feedback.map { |fb| fb[:negated] }).to all(be true)
114
+ end
115
+
116
+ it 'keys every entry on a question that exists' do
117
+ expect(subject.answer_feedback.map { |fb| fb[:response_id] })
118
+ .to all(be_in(subject.questions.map { |q| q[:id] }))
119
+ end
120
+
121
+ it 'skips the left hand items without a comment' do
122
+ expect(subject.answer_feedback.map { |fb| fb[:response_id] })
123
+ .not_to include('response_743', 'response_1943')
124
+ end
125
+
126
+ it 'ignores the item level feedback' do
127
+ expect(subject.answer_feedback.map { |fb| fb[:feedback] })
128
+ .not_to include('<p>Neutral</p>', '<p>Correct</p>', '<p>Incorrect</p>')
129
+ end
130
+ end
131
+ end
132
+
133
+ context 'matching.xml without answer feedback' do
134
+ let(:file) { File.join(path, 'matching.xml') }
135
+
136
+ it 'returns nil' do
137
+ expect(subject.answer_feedback).to be_nil
138
+ end
99
139
  end
100
140
  end
@@ -140,4 +140,62 @@ describe Qti::V1::Models::Interactions::NumericInteraction do
140
140
  end
141
141
  end
142
142
  end
143
+
144
+ context 'answer feedback' do
145
+ let(:xml_file_name) { 'numeric_answer_feedback.xml' }
146
+
147
+ context 'a question with a comment on every answer type' do
148
+ let(:loaded_class) { described_class.new(assessment_item_refs.first, test_object) }
149
+
150
+ it 'returns a comment for the exact, precision, margin of error and range answers' do
151
+ expect(loaded_class.answer_feedback).to eq(
152
+ [
153
+ { response_index: 0, texttype: 'text/html', feedback: '<p>Exact answer comment</p>' },
154
+ { response_index: 1, texttype: 'text/html', feedback: '<p>Precision answer comment</p>' },
155
+ { response_index: 2, texttype: 'text/html', feedback: '<p>Margin of error answer comment</p>' },
156
+ { response_index: 3, texttype: 'text/html', feedback: '<p>Range answer comment</p>' }
157
+ ]
158
+ )
159
+ end
160
+
161
+ it 'aligns every response_index with the matching scoring_data_struct' do
162
+ structs = loaded_class.scoring_data_structs
163
+ expect(structs.map(&:type)).to eq(
164
+ %w[exactResponse preciseResponse marginOfError withinARange]
165
+ )
166
+ expect(loaded_class.answer_feedback.map { |fb| structs[fb[:response_index]].type }).to eq(
167
+ %w[exactResponse preciseResponse marginOfError withinARange]
168
+ )
169
+ end
170
+
171
+ it 'ignores the item level feedback' do
172
+ expect(loaded_class.answer_feedback.map { |fb| fb[:feedback] }).not_to include(
173
+ '<p>General Correct Feedback</p>', '<p>General Feedback</p>'
174
+ )
175
+ end
176
+ end
177
+
178
+ context 'a question where only some answers have a comment' do
179
+ let(:loaded_class) { described_class.new(assessment_item_refs[1], test_object) }
180
+
181
+ it 'keeps the index of the commented answers aligned with scoring_data_structs' do
182
+ expect(loaded_class.answer_feedback).to eq(
183
+ [
184
+ { response_index: 0, texttype: 'text/html', feedback: '<p>First answer comment</p>' },
185
+ { response_index: 2, texttype: 'text/html', feedback: '<p>Third answer comment</p>' }
186
+ ]
187
+ )
188
+ expect(loaded_class.scoring_data_structs.map(&:value)).to eq(%w[10.0 20.0 30.0])
189
+ end
190
+ end
191
+ end
192
+
193
+ context 'without answer feedback' do
194
+ let(:xml_file_name) { 'numeric_exact_match.xml' }
195
+ let(:loaded_class) { described_class.new(assessment_item_refs[1], test_object) }
196
+
197
+ it 'returns nil' do
198
+ expect(loaded_class.answer_feedback).to be_nil
199
+ end
200
+ end
143
201
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qti
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.29.0
4
+ version: 2.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Diaz
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2026-07-24 00:00:00.000000000 Z
15
+ date: 2026-09-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: actionview
@@ -412,6 +412,7 @@ files:
412
412
  - spec/fixtures/items_1.2/nq_multiple_fib_answer_types.xml
413
413
  - spec/fixtures/items_1.2/nq_multiple_fib_case_sensitive.xml
414
414
  - spec/fixtures/items_1.2/nq_multiple_fib_scoring_algorithms.xml
415
+ - spec/fixtures/items_1.2/numeric_answer_feedback.xml
415
416
  - spec/fixtures/items_1.2/numeric_exact_match.xml
416
417
  - spec/fixtures/items_1.2/numeric_margin_error.xml
417
418
  - spec/fixtures/items_1.2/numeric_margin_error_percent.xml
@@ -797,6 +798,7 @@ test_files:
797
798
  - spec/fixtures/items_1.2/nq_multiple_fib_answer_types.xml
798
799
  - spec/fixtures/items_1.2/nq_multiple_fib_case_sensitive.xml
799
800
  - spec/fixtures/items_1.2/nq_multiple_fib_scoring_algorithms.xml
801
+ - spec/fixtures/items_1.2/numeric_answer_feedback.xml
800
802
  - spec/fixtures/items_1.2/numeric_exact_match.xml
801
803
  - spec/fixtures/items_1.2/numeric_margin_error.xml
802
804
  - spec/fixtures/items_1.2/numeric_margin_error_percent.xml