ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
assFormulaQuestionTest.php
Go to the documentation of this file.
1 <?php
2 
20 
29 {
30  protected $backupGlobals = false;
32 
33  protected function setUp(): void
34  {
35  parent::setUp();
36  $lng = $this->getMockBuilder(\ilLanguage::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39  $lng->method('txt')
40  ->will($this->returnArgument(0));
41 
42  $this->setGlobalVariable('lng', $lng);
43  }
44 
55  /* assFormulaQuestionResult $result,
56  array $variables,
57  array $results,
58  string $userResult,
59  ?assFormulaQuestionUnit $userResultUnit,
60  bool $expectedResult*/
61  ): void {
62  $this->markTestSkipped('Data Provider needs to be revisited.');
63  $isCorrect = $result->isCorrect($variables, $results, $userResult, $userResultUnit);
64  $this->assertEquals($expectedResult, $isCorrect);
65  }
66 
67  public static function simpleRatedCalculationsData(): array
68  {
69  $points = 5;
70  $precision = 2;
71 
72  $meter = new assFormulaQuestionUnit();
73  $meter->initFormArray([
74  'unit_id' => 1,
75  'category' => 1,
76  'sequence' => 1,
77  'unit' => 'Meter',
78  'factor' => 1,
79  'baseunit_fi' => -1,
80  'baseunit_title' => '',
81  ]);
82 
83  $centimeter = new assFormulaQuestionUnit();
84  $centimeter->initFormArray([
85  'unit_id' => 2,
86  'category' => 1,
87  'sequence' => 2,
88  'unit' => 'Centimeter',
89  'factor' => 0.01,
90  'baseunit_fi' => 1,
91  'baseunit_title' => 'Meter',
92  ]);
93 
94  $newtonmetre = new assFormulaQuestionUnit();
95  $newtonmetre->initFormArray([
96  'unit_id' => 3,
97  'category' => 1,
98  'sequence' => 3,
99  'unit' => 'Newton Metre',
100  'factor' => 1,
101  'baseunit_fi' => -1,
102  'baseunit_title' => '',
103  ]);
104 
105  $newtoncentimeter = new assFormulaQuestionUnit();
106  $newtoncentimeter->initFormArray([
107  'unit_id' => 4,
108  'category' => 1,
109  'sequence' => 4,
110  'unit' => 'Newton Centimeter',
111  'factor' => 0.01,
112  'baseunit_fi' => 3,
113  'baseunit_title' => 'Newton Metre',
114  ]);
115 
116  $v1 = new assFormulaQuestionVariable('$v1', 1, 20, $newtonmetre, 1);
117  $v2 = new assFormulaQuestionVariable('$v2', 1, 10, $centimeter, 1);
118  $v1->setValue(19.6);
119  $v1->setIntprecision(1);
120  $v2->setValue(6.6);
121  $v2->setIntprecision(1);
122 
123  $v3 = clone $v1;
124  $v4 = clone $v2;
125  $v3->setUnit(null);
126  $v3->setVariable('$v3');
127  $v4->setUnit(null);
128  $v4->setVariable('$v4');
129 
130  $r1 = new assFormulaQuestionResult(
131  '$r1',
132  0,
133  0,
134  0,
135  $newtoncentimeter,
136  '$v1 * $v2',
137  $points,
138  $precision,
139  true,
140  33,
141  34,
142  33,
144  );
145  $r2 = new assFormulaQuestionResult(
146  '$r2',
147  0,
148  0,
149  0,
150  $newtonmetre,
151  '$v1 * $v2',
152  $points,
153  $precision,
154  true,
155  33,
156  34,
157  33,
159  );
160  $r3 = new assFormulaQuestionResult(
161  '$r3',
162  0,
163  0,
164  0,
165  null,
166  '$v1 * $v2',
167  $points,
168  $precision,
169  true,
170  33,
171  34,
172  33,
174  );
175  $r4 = new assFormulaQuestionResult(
176  '$r4',
177  0,
178  0,
179  0,
180  null,
181  '$v1 * $v2',
182  $points,
183  $precision,
184  true,
185  33,
186  34,
187  33,
189  );
190  $r5 = new assFormulaQuestionResult(
191  '$r5',
192  0,
193  0,
194  0,
195  null,
196  '$v1 * $v2',
197  $points,
198  $precision,
199  true,
200  33,
201  34,
202  33,
204  );
205  $r6 = new assFormulaQuestionResult(
206  '$r6',
207  0,
208  0,
209  0,
210  null,
211  '$v3 * $v4',
212  $points,
213  $precision,
214  true,
215  33,
216  34,
217  33,
219  );
220 
221  // RESULT_FRAC
222  $v5 = new assFormulaQuestionVariable('$v5', 1, 20, null, 1);
223  $v6 = new assFormulaQuestionVariable('$v6', 1, 10, null, 1);
224  $v5->setValue(1);
225  $v6->setValue(3);
226 
227  $v7 = new assFormulaQuestionVariable('$v7', 1, 20, null, 1);
228  $v8 = new assFormulaQuestionVariable('$v8', 1, 10, null, 1);
229  $v7->setValue(2);
230  $v8->setValue(4);
231 
232  $r7 = new assFormulaQuestionResult(
233  '$r7',
234  0,
235  0,
236  0,
237  null,
238  '$v5/$v6',
239  $points,
240  $precision,
241  true,
242  33,
243  34,
244  33,
246  );
247 
248  $r8 = new assFormulaQuestionResult(
249  '$r8',
250  0,
251  0,
252  0,
253  null,
254  '$v7/$v8',
255  $points,
256  $precision,
257  true,
258  33,
259  34,
260  33,
262  );
263 
264  // RESULT_CO_FRAC
265  $v9 = clone $v7;
266  $v9->setVariable('$v9');
267  $v10 = clone $v8;
268  $v10->setVariable('$v10');
269 
270  $v11 = clone $v7;
271  $v11->setVariable('$v11');
272  $v12 = clone $v8;
273  $v12->setVariable('$v12');
274 
275  $r9 = new assFormulaQuestionResult(
276  '$r9',
277  0,
278  0,
279  0,
280  null,
281  '$v9/$v10',
282  $points,
283  $precision,
284  true,
285  33,
286  34,
287  33,
289  );
290 
291  $r10 = new assFormulaQuestionResult(
292  '$r10',
293  0,
294  0,
295  0,
296  null,
297  '$v11/$v12',
298  $points,
299  $precision,
300  true,
301  33,
302  34,
303  33,
305  );
306 
307  // RESULT_NO_SELECTION
308  $v13 = new assFormulaQuestionVariable('$v13', 1, 20, null, 1);
309  $v14 = new assFormulaQuestionVariable('$v14', 1, 10, null, 1);
310  $v13->setValue(1);
311  $v14->setValue(3);
312  $r11 = new assFormulaQuestionResult(
313  '$r11',
314  0,
315  0,
316  0,
317  null,
318  '$v13/$v14',
319  $points,
320  $precision,
321  true,
322  33,
323  34,
324  33,
326  );
327 
328  $v15 = new assFormulaQuestionVariable('$v15', 200, 800, null, 0);
329  $v16 = new assFormulaQuestionVariable('$v16', 50, 250, null, 0);
330  $v17 = new assFormulaQuestionVariable('$v17', 3, 18, null, 0);
331  $v15->setIntprecision(25);
332  $v16->setIntprecision(5);
333  $v17->setIntprecision(1);
334  $v15->setValue(225);
335  $v16->setValue(85);
336  $v17->setValue(10);
337  $r12 = new assFormulaQuestionResult(
338  '$r12',
339  0,
340  0,
341  0,
342  null,
343  '1/(2*pi)*sqrt($v16*1000/$v15)+$v17-$v17',
344  $points,
345  1,
346  true,
347  33,
348  34,
349  33,
351  );
352  $r13 = new assFormulaQuestionResult(
353  '$r12',
354  0,
355  0,
356  0,
357  null,
358  '1/(2*pi)*sqrt($v16*1000/$v15)+$v17-$v17',
359  $points,
360  2,
361  true,
362  33,
363  34,
364  33,
366  );
367  $r14 = new assFormulaQuestionResult(
368  '$r11',
369  0,
370  0,
371  0,
372  null,
373  '$v7/$v14',
374  $points,
375  $precision,
376  true,
377  33,
378  34,
379  33,
381  );
382 
383  $variables = [
384  $v1->getVariable() => $v1,
385  $v2->getVariable() => $v2,
386  $v3->getVariable() => $v3,
387  $v4->getVariable() => $v4,
388  $v5->getVariable() => $v5,
389  $v6->getVariable() => $v6,
390  $v7->getVariable() => $v7,
391  $v8->getVariable() => $v8,
392  $v9->getVariable() => $v9,
393  $v10->getVariable() => $v10,
394  $v11->getVariable() => $v11,
395  $v12->getVariable() => $v12,
396  $v13->getVariable() => $v13,
397  $v14->getVariable() => $v14,
398  $v15->getVariable() => $v15,
399  $v16->getVariable() => $v16,
400  $v17->getVariable() => $v17,
401  ];
402 
403  $results = [
404  $r1->getResult() => $r1,
405  $r2->getResult() => $r2,
406  $r3->getResult() => $r3,
407  $r4->getResult() => $r4,
408  $r5->getResult() => $r5,
409  $r6->getResult() => $r6,
410  $r7->getResult() => $r7,
411  $r8->getResult() => $r8,
412  $r9->getResult() => $r9,
413  $r10->getResult() => $r10,
414  $r11->getResult() => $r11,
415  $r12->getResult() => $r12,
416  $r13->getResult() => $r13,
417  $r14->getResult() => $r14,
418  ];
419 
420  return [
421  //result, all variables, all results, user solution, unit chosen by user for solution
422  [$r1, $variables, $results, '129.36', $newtoncentimeter, true],
423  [$r2, $variables, $results, '1.29', $newtonmetre, true],
424  [$r3, $variables, $results, '1.29', $newtonmetre, true],
425  [$r4, $variables, $results, '129.36', $newtoncentimeter, true],
426  [$r5, $variables, $results, '1.29', null, true],
427  [$r6, $variables, $results, '129.36', null, true],
428  // RESULT_FRAC
429  [$r7, $variables, $results, '1/3', null, true],
430  [$r8, $variables, $results, '4/8', null, true],
431  // RESULT_CO_FRAC
432  [$r9, $variables, $results, '1/2', null, true],
433  [$r10, $variables, $results, '4/8', null, false],
434  // RESULT_NO_SELECTION
435  [$r11, $variables, $results, '1/3', null, true],
436  [$r14, $variables, $results, '0.67', null, true],
437  [$r14, $variables, $results, '0.66666', null, true],
438  [$r14, $variables, $results, '0.7', null, false],
439  [$r14, $variables, $results, '2/3', null, true],
440  // Test for #22381
441  [$r12, $variables, $results, '3.1', null, true],
442  [$r13, $variables, $results, '3.09', null, true],
443  [$r13, $variables, $results, '3.1', null, false],
444  ];
445  }
446 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class assBaseTestCase.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$results
testSimpleRatedFormulaQuestionCalculations()
simpleRatedCalculationsData
global $lng
Definition: privfeed.php:31