rustla/parser/tests/
test_aplus_questionnaire.rs

1/*!
2A submodule for testing A+ questionnaire directrives.
3
4Copyright © 2020 Santtu Söderholm
5*/
6
7
8use super::*;
9
10#[cfg(test)]
11#[test]
12fn aplus_questionnaire_01() {
13    let src =
14r#"
15.. questionnaire:: 1 A
16  :submissions: 4
17  :points-to-pass: 0
18
19  This is a questionnaire with the key `1` that grants at maximum 70 points
20  of difficulty A. Students can make at most 4 submissions.
21  This exercise is marked passed when 0 points are reached (the default).
22
23  .. pick-one:: 10
24    :required:
25
26    What is 1+1?
27
28    a. 1
29    *b. 2
30    c. 3
31
32    !b § Count again!
33    b § That is correct!
34    c § Too much
35
36  (Hints can be included or omitted in any question.)
37
38  .. pick-one:: 10
39    :required:
40    :dropdown:
41
42    What is 1+2?
43
44    +0. 0
45    1. 1
46    2. 2
47    *3. 3
48
49  .. pick-any:: 10
50    :partial-points:
51
52    Pick the two **first**. Since the 'partial-points' option is set,
53    some points are awarded with a partially correct answer. If either one of the
54    correct options is not chosen or one of the wrong fields is chosen, 5 points are
55    still awarded. Selecting the last neutral option does not affect the points.
56
57    +*a. this is the **first**
58    *b. this is the **second**
59    c. this is the **third**
60    d. this is the **fourth**
61    ?e. choosing this does not affect the granted points
62
63  .. freetext:: 30 string-ignorews-ignorequotes-requirecase
64    :length: 10
65
66    A textual input can be compared with the model solution as integer, float or string.
67    Here the correct answer is "test". Surrounding quotes are ignored in the solution
68    as well as whitespace everywhere (modifiers ignorequotes and ignorews).
69
70    test
71    !test § Follow the instruction.
72    regexp:Test|TEST § Use the lower case!
73
74  .. freetext:: 10 regexp
75
76    This question accepts either "red" or "blue" as the correct answer.
77    The model solution is a regular expression.
78
79    red|blue
80"#
81    .lines()
82    .map(|s| s.to_string())
83    .collect::<Vec<String>>();
84
85    let mut doctree = DocTree::new(PathBuf::from("test"));
86
87    let mut parser = Parser::new(src, doctree, 0, 0, State::Body, 0);
88
89    doctree = parser.parse().unwrap_tree();
90    doctree = doctree.walk_to_root();
91    doctree.print_tree();
92
93    if let TreeNodeType::AplusQuestionnaire { .. } = doctree
94        .shared_child(0).unwrap().shared_data() {
95    } else {
96        panic!()
97    }
98    if let TreeNodeType::Paragraph { .. } = doctree
99        .shared_child(0).unwrap()
100        .shared_child(0).unwrap().shared_data() {
101    } else {
102        panic!()
103    }
104    if let TreeNodeType::AplusPickOne { .. } = doctree
105        .shared_child(0).unwrap()
106        .shared_child(1).unwrap().shared_data()
107    {
108    } else {
109        panic!()
110    }
111    if let TreeNodeType::Paragraph { .. } = doctree
112        .shared_child(0).unwrap()
113        .shared_child(2).unwrap().shared_data() {
114    } else {
115        panic!()
116    }
117    if let TreeNodeType::AplusPickOne { .. } = doctree
118        .shared_child(0).unwrap()
119        .shared_child(3).unwrap().shared_data()
120    {
121    } else {
122        panic!()
123    }
124    if let TreeNodeType::AplusPickAny { .. } = doctree
125        .shared_child(0).unwrap()
126        .shared_child(4).unwrap().shared_data()
127    {
128    } else {
129        panic!()
130    }
131    if let TreeNodeType::AplusFreeText { .. } =
132        doctree
133        .shared_child(0).unwrap()
134        .shared_child(5).unwrap().shared_data()
135    {
136    } else {
137        panic!()
138    }
139    if let TreeNodeType::AplusFreeText { .. } =
140        doctree
141        .shared_child(0).unwrap()
142        .shared_child(6).unwrap().shared_data()
143    {
144    } else {
145        panic!()
146    }
147}
148
149#[test]
150fn aplus_questionnaire_02() {
151    let src =
152        r#"
153(K) Suostumus anonyymin kurssidatan tutkimuskäyttöön
154====================================================
155
156Kurssin aikana kurssin tietojärjestelmiin (Plussa, GitLab) syntyy
157opiskelijoiden tuottamaa dataa.
158Yliopiston yksi tehtävistä on tutkimus, ja siten tätä dataa halutaan
159hyödyntää opetuksen ja ohjelmistokehityksen tutkimustyössä.
160Tämä parantaa opetuksen laatua ja luo uutta tietoa.
161Kaikki data käsitellään tutkimuksissa anonyymisti, eikä yksittäistä
162opiskelijaa voi tunnistaa.
163
164Kurssi pyytää siten jokaiselta opiskelijalta suostumuksen datan käyttöön.
165
166.. questionnaire:: gdpr 10
167  :category: N
168  :submissions: 2
169  :points-to-pass: 0
170
171
172  .. pick-one:: 10
173
174    Annan luvan käyttää kurssidataa anonymisoituna tutkimustarkoituksiin
175
176    *a. Kyllä
177    *b. En
178
179"#
180    .lines()
181    .map(|s| s.to_string())
182    .collect::<Vec<String>>();
183
184    let mut doctree = DocTree::new(PathBuf::from("test"));
185
186    let mut parser = Parser::new(src, doctree, 0, 0, State::Body, 0);
187
188    doctree = parser.parse().unwrap_tree();
189    doctree = doctree.walk_to_root();
190    doctree.print_tree();
191
192    if let TreeNodeType::AplusQuestionnaire { .. } =
193        doctree
194        .shared_child(0).unwrap()
195        .shared_child(2).unwrap().shared_data()
196    {
197    } else {
198        panic!()
199    }
200    if let TreeNodeType::AplusPickOne { .. } = doctree
201        .shared_child(0).unwrap()
202        .shared_child(2).unwrap()
203        .shared_child(0).unwrap()
204        .shared_data()
205    {
206    } else {
207        panic!()
208    }
209    if let TreeNodeType::Paragraph { .. } = doctree
210        .shared_child(0).unwrap()
211        .shared_child(2).unwrap()
212        .shared_child(0).unwrap()
213        .shared_child(0).unwrap()
214        .shared_data()
215    {
216    } else {
217        panic!()
218    }
219    if let TreeNodeType::AplusPickChoices { .. } = doctree
220        .shared_child(0).unwrap()
221        .shared_child(2).unwrap()
222        .shared_child(0).unwrap()
223        .shared_child(1).unwrap()
224        .shared_data()
225    {
226    } else {
227        panic!()
228    }
229    if let TreeNodeType::AplusPickChoice { .. } = doctree
230        .shared_child(0).unwrap()
231        .shared_child(2).unwrap()
232        .shared_child(0).unwrap()
233        .shared_child(1).unwrap()
234        .shared_child(0).unwrap()
235        .shared_data()
236    {
237    } else {
238        panic!()
239    }
240    if let TreeNodeType::AplusPickChoice { .. } = doctree
241        .shared_child(0).unwrap()
242        .shared_child(2).unwrap()
243        .shared_child(0).unwrap()
244        .shared_child(1).unwrap()
245        .shared_child(1).unwrap()
246        .shared_data()
247    {
248    } else {
249        panic!()
250    }
251}