Commit 98a6e662 by muhammad-ammar Committed by muzaffaryousaf

separation based on responsetypes poc

FEDX-176
parent 220cf1b4
......@@ -152,6 +152,13 @@ div.problem {
margin-top: $baseline;
}
}
span > label {
display: block;
margin-bottom: $baseline;
font: inherit;
color: inherit;
}
}
// +Problem - Choice Group
......
......@@ -189,11 +189,11 @@ describe 'MarkdownEditingDescriptor', ->
Enter 0 with a tolerance:
= 0 +- .02
""")
expect(data).toEqual("""<problem>
<p>Enter 0 with a tolerance:</p>
expect(data).toXMLEqual("""<problem>
<numericalresponse answer="0">
<responseparam type="tolerance" default=".02" />
<formulaequationinput />
<p>Enter 0 with a tolerance:</p>
<responseparam type="tolerance" default=".02"/>
<formulaequationinput/>
</numericalresponse>
......@@ -204,11 +204,11 @@ describe 'MarkdownEditingDescriptor', ->
= 1 +- .02
or= 2 +- 5%
""")
expect(data).toEqual("""<problem>
<p>Enter 1 with a tolerance:</p>
expect(data).toXMLEqual("""<problem>
<numericalresponse answer="1">
<responseparam type="tolerance" default=".02" />
<formulaequationinput />
<p>Enter 1 with a tolerance:</p>
<responseparam type="tolerance" default=".02"/>
<formulaequationinput/>
</numericalresponse>
......@@ -230,21 +230,19 @@ describe 'MarkdownEditingDescriptor', ->
The release of the iPod allowed consumers to carry their entire music library with them in a format that did not rely on fragile and energy-intensive spinning disks.
[Explanation]
""")
expect(data).toEqual("""<problem>
expect(data).toXMLEqual("""<problem>
<multiplechoiceresponse>
<p>A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.</p>
<p>One of the main elements that goes into a good multiple choice question is the existence of good distractors. That is, each of the alternate responses presented to the student should be the result of a plausible mistake that a student might make.</p>
<p>What Apple device competed with the portable CD player?</p>
<multiplechoiceresponse>
<choicegroup type="MultipleChoice">
<choicegroup type="MultipleChoice">
<choice correct="false">The iPad</choice>
<choice correct="false">Napster</choice>
<choice correct="true">The iPod</choice>
<choice correct="false">The vegetable peeler</choice>
<choice correct="false">Android</choice>
<choice correct="false">The Beatles</choice>
</choicegroup>
</choicegroup>
</multiplechoiceresponse>
<solution>
......@@ -273,14 +271,12 @@ describe 'MarkdownEditingDescriptor', ->
The release of the iPod allowed consumers to carry their entire music library with them in a format that did not rely on fragile and energy-intensive spinning disks.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.</p>
expect(data).toXMLEqual("""<problem>
<multiplechoiceresponse>
<p>A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.</p>
<p>One of the main elements that goes into a good multiple choice question is the existence of good distractors. That is, each of the alternate responses presented to the student should be the result of a plausible mistake that a student might make.</p>
<p>What Apple device competed with the portable CD player?</p>
<multiplechoiceresponse>
<choicegroup type="MultipleChoice" shuffle="true">
<choicegroup type="MultipleChoice" shuffle="true">
<choice correct="true" fixed="true">The iPad</choice>
<choice correct="false" fixed="true">Napster</choice>
<choice correct="false">The iPod</choice>
......@@ -367,15 +363,12 @@ describe 'MarkdownEditingDescriptor', ->
Multiple Choice also allows students to select from a variety of pre-written responses, although the format makes it easier for students to read very long response options. Optionresponse also differs slightly because students are more likely to think of an answer and then search for it rather than relying purely on recognition to answer the question.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>OptionResponse gives a limited set of options for students to respond with, and presents those options in a format that encourages them to search for a specific answer rather than being immediately presented with options from which to recognize the correct answer.</p>
expect(data).toXMLEqual("""<problem>
<optionresponse>
<p>OptionResponse gives a limited set of options for students to respond with, and presents those options in a format that encourages them to search for a specific answer rather than being immediately presented with options from which to recognize the correct answer.</p>
<p>The answer options and the identification of the correct answer is defined in the <b>optioninput</b> tag.</p>
<p>Translation between Option Response and __________ is extremely straightforward:</p>
<optionresponse>
<optioninput options="('Multiple Choice','String Response','Numerical Response','External Response','Image Response')" correct="Multiple Choice"></optioninput>
<optioninput options="('Multiple Choice','String Response','Numerical Response','External Response','Image Response')" correct="Multiple Choice"/>
</optionresponse>
<solution>
......@@ -399,14 +392,12 @@ describe 'MarkdownEditingDescriptor', ->
Lansing is the capital of Michigan, although it is not Michgan's largest city, or even the seat of the county in which it resides.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>A string response problem accepts a line of text input from the student, and evaluates the input for correctness based on an expected answer within each input box.</p>
expect(data).toXMLEqual("""<problem>
<stringresponse answer="Michigan" type="ci">
<p>A string response problem accepts a line of text input from the student, and evaluates the input for correctness based on an expected answer within each input box.</p>
<p>The answer is correct if it matches every character of the expected answer. This can be a problem with international spelling, dates, or anything where the format of the answer is not clear.</p>
<p>Which US state has Lansing as its capital?</p>
<stringresponse answer="Michigan" type="ci" >
<textline size="20"/>
<textline size="20"/>
</stringresponse>
<solution>
......@@ -426,10 +417,10 @@ describe 'MarkdownEditingDescriptor', ->
Test Explanation.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>Who lead the civil right movement in the United States of America?</p>
<stringresponse answer="\w*\.?\s*Luther King\s*.*" type="ci regexp" >
<textline size="20"/>
expect(data).toXMLEqual("""<problem>
<stringresponse answer="w*.?s*Luther Kings*.*" type="ci regexp">
<p>Who lead the civil right movement in the United States of America?</p>
<textline size="20"/>
</stringresponse>
<solution>
......@@ -452,12 +443,12 @@ describe 'MarkdownEditingDescriptor', ->
Test Explanation.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>Who lead the civil right movement in the United States of America?</p>
<stringresponse answer="Dr. Martin Luther King Jr." type="ci" >
<additional_answer answer="Doctor Martin Luther King Junior"></additional_answer>
<additional_answer answer="Martin Luther King"></additional_answer>
<additional_answer answer="Martin Luther King Junior"></additional_answer>
expect(data).toXMLEqual("""<problem>
<stringresponse answer="Dr. Martin Luther King Jr." type="ci">
<p>Who lead the civil right movement in the United States of America?</p>
<additional_answer answer="Doctor Martin Luther King Junior"/>
<additional_answer answer="Martin Luther King"/>
<additional_answer answer="Martin Luther King Junior"/>
<textline size="20"/>
</stringresponse>
......@@ -481,12 +472,12 @@ describe 'MarkdownEditingDescriptor', ->
Test Explanation.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>Write a number from 1 to 4.</p>
<stringresponse answer="^One$" type="ci regexp" >
<additional_answer answer="two"></additional_answer>
<additional_answer answer="^thre+"></additional_answer>
<additional_answer answer="^4|Four$"></additional_answer>
expect(data).toXMLEqual("""<problem>
<stringresponse answer="^One$" type="ci regexp">
<p>Write a number from 1 to 4.</p>
<additional_answer answer="two"/>
<additional_answer answer="^thre+"/>
<additional_answer answer="^4|Four$"/>
<textline size="20"/>
</stringresponse>
......@@ -508,21 +499,21 @@ describe 'MarkdownEditingDescriptor', ->
Test Explanation.
[Explanation]
""")
expect(data).toEqual("""<problem>
<p>Who lead the civil right movement in the United States of America?</p>
<stringresponse answer="w*.?s*Luther Kings*.*" type="ci regexp" >
<textline label="Who lead the civil right movement in the United States of America?" size="20"/>
</stringresponse>
expect(data).toXMLEqual("""<problem>
<stringresponse answer="w*.?s*Luther Kings*.*" type="ci regexp">
<label>Who lead the civil right movement in the United States of America?</label>
<textline label="Who lead the civil right movement in the United States of America?" size="20"/>
</stringresponse>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p>Test Explanation.</p>
<p>Test Explanation.</p>
</div>
</solution>
</problem>""")
</div>
</solution>
</problem>""")
it 'handles multiple questions with labels', ->
data = MarkdownEditingDescriptor.markdownToXml("""
France is a country in Europe.
......@@ -538,7 +529,7 @@ describe 'MarkdownEditingDescriptor', ->
(x) Berlin
( ) Donut
""")
expect(data).toEqual("""<problem>
expect(data).toXMLEqual("""<problem>
<p>France is a country in Europe.</p>
<p>What is the capital of France?</p>
......@@ -575,7 +566,7 @@ describe 'MarkdownEditingDescriptor', ->
(x) Berlin
( ) Donut
""")
expect(data).toEqual("""<problem>
expect(data).toXMLEqual("""<problem>
<p>France is a country in Europe.</p>
<p>What is the capital of France?</p>
......@@ -597,66 +588,22 @@ describe 'MarkdownEditingDescriptor', ->
</problem>""")
it 'tests malformed labels', ->
data = MarkdownEditingDescriptor.markdownToXml("""
France is a country in Europe.
>>What is the capital of France?<
= Paris
blah>>What is the capital of <<Germany?<<
( ) Bonn
( ) Hamburg
(x) Berlin
( ) Donut
""")
expect(data).toEqual("""<problem>
<p>France is a country in Europe.</p>
<p>>>What is the capital of France?<</p>
<stringresponse answer="Paris" type="ci" >
<textline size="20"/>
</stringresponse>
<p>blahWhat is the capital of Germany?</p>
<multiplechoiceresponse>
<choicegroup label="What is the capital of &lt;&lt;Germany?" type="MultipleChoice">
<choice correct="false">Bonn</choice>
<choice correct="false">Hamburg</choice>
<choice correct="true">Berlin</choice>
<choice correct="false">Donut</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>""")
it 'adds labels to formulae', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>Enter the numerical value of Pi:<<
= 3.14159 +- .02
""")
expect(data).toEqual("""<problem>
<p>Enter the numerical value of Pi:</p>
<numericalresponse answer="3.14159">
<responseparam type="tolerance" default=".02" />
<formulaequationinput label="Enter the numerical value of Pi:" />
</numericalresponse>
expect(data).toXMLEqual("""<problem>
<numericalresponse answer="3.14159">
<label>Enter the numerical value of Pi:</label>
<responseparam type="tolerance" default=".02"/>
<formulaequationinput label="Enter the numerical value of Pi:"/>
</numericalresponse>
</problem>""")
it 'escapes entities in labels', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>What is the "capital" of France & the 'best' > place < to live"?<<
= Paris
""")
expect(data).toEqual("""<problem>
<p>What is the "capital" of France & the 'best' > place < to live"?</p>
<stringresponse answer="Paris" type="ci" >
<textline label="What is the &quot;capital&quot; of France &amp; the &apos;best&apos; &gt; place &lt; to live&quot;?" size="20"/>
</stringresponse>
</problem>""")
</problem>""")
# test oddities
it 'converts headers and oddities to xml', ->
data = MarkdownEditingDescriptor.markdownToXml("""Not a header
......@@ -780,4 +727,187 @@ describe 'MarkdownEditingDescriptor', ->
Code should be nicely monospaced.
</code></pre>
</problem>""")
# failure tests
it 'can separate responsetypes based on ---', ->
data = MarkdownEditingDescriptor.markdownToXml("""
Multiple choice problems allow learners to select only one option. Learners can see all the options along with the problem text.
>>Which of the following countries has the largest population?<<
( ) Brazil {{ timely feedback -- explain why an almost correct answer is wrong }}
( ) Germany
(x) Indonesia
( ) Russia
[explanation]
According to September 2014 estimates:
The population of Indonesia is approximately 250 million.
The population of Brazil is approximately 200 million.
The population of Russia is approximately 146 million.
The population of Germany is approximately 81 million.
[explanation]
---
Checkbox problems allow learners to select multiple options. Learners can see all the options along with the problem text.
>>The following languages are in the Indo-European family:<<
[x] Urdu
[ ] Finnish
[x] Marathi
[x] French
[ ] Hungarian
Note: Make sure you select all of the correct options—there may be more than one!
[explanation]
Urdu, Marathi, and French are all Indo-European languages, while Finnish and Hungarian are in the Uralic family.
[explanation]
""")
expect(data).toXMLEqual("""
<problem>
<multiplechoiceresponse>
<p>Multiple choice problems allow learners to select only one option. Learners can see all the options along with the problem text.</p>
<label>Which of the following countries has the largest population?</label>
<choicegroup label="Which of the following countries has the largest population?" type="MultipleChoice">
<choice correct="false">Brazil <choicehint>timely feedback -- explain why an almost correct answer is wrong</choicehint>
</choice>
<choice correct="false">Germany</choice>
<choice correct="true">Indonesia</choice>
<choice correct="false">Russia</choice>
</choicegroup>
</multiplechoiceresponse>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p>According to September 2014 estimates:</p>
<p>The population of Indonesia is approximately 250 million.</p>
<p>The population of Brazil is approximately 200 million.</p>
<p>The population of Russia is approximately 146 million.</p>
<p>The population of Germany is approximately 81 million.</p>
</div>
</solution>
<choiceresponse>
<p>Checkbox problems allow learners to select multiple options. Learners can see all the options along with the problem text.</p>
<label>The following languages are in the Indo-European family:</label>
<checkboxgroup label="The following languages are in the Indo-European family:">
<choice correct="true">Urdu</choice>
<choice correct="false">Finnish</choice>
<choice correct="true">Marathi</choice>
<choice correct="true">French</choice>
<choice correct="false">Hungarian</choice>
</checkboxgroup>
<p>Note: Make sure you select all of the correct options—there may be more than one!</p>
</choiceresponse>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p>Urdu, Marathi, and French are all Indo-European languages, while Finnish and Hungarian are in the Uralic family.</p>
</div>
</solution>
</problem>
""")
it 'can separate other things based on ---', ->
data = MarkdownEditingDescriptor.markdownToXml("""
Multiple choice problems allow learners to select only one option. Learners can see all the options along with the problem text.
---
>>Which of the following countries has the largest population?<<
( ) Brazil {{ timely feedback -- explain why an almost correct answer is wrong }}
( ) Germany
(x) Indonesia
( ) Russia
[explanation]
According to September 2014 estimates:
The population of Indonesia is approximately 250 million.
The population of Brazil is approximately 200 million.
The population of Russia is approximately 146 million.
The population of Germany is approximately 81 million.
[explanation]
""")
expect(data).toXMLEqual("""
<problem>
<p>Multiple choice problems allow learners to select only one option. Learners can see all the options along with the problem text.</p>
<multiplechoiceresponse>
<label>Which of the following countries has the largest population?</label>
<choicegroup label="Which of the following countries has the largest population?" type="MultipleChoice">
<choice correct="false">Brazil <choicehint>timely feedback -- explain why an almost correct answer is wrong</choicehint>
</choice>
<choice correct="false">Germany</choice>
<choice correct="true">Indonesia</choice>
<choice correct="false">Russia</choice>
</choicegroup>
</multiplechoiceresponse>
<solution>
<div class="detailed-solution">
<p>Explanation</p>
<p>According to September 2014 estimates:</p>
<p>The population of Indonesia is approximately 250 million.</p>
<p>The population of Brazil is approximately 200 million.</p>
<p>The population of Russia is approximately 146 million.</p>
<p>The population of Germany is approximately 81 million.</p>
</div>
</solution>
</problem>
""")
it 'can do separation if spaces are prsent around ---', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>The following languages are in the Indo-European family:<<
[x] Urdu
[ ] Finnish
[x] Marathi
[x] French
[ ] Hungarian
---
>>Which of the following countries has the largest population?<<
( ) Brazil {{ timely feedback -- explain why an almost correct answer is wrong }}
( ) Germany
(x) Indonesia
( ) Russia
""")
expect(data).toXMLEqual("""
<problem>
<choiceresponse>
<label>The following languages are in the Indo-European family:</label>
<checkboxgroup label="The following languages are in the Indo-European family:">
<choice correct="true">Urdu</choice>
<choice correct="false">Finnish</choice>
<choice correct="true">Marathi</choice>
<choice correct="true">French</choice>
<choice correct="false">Hungarian</choice>
</checkboxgroup>
</choiceresponse>
<multiplechoiceresponse>
<label>Which of the following countries has the largest population?</label>
<choicegroup label="Which of the following countries has the largest population?" type="MultipleChoice">
<choice correct="false">Brazil <choicehint>timely feedback -- explain why an almost correct answer is wrong</choicehint>
</choice>
<choice correct="false">Germany</choice>
<choice correct="true">Indonesia</choice>
<choice correct="false">Russia</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
""")
......@@ -14,11 +14,11 @@ describe 'Markdown to xml extended hint dropdown', ->
Clowns have funny _________ to make people laugh.
[[
dogs {{ NOPE::Not dogs, not cats, not toads }}
(FACES) {{ With lots of makeup, doncha know?}}
money {{ Clowns don't have any money, of course }}
donkeys {{don't be an ass.}}
-no hint-
......@@ -46,7 +46,7 @@ describe 'Markdown to xml extended hint dropdown', ->
<option correct="False">-no hint-</option>
</optioninput>
</optionresponse>
</problem>
""")
......@@ -64,14 +64,17 @@ describe 'Markdown to xml extended hint dropdown', ->
|| 1) one ||
|| 2) two ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Translation between Dropdown and ________ is straightforward.</p>
<optionresponse>
<optioninput>
<option correct="True">Right <optionhint label="Good Job">yes</optionhint></option>
<option correct="False">Wrong 1 <optionhint>no</optionhint></option>
<option correct="False">Wrong 2 <optionhint label="Label">no</optionhint></option>
<p>Translation between Dropdown and ________ is straightforward.</p>
<optioninput>
<option correct="True">Right <optionhint label="Good Job">yes</optionhint>
</option>
<option correct="False">Wrong 1 <optionhint>no</optionhint>
</option>
<option correct="False">Wrong 2 <optionhint label="Label">no</optionhint>
</option>
</optioninput>
</optionresponse>
......@@ -91,11 +94,11 @@ describe 'Markdown to xml extended hint dropdown', ->
|| 0) zero ||
|| 1) one ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>A Question ________ is answered.</p>
<optionresponse>
<optioninput options="('Right','Wrong 1','Wrong 2')" correct="Right"></optioninput>
<p>A Question ________ is answered.</p>
<optioninput options="('Right','Wrong 1','Wrong 2')" correct="Right"/>
</optionresponse>
<demandhint>
......@@ -112,19 +115,20 @@ describe 'Markdown to xml extended hint dropdown', ->
bb
cc {{ hint2 }} ]]
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q1</p>
<optionresponse>
<optioninput label="q1">
<option correct="True">aa <optionhint>hint1</optionhint></option>
<label>q1</label>
<optioninput label="q1">
<option correct="True">aa <optionhint>hint1</optionhint>
</option>
<option correct="False">bb</option>
<option correct="False">cc <optionhint>hint2</optionhint></option>
<option correct="False">cc <optionhint>hint2</optionhint>
</option>
</optioninput>
</optionresponse>
</problem>
""")
......@@ -132,28 +136,29 @@ describe 'Markdown to xml extended hint dropdown', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>q1<<
[[
aa {{ hint1 }}
bb {{ hint2 }}
(cc)
]]
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q1</p>
<optionresponse>
<optioninput label="q1">
<option correct="False">aa <optionhint>hint1</optionhint></option>
<option correct="False">bb <optionhint>hint2</optionhint></option>
<label>q1</label>
<optioninput label="q1">
<option correct="False">aa <optionhint>hint1</optionhint>
</option>
<option correct="False">bb <optionhint>hint2</optionhint>
</option>
<option correct="True">cc</option>
</optioninput>
</optionresponse>
</problem>
""")
......@@ -161,20 +166,20 @@ describe 'Markdown to xml extended hint checkbox', ->
it 'produces xml', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>Select all the fruits from the list<<
[x] Apple {{ selected: You're right that apple is a fruit. }, {unselected: Remember that apple is also a fruit.}}
[ ] Mushroom {{U: You're right that mushrooms aren't fruit}, { selected: Mushroom is a fungus, not a fruit.}}
[x] Grape {{ selected: You're right that grape is a fruit }, {unselected: Remember that grape is also a fruit.}}
[ ] Mustang
[ ] Camero {{S:I don't know what a Camero is but it isn't a fruit.},{U:What is a camero anyway?}}
{{ ((A*B)) You're right that apple is a fruit, but there's one you're missing. Also, mushroom is not a fruit.}}
{{ ((B*C)) You're right that grape is a fruit, but there's one you're missing. Also, mushroom is not a fruit. }}
>>Select all the vegetables from the list<<
[ ] Banana {{ selected: No, sorry, a banana is a fruit. }, {unselected: poor banana.}}
[ ] Ice Cream
[ ] Mushroom {{U: You're right that mushrooms aren't vegetables.}, { selected: Mushroom is a fungus, not a vegetable.}}
......@@ -184,7 +189,7 @@ describe 'Markdown to xml extended hint checkbox', ->
{{ ((A*B)) Making a banana split? }}
{{ ((B*D)) That will make a horrible dessert: a brussel sprout split? }}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Select all the fruits from the list</p>
<choiceresponse>
......@@ -262,7 +267,7 @@ describe 'Markdown to xml extended hint checkbox', ->
|| Hint two. ||
|| Hint three. ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Select all the fruits from the list</p>
<choiceresponse>
......@@ -317,7 +322,7 @@ describe 'Markdown to xml extended hint multiple choice', ->
it 'produces xml', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>Select the fruit from the list<<
() Mushroom {{ Mushroom is a fungus, not a fruit.}}
() Potato
(x) Apple {{ OUTSTANDING::Apple is indeed a fruit.}}
......@@ -328,7 +333,7 @@ describe 'Markdown to xml extended hint multiple choice', ->
(x) Potato {{ Potato is a root vegetable. }}
() Apple {{ OOPS::Apple is a fruit.}}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Select the fruit from the list</p>
<multiplechoiceresponse>
......@@ -338,7 +343,7 @@ describe 'Markdown to xml extended hint multiple choice', ->
<choice correct="true">Apple <choicehint label="OUTSTANDING">Apple is indeed a fruit.</choicehint></choice>
</choicegroup>
</multiplechoiceresponse>
<p>Select the vegetables from the list</p>
<multiplechoiceresponse>
<choicegroup label="Select the vegetables from the list" type="MultipleChoice">
......@@ -347,8 +352,8 @@ describe 'Markdown to xml extended hint multiple choice', ->
<choice correct="false">Apple <choicehint label="OOPS">Apple is a fruit.</choicehint></choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
""")
......@@ -359,24 +364,24 @@ describe 'Markdown to xml extended hint multiple choice', ->
() Mushroom {{ Mushroom is a fungus, not a fruit.}}
() Potato
(x) Apple {{ OUTSTANDING::Apple is indeed a fruit.}}
|| 0) spaces on previous line. ||
|| 1) roses are red. ||
>>Select the vegetables from the list<<
() Mushroom {{ Mushroom is a fungus, not a vegetable.}}
(x) Potato {{ Potato is a root vegetable. }}
() Apple {{ OOPS::Apple is a fruit.}}
|| 2) where are the lions? ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Select the fruit from the list</p>
<multiplechoiceresponse>
......@@ -412,14 +417,15 @@ describe 'Markdown to xml extended hint text input', ->
= France {{ BRAVO::Viva la France! }}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>In which country would you find the city of Paris?</p>
<stringresponse answer="France" type="ci" >
<correcthint label="BRAVO">Viva la France!</correcthint>
<stringresponse answer="France" type="ci">
<label>In which country would you find the city of Paris?</label>
<correcthint label="BRAVO">Viva la France!</correcthint>
<textline label="In which country would you find the city of Paris?" size="20"/>
</stringresponse>
</problem>
""")
......@@ -429,15 +435,17 @@ describe 'Markdown to xml extended hint text input', ->
or= USA {{ meh::hint2 }}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Where Paris?</p>
<stringresponse answer="France" type="ci" >
<correcthint label="BRAVO">hint1</correcthint>
<additional_answer answer="USA"><correcthint label="meh">hint2</correcthint></additional_answer>
<stringresponse answer="France" type="ci">
<label>Where Paris?</label>
<correcthint label="BRAVO">hint1</correcthint>
<additional_answer answer="USA"><correcthint label="meh">hint2</correcthint>
</additional_answer>
<textline label="Where Paris?" size="20"/>
</stringresponse>
</problem>
""")
......@@ -447,15 +455,16 @@ describe 'Markdown to xml extended hint text input', ->
not= warm {{feedback2}}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Revenge is a dish best served</p>
<stringresponse answer="cold" type="ci" >
<correcthint>khaaaaaan!</correcthint>
<stringresponse answer="cold" type="ci">
<label>Revenge is a dish best served</label>
<correcthint>khaaaaaan!</correcthint>
<stringequalhint answer="warm">feedback2</stringequalhint>
<textline label="Revenge is a dish best served" size="20"/>
</stringresponse>
</problem>
""")
......@@ -464,14 +473,15 @@ describe 'Markdown to xml extended hint text input', ->
s= 2 {{feedback1}}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q</p>
<stringresponse answer="2" type="ci" >
<correcthint>feedback1</correcthint>
<stringresponse answer="2" type="ci">
<label>q</label>
<correcthint>feedback1</correcthint>
<textline label="q" size="20"/>
</stringresponse>
</problem>
""")
......@@ -483,16 +493,18 @@ describe 'Markdown to xml extended hint text input', ->
or= ccc
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q</p>
<stringresponse answer="aaa" type="ci" >
<additional_answer answer="bbb"><correcthint>feedback1</correcthint></additional_answer>
<stringresponse answer="aaa" type="ci">
<label>q</label>
<additional_answer answer="bbb"><correcthint>feedback1</correcthint>
</additional_answer>
<stringequalhint answer="no">feedback2</stringequalhint>
<additional_answer answer="ccc"></additional_answer>
<additional_answer answer="ccc"/>
<textline label="q" size="20"/>
</stringresponse>
</problem>
""")
......@@ -503,16 +515,18 @@ describe 'Markdown to xml extended hint text input', ->
or= ccc
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q</p>
<stringresponse answer="2" type="ci" >
<correcthint>feedback1</correcthint>
<additional_answer answer="bbb"><correcthint>feedback2</correcthint></additional_answer>
<additional_answer answer="ccc"></additional_answer>
<stringresponse answer="2" type="ci">
<label>q</label>
<correcthint>feedback1</correcthint>
<additional_answer answer="bbb"><correcthint>feedback2</correcthint>
</additional_answer>
<additional_answer answer="ccc"/>
<textline label="q" size="20"/>
</stringresponse>
</problem>
""")
......@@ -523,7 +537,7 @@ describe 'Markdown to xml extended hint text input', ->
s= ccc
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q</p>
<stringresponse answer="aaa" type="ci" >
......@@ -549,7 +563,7 @@ describe 'Markdown to xml extended hint text input', ->
paragraph 2
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>paragraph</p>
<p>q</p>
......@@ -574,7 +588,7 @@ describe 'Markdown to xml extended hint text input', ->
paragraph 2
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>paragraph</p>
<p>q</p>
......@@ -591,7 +605,7 @@ describe 'Markdown to xml extended hint text input', ->
= ccc {{feedback2}}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q</p>
<stringresponse answer="aaa" type="ci" >
......@@ -614,11 +628,11 @@ describe 'Markdown to xml extended hint text input', ->
|| Paris is the capital of one of those countries. ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Where Paris?</p>
<stringresponse answer="France" type="ci" >
<correcthint label="BRAVO">hint1</correcthint>
<stringresponse answer="France" type="ci">
<label>Where Paris?</label>
<correcthint label="BRAVO">hint1</correcthint>
<textline label="Where Paris?" size="20"/>
</stringresponse>
......@@ -640,10 +654,10 @@ describe 'Markdown to xml extended hint numeric input', ->
>>Enter the number of fingers on a human hand<<
= 5
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Enter the numerical value of Pi:</p>
<numericalresponse answer="3.14159">
......@@ -681,7 +695,7 @@ describe 'Markdown to xml extended hint numeric input', ->
|| hintB ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>text1</p>
<numericalresponse answer="1">
......@@ -707,10 +721,10 @@ describe 'Markdown to xml extended hint with multiline hints', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>Checkboxes<<
[x] A {{
[x] A {{
selected: aaa },
{unselected:bbb}}
[ ] B {{U: c}, {
[ ] B {{U: c}, {
selected: d.}}
{{ ((A*B)) A*B hint}}
......@@ -725,7 +739,7 @@ describe 'Markdown to xml extended hint with multiline hints', ->
hello
hint
}}
>>multiple choice<<
(x) AA{{hint1}}
() BB {{
......@@ -733,11 +747,11 @@ describe 'Markdown to xml extended hint with multiline hints', ->
}}
( ) CC {{ hint3
}}
>>dropdown<<
[[
W1 {{
no }}
W1 {{
no }}
W2 {{
nope}}
(C1) {{ yes
......@@ -749,7 +763,7 @@ describe 'Markdown to xml extended hint with multiline hints', ->
|| ccc ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>Checkboxes</p>
<choiceresponse>
......@@ -816,23 +830,23 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
|| Ø ||
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>á and Ø</p>
<multiplechoiceresponse>
<choicegroup label="á and Ø" type="MultipleChoice">
<choice correct="true">Ø <choicehint>Ø</choicehint></choice>
<label>á and Ø</label>
<choicegroup label="á and Ø" type="MultipleChoice">
<choice correct="true">Ø <choicehint>Ø</choicehint>
</choice>
<choice correct="false">BB</choice>
</choicegroup>
</multiplechoiceresponse>
<demandhint>
<hint>Ø</hint>
</demandhint>
</problem>
""")
it 'produces xml with quote-type characters', ->
data = MarkdownEditingDescriptor.markdownToXml("""
>>"quotes" aren't `fun`<<
......@@ -840,13 +854,15 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
(x) "isn't" {{ "hello" }}
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>"quotes" aren't `fun`</p>
<multiplechoiceresponse>
<choicegroup label="&quot;quotes&quot; aren&apos;t `fun`" type="MultipleChoice">
<choice correct="false">"hello" <choicehint>isn't</choicehint></choice>
<choice correct="true">"isn't" <choicehint>"hello"</choicehint></choice>
<label>"quotes" aren't `fun`</label>
<choicegroup label="&quot;quotes&quot; aren't `fun`" type="MultipleChoice">
<choice correct="false">"hello" <choicehint>isn't</choicehint>
</choice>
<choice correct="true">"isn't" <choicehint>"hello"</choicehint>
</choice>
</choicegroup>
</multiplechoiceresponse>
......@@ -862,18 +878,20 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
(x) b
that (y)
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q1</p>
<p>this (x)</p>
<multiplechoiceresponse>
<choicegroup label="q1" type="MultipleChoice">
<choice correct="false">a <choicehint>(hint)</choicehint></choice>
<label>q1</label>
<p>this (x)</p>
<choicegroup label="q1" type="MultipleChoice">
<choice correct="false">a <choicehint>(hint)</choicehint>
</choice>
<choice correct="true">b</choice>
</choicegroup>
<p>that (y)</p>
</multiplechoiceresponse>
<p>that (y)</p>
</problem>
""")
......@@ -886,18 +904,19 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
[x] b {{ this hint passes through }}
that []
""")
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q1</p>
<p>this [x]</p>
<choiceresponse>
<checkboxgroup label="q1">
<label>q1</label>
<p>this [x]</p>
<checkboxgroup label="q1">
<choice correct="false">a [square]</choice>
<choice correct="true">b {{ this hint passes through }}</choice>
</checkboxgroup>
<p>that []</p>
</choiceresponse>
<p>that []</p>
</problem>
""")
......@@ -907,7 +926,7 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
markdown = """
>>q22<<
[[
[[
(x) {{ hintx
these
span
......@@ -919,18 +938,20 @@ describe 'Markdown to xml extended hint with tricky syntax cases', ->
"""
markdown = markdown.replace(/\n/g, '\r\n') # make DOS line endings
data = MarkdownEditingDescriptor.markdownToXml(markdown)
expect(data).toEqual("""
expect(data).toXMLEqual("""
<problem>
<p>q22</p>
<optionresponse>
<optioninput label="q22">
<option correct="True">x <optionhint>hintx these span</optionhint></option>
<option correct="False">yy <optionhint label="meh">hinty</optionhint></option>
<option correct="False">zzz <optionhint>hintz</optionhint></option>
<label>q22</label>
<optioninput label="q22">
<option correct="True">x <optionhint>hintx these span</optionhint>
</option>
<option correct="False">yy <optionhint label="meh">hinty</optionhint>
</option>
<option correct="False">zzz <optionhint>hintz</optionhint>
</option>
</optioninput>
</optionresponse>
</problem>
""")
......@@ -192,11 +192,15 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
else
return template
@markdownToXml: (markdown)->
# it will contain <hint>...</hint> tags
demandHintTags = [];
toXml = `function (markdown) {
var xml = markdown,
i, splits, scriptFlag;
var responseTypes = [
'optionresponse', 'multiplechoiceresponse', 'stringresponse', 'numericalresponse', 'choiceresponse'
];
// fix DOS \r\n line endings to look like \n
xml = xml.replace(/\r\n/g, '\n');
......@@ -212,6 +216,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
for (i = 0; i < options.length; i += 1) {
var inner = /\s*\|\|(.*?)\|\|/.exec(options[i]);
if (inner) {
//safe-lint: disable=javascript-concat-html
demandhints += ' <hint>' + inner[1].trim() + '</hint>\n';
}
}
......@@ -524,7 +529,8 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
line = line.replace(/>>|<</g, '');
// extract the question text and convert it to a <p> tag
line = line.replace(/>>(.*?)<</, "<p class='qtitle'>$1</p>");
} else if (line.match(/<\w+response/) && didinput && curlabel == prevlabel) {
// reset label to prevent gobbling up previous one (if multiple questions)
curlabel = '';
......@@ -570,12 +576,83 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
// if we've come across demand hints, wrap in <demandhint> at the end
if (demandhints) {
demandhints = '\n<demandhint>\n' + demandhints + '</demandhint>';
demandHintTags.push(demandhints);
}
// make all elements descendants of a single problem element
xml = '<problem>\n' + xml + demandhints + '\n</problem>';
// make selector to search responsetypes in xml
var responseTypesSelector = responseTypes.join(', ');
// these will be placed at outside the end of responsetype
var independentTagNames = ['solution'];
var independentTagNodes = [];
// make temporary xml
// safe-lint: disable=javascript-concat-html
var $xml = $($.parseXML('<prob>' + xml + '</prob>'));
responseType = $xml.find(responseTypesSelector);
// convert if there is only one responsetype
if (responseType.length === 1) {
var inputtype = responseType[0].firstElementChild
// used to decide whether an element should be placed before or after an inputtype
var beforeInputtype = true;
_.each($xml.find('prob').children(), function(child, index){
// we don't want to add the responsetype again into new xml
if (responseType[0].nodeName === child.nodeName) {
beforeInputtype = false;
return;
}
// replace <p> tag for question title with <label> tag
if (child.hasAttribute('class') && child.getAttribute('class') === 'qtitle') {
child = $('<label>' + child.textContent + '</label>')[0];
}
if (_.contains(independentTagNames, child.nodeName)) {
independentTagNodes.push(child)
return;
}
if (beforeInputtype) {
// safe-lint: disable=javascript-jquery-insert-into-target
responseType[0].insertBefore(child, inputtype);
} else {
responseType[0].appendChild(child);
}
})
var serializer = new XMLSerializer();
// combine responsetype and independent tags
xml = serializer.serializeToString(responseType[0]) + '\n\n' + _.map(independentTagNodes, function(node){
return serializer.serializeToString(node)
}).join('\n\n');
// remove xmlns attribute added by the serializer
xml = xml.replace(/\sxmlns=['"].*?['"]/gi, '');
// XMLSerializer messes the indentation of XML so add newline
// at the end of each ending tag to make the xml looks better
xml = xml.replace(/(\<\/.*?\>)(\<.*?\>)/gi, '$1\n$2');
}
// remove class attribute added on <p> tag for question title
xml = xml.replace(/\sclass=\'qtitle\'/gi, '');
return xml;
}`
return toXml markdown
responseTypesXML = []
responseTypesMarkdown = markdown.split(/\n\s*---\s*\n/g)
_.each responseTypesMarkdown, (responseTypeMarkdown, index) ->
if responseTypeMarkdown.trim().length > 0
responseTypesXML.push toXml(responseTypeMarkdown)
# combine demandhints
demandHints = ''
if demandHintTags.length
## safe-lint: disable=javascript-concat-html
demandHints = '\n<demandhint>\n' + demandHintTags.join('') + '</demandhint>'
# make all responsetypes descendants of a single problem element
## safe-lint: disable=javascript-concat-html
return '<problem>\n' + responseTypesXML.join('\n\n') + demandHints + '\n</problem>'
......@@ -86,6 +86,15 @@
};
}
};
},
toXMLEqual: function() {
return {
compare: function(actual, expected) {
return {
pass: actual.replace(/\s+/g, '') === expected.replace(/\s+/g, '')
};
}
};
}
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment