ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
assFormulaQuestionTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'libs/composer/vendor/autoload.php';
5 
14 {
15  protected $backupGlobals = false;
16 
28  array $variables,
30  $userResult,
31  $userResultUnit,
32  $expectedResult
33  ) {
34  $isCorrect = $result->isCorrect($variables, $results, $userResult, $userResultUnit);
35  $this->assertEquals($expectedResult, $isCorrect);
36  }
37 
41  public function simpleRatedCalculationsData()
42  {
43  $points = 5;
44  $precision = 2;
45 
46  $meter = new assFormulaQuestionUnit();
47  $meter->initFormArray([
48  'unit_id' => 1,
49  'category' => 1,
50  'sequence' => 1,
51  'unit' => 'Meter',
52  'factor' => 1,
53  'baseunit_fi' => -1,
54  'baseunit_title' => ''
55  ]);
56 
57  $centimeter = new assFormulaQuestionUnit();
58  $centimeter->initFormArray([
59  'unit_id' => 2,
60  'category' => 1,
61  'sequence' => 2,
62  'unit' => 'Centimeter',
63  'factor' => 0.01,
64  'baseunit_fi' => 1,
65  'baseunit_title' => 'Meter'
66  ]);
67 
68  $newtonmetre = new assFormulaQuestionUnit();
69  $newtonmetre->initFormArray([
70  'unit_id' => 3,
71  'category' => 1,
72  'sequence' => 3,
73  'unit' => 'Newton Metre',
74  'factor' => 1,
75  'baseunit_fi' => -1,
76  'baseunit_title' => ''
77  ]);
78 
79  $newtoncentimeter = new assFormulaQuestionUnit();
80  $newtoncentimeter->initFormArray([
81  'unit_id' => 4,
82  'category' => 1,
83  'sequence' => 4,
84  'unit' => 'Newton Centimeter',
85  'factor' => 0.01,
86  'baseunit_fi' => 3,
87  'baseunit_title' => 'Newton Metre'
88  ]);
89 
90  $v1 = new assFormulaQuestionVariable('$v1', 1, 20, $newtonmetre, 1);
91  $v2 = new assFormulaQuestionVariable('$v2', 1, 10, $centimeter, 1);
92  $v1->setValue(19.6);
93  $v1->setIntprecision(1);
94  $v2->setValue(6.6);
95  $v2->setIntprecision(1);
96 
97  $v3 = clone $v1;
98  $v4 = clone $v2;
99  $v3->setUnit(null);
100  $v3->setVariable('$v3');
101  $v4->setUnit(null);
102  $v4->setVariable('$v4');
103 
104  $r1 = new assFormulaQuestionResult(
105  '$r1',
106  0,
107  0,
108  0,
109  $newtoncentimeter,
110  '$v1 * $v2',
111  $points,
112  $precision,
113  true,
114  33,
115  34,
116  33,
118  );
119  $r2 = new assFormulaQuestionResult(
120  '$r2',
121  0,
122  0,
123  0,
124  $newtonmetre,
125  '$v1 * $v2',
126  $points,
127  $precision,
128  true,
129  33,
130  34,
131  33,
133  );
134  $r3 = new assFormulaQuestionResult(
135  '$r3',
136  0,
137  0,
138  0,
139  null,
140  '$v1 * $v2',
141  $points,
142  $precision,
143  true,
144  33,
145  34,
146  33,
148  );
149  $r4 = new assFormulaQuestionResult(
150  '$r4',
151  0,
152  0,
153  0,
154  null,
155  '$v1 * $v2',
156  $points,
157  $precision,
158  true,
159  33,
160  34,
161  33,
163  );
164  $r5 = new assFormulaQuestionResult(
165  '$r5',
166  0,
167  0,
168  0,
169  null,
170  '$v1 * $v2',
171  $points,
172  $precision,
173  true,
174  33,
175  34,
176  33,
178  );
179  $r6 = new assFormulaQuestionResult(
180  '$r6',
181  0,
182  0,
183  0,
184  null,
185  '$v3 * $v4',
186  $points,
187  $precision,
188  true,
189  33,
190  34,
191  33,
193  );
194 
195  // RESULT_FRAC
196  $v5 = new assFormulaQuestionVariable('$v5', 1, 20, null, 1);
197  $v6 = new assFormulaQuestionVariable('$v6', 1, 10, null, 1);
198  $v5->setValue(1);
199  $v6->setValue(3);
200 
201  $v7 = new assFormulaQuestionVariable('$v7', 1, 20, null, 1);
202  $v8 = new assFormulaQuestionVariable('$v8', 1, 10, null, 1);
203  $v7->setValue(2);
204  $v8->setValue(4);
205 
206  $r7 = new assFormulaQuestionResult(
207  '$r7',
208  0,
209  0,
210  0,
211  null,
212  '$v5/$v6',
213  $points,
214  $precision,
215  true,
216  33,
217  34,
218  33,
220  );
221 
222  $r8 = new assFormulaQuestionResult(
223  '$r8',
224  0,
225  0,
226  0,
227  null,
228  '$v7/$v8',
229  $points,
230  $precision,
231  true,
232  33,
233  34,
234  33,
236  );
237 
238  // RESULT_CO_FRAC
239  $v9 = clone $v7;
240  $v9->setVariable('$v9');
241  $v10 = clone $v8;
242  $v10->setVariable('$v10');
243 
244  $v11 = clone $v7;
245  $v11->setVariable('$v11');
246  $v12 = clone $v8;
247  $v12->setVariable('$v12');
248 
249  $r9 = new assFormulaQuestionResult(
250  '$r9',
251  0,
252  0,
253  0,
254  null,
255  '$v9/$v10',
256  $points,
257  $precision,
258  true,
259  33,
260  34,
261  33,
263  );
264 
265  $r10 = new assFormulaQuestionResult(
266  '$r10',
267  0,
268  0,
269  0,
270  null,
271  '$v11/$v12',
272  $points,
273  $precision,
274  true,
275  33,
276  34,
277  33,
279  );
280 
281  // RESULT_NO_SELECTION
282  $v13 = new assFormulaQuestionVariable('$v13', 1, 20, null, 1);
283  $v14 = new assFormulaQuestionVariable('$v14', 1, 10, null, 1);
284  $v13->setValue(1);
285  $v14->setValue(3);
286  $r11 = new assFormulaQuestionResult(
287  '$r11',
288  0,
289  0,
290  0,
291  null,
292  '$v13/$v14',
293  $points,
294  $precision,
295  true,
296  33,
297  34,
298  33,
300  );
301 
302  $v15 = new assFormulaQuestionVariable('$v15', 200, 800, null, 0);
303  $v16 = new assFormulaQuestionVariable('$v16', 50, 250, null, 0);
304  $v17 = new assFormulaQuestionVariable('$v17', 3, 18, null, 0);
305  $v15->setIntprecision(25);
306  $v16->setIntprecision(5);
307  $v17->setIntprecision(1);
308  $v15->setValue(225);
309  $v16->setValue(85);
310  $v17->setValue(10);
311  $r12 = new assFormulaQuestionResult(
312  '$r12',
313  0,
314  0,
315  0,
316  null,
317  '1/(2*pi)*sqrt($v16*1000/$v15)+$v17-$v17',
318  $points,
319  1,
320  true,
321  33,
322  34,
323  33,
325  );
326 
327  $variables = [
328  $v1->getVariable() => $v1,
329  $v2->getVariable() => $v2,
330  $v3->getVariable() => $v3,
331  $v4->getVariable() => $v4,
332  $v5->getVariable() => $v5,
333  $v6->getVariable() => $v6,
334  $v7->getVariable() => $v7,
335  $v8->getVariable() => $v8,
336  $v9->getVariable() => $v9,
337  $v10->getVariable() => $v10,
338  $v11->getVariable() => $v11,
339  $v12->getVariable() => $v12,
340  $v13->getVariable() => $v13,
341  $v14->getVariable() => $v14,
342  $v15->getVariable() => $v15,
343  $v16->getVariable() => $v16,
344  $v17->getVariable() => $v17,
345  ];
346 
347  $results = [
348  $r1->getResult() => $r1,
349  $r2->getResult() => $r2,
350  $r3->getResult() => $r3,
351  $r4->getResult() => $r4,
352  $r5->getResult() => $r5,
353  $r6->getResult() => $r6,
354  $r7->getResult() => $r7,
355  $r8->getResult() => $r8,
356  $r9->getResult() => $r9,
357  $r10->getResult() => $r10,
358  $r11->getResult() => $r11,
359  $r12->getResult() => $r12,
360  ];
361 
362  return [
363  //result, all variables, all results, user solution, unit chosen by user for solution
364  [$r1, $variables, $results, '129.36', $newtoncentimeter, true],
365  [$r2, $variables, $results, '1.29', $newtonmetre, true],
366  [$r3, $variables, $results, '1.29', $newtonmetre, true],
367  [$r4, $variables, $results, '129.36', $newtoncentimeter, true],
368  [$r5, $variables, $results, '1.29', null, true],
369  [$r6, $variables, $results, '129.36', null, true],
370  // RESULT_FRAC
371  [$r7, $variables, $results, '1/3', null, true],
372  [$r8, $variables, $results, '4/8', null, true],
373  // RESULT_CO_FRAC
374  [$r9, $variables, $results, '1/2', null, true],
375  [$r10, $variables, $results, '4/8', null, false],
376  // RESULT_NO_SELECTION
377  [$r11, $variables, $results, '1/3', null, true],
378  // Test for #22381
379  [$r12, $variables, $results, '3.0', null, true],
380  ];
381  }
382 }
$result
isCorrect($variables, $results, $value, $unit=null)
Create styles array
The data for the language used.
testSimpleRatedFormulaQuestionCalculations(assFormulaQuestionResult $result, array $variables, array $results, $userResult, $userResultUnit, $expectedResult)
simpleRatedCalculationsData
$results
Definition: svg-scanner.php:47