Skip to content

Commit d8236e0

Browse files
committed
test: update test
1 parent 61ca0b4 commit d8236e0

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/editors/containers/ProblemEditor/data/ReactStateOLXParser.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
numericInputWithAnswerRange,
1919
textInputWithFeedbackAndHintsWithMultipleAnswers,
2020
numberParseTest,
21+
numericInputWithFractionBounds,
22+
numericInputWithEmptyUpperBound,
23+
numericInputWithSwappedBounds,
2124
} from './mockData/editorTestData';
2225
import ReactStateOLXParser from './ReactStateOLXParser';
2326

@@ -147,4 +150,32 @@ describe('Check React State OLXParser problem', () => {
147150
);
148151
});
149152
});
153+
describe('ReactStateOLXParser numerical response range parsing', () => {
154+
test('handles empty upper bound as same as lower', () => {
155+
const parser = new ReactStateOLXParser({
156+
problem: numericInputWithEmptyUpperBound,
157+
editorObject: numericInputWithEmptyUpperBound,
158+
});
159+
const result = parser.buildNumericalResponse();
160+
expect(result[':@']['@_answer']).toBe('[0,1.5]');
161+
});
162+
163+
test('handles swapped bounds and corrects order', () => {
164+
const parser = new ReactStateOLXParser({
165+
problem: numericInputWithSwappedBounds,
166+
editorObject: numericInputWithSwappedBounds,
167+
});
168+
const result = parser.buildNumericalResponse();
169+
expect(result[':@']['@_answer']).toBe('[2,5]');
170+
});
171+
172+
test('fixes swapped fraction bounds and preserves brackets', () => {
173+
const parser = new ReactStateOLXParser({
174+
problem: numericInputWithFractionBounds,
175+
editorObject: numericInputWithFractionBounds,
176+
});
177+
const result = parser.buildNumericalResponse();
178+
expect(result[':@']['@_answer']).toBe('(1/2,3/2)');
179+
});
180+
});
150181
});

src/editors/containers/ProblemEditor/data/mockData/editorTestData.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,57 @@ export const numberParseTest = {
130130
hints: [],
131131
question: '<p>What is the content of the register x2 after executing the following three lines of instructions?</p>',
132132
};
133+
134+
export const numericInputWithEmptyUpperBound = {
135+
solution: '',
136+
selectedFeedback: {
137+
a1: '<p>Feedback</p>',
138+
},
139+
hints: [],
140+
question: '<p>Question?</p>',
141+
answers: [
142+
{
143+
id: 'a1',
144+
title: '[1.5,]',
145+
correct: true,
146+
},
147+
],
148+
problemType: 'numericalresponse',
149+
settings: {},
150+
};
151+
152+
export const numericInputWithSwappedBounds = {
153+
solution: '',
154+
selectedFeedback: {
155+
a1: '<p>Feedback</p>',
156+
},
157+
hints: [],
158+
question: '<p>Question?</p>',
159+
answers: [
160+
{
161+
id: 'a1',
162+
title: '[5,2]',
163+
correct: true,
164+
},
165+
],
166+
problemType: 'numericalresponse',
167+
settings: {},
168+
};
169+
170+
export const numericInputWithFractionBounds = {
171+
solution: '',
172+
selectedFeedback: {
173+
a1: '<p>Feedback</p>',
174+
},
175+
hints: [],
176+
question: '<p>Question?</p>',
177+
answers: [
178+
{
179+
id: 'a1',
180+
title: '(3/2,1/2)',
181+
correct: true,
182+
},
183+
],
184+
problemType: 'numericalresponse',
185+
settings: {},
186+
};

0 commit comments

Comments
 (0)