ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
17  protected function setUp() : void
18  {
19  parent::setUp();
20 
21  $lng = $this->getMockBuilder(\ilLanguage::class)
22  ->disableOriginalConstructor()
23  ->getMock();
24  $lng->method('txt')
25  ->will($this->returnArgument(0));
26 
27  $this->setGlobalVariable('lng', $lng);
28  }
29 
30 
42  array $variables,
43  array $results,
44  $userResult,
45  $userResultUnit,
46  $expectedResult
47  ) {
48  $isCorrect = $result->isCorrect($variables, $results, $userResult, $userResultUnit);
49  $this->assertEquals($expectedResult, $isCorrect);
50  }
51 
55  public function simpleRatedCalculationsData()
56  {
57  $points = 5;
58  $precision = 2;
59 
60  $meter = new assFormulaQuestionUnit();
61  $meter->initFormArray([
62  'unit_id' => 1,
63  'category' => 1,
64  'sequence' => 1,
65  'unit' => 'Meter',
66  'factor' => 1,
67  'baseunit_fi' => -1,
68  'baseunit_title' => ''
69  ]);
70 
71  $centimeter = new assFormulaQuestionUnit();
72  $centimeter->initFormArray([
73  'unit_id' => 2,
74  'category' => 1,
75  'sequence' => 2,
76  'unit' => 'Centimeter',
77  'factor' => 0.01,
78  'baseunit_fi' => 1,
79  'baseunit_title' => 'Meter'
80  ]);
81 
82  $newtonmetre = new assFormulaQuestionUnit();
83  $newtonmetre->initFormArray([
84  'unit_id' => 3,
85  'category' => 1,
86  'sequence' => 3,
87  'unit' => 'Newton Metre',
88  'factor' => 1,
89  'baseunit_fi' => -1,
90  'baseunit_title' => ''
91  ]);
92 
93  $newtoncentimeter = new assFormulaQuestionUnit();
94  $newtoncentimeter->initFormArray([
95  'unit_id' => 4,
96  'category' => 1,
97  'sequence' => 4,
98  'unit' => 'Newton Centimeter',
99  'factor' => 0.01,
100  'baseunit_fi' => 3,
101  'baseunit_title' => 'Newton Metre'
102  ]);
103 
104  $v1 = new assFormulaQuestionVariable('$v1', 1, 20, $newtonmetre, 1);
105  $v2 = new assFormulaQuestionVariable('$v2', 1, 10, $centimeter, 1);
106  $v1->setValue(19.6);
107  $v1->setIntprecision(1);
108  $v2->setValue(6.6);
109  $v2->setIntprecision(1);
110 
111  $v3 = clone $v1;
112  $v4 = clone $v2;
113  $v3->setUnit(null);
114  $v3->setVariable('$v3');
115  $v4->setUnit(null);
116  $v4->setVariable('$v4');
117 
118  $r1 = new assFormulaQuestionResult(
119  '$r1',
120  0,
121  0,
122  0,
123  $newtoncentimeter,
124  '$v1 * $v2',
125  $points,
126  $precision,
127  true,
128  33,
129  34,
130  33,
132  );
133  $r2 = new assFormulaQuestionResult(
134  '$r2',
135  0,
136  0,
137  0,
138  $newtonmetre,
139  '$v1 * $v2',
140  $points,
141  $precision,
142  true,
143  33,
144  34,
145  33,
147  );
148  $r3 = new assFormulaQuestionResult(
149  '$r3',
150  0,
151  0,
152  0,
153  null,
154  '$v1 * $v2',
155  $points,
156  $precision,
157  true,
158  33,
159  34,
160  33,
162  );
163  $r4 = new assFormulaQuestionResult(
164  '$r4',
165  0,
166  0,
167  0,
168  null,
169  '$v1 * $v2',
170  $points,
171  $precision,
172  true,
173  33,
174  34,
175  33,
177  );
178  $r5 = new assFormulaQuestionResult(
179  '$r5',
180  0,
181  0,
182  0,
183  null,
184  '$v1 * $v2',
185  $points,
186  $precision,
187  true,
188  33,
189  34,
190  33,
192  );
193  $r6 = new assFormulaQuestionResult(
194  '$r6',
195  0,
196  0,
197  0,
198  null,
199  '$v3 * $v4',
200  $points,
201  $precision,
202  true,
203  33,
204  34,
205  33,
207  );
208 
209  // RESULT_FRAC
210  $v5 = new assFormulaQuestionVariable('$v5', 1, 20, null, 1);
211  $v6 = new assFormulaQuestionVariable('$v6', 1, 10, null, 1);
212  $v5->setValue(1);
213  $v6->setValue(3);
214 
215  $v7 = new assFormulaQuestionVariable('$v7', 1, 20, null, 1);
216  $v8 = new assFormulaQuestionVariable('$v8', 1, 10, null, 1);
217  $v7->setValue(2);
218  $v8->setValue(4);
219 
220  $r7 = new assFormulaQuestionResult(
221  '$r7',
222  0,
223  0,
224  0,
225  null,
226  '$v5/$v6',
227  $points,
228  $precision,
229  true,
230  33,
231  34,
232  33,
234  );
235 
236  $r8 = new assFormulaQuestionResult(
237  '$r8',
238  0,
239  0,
240  0,
241  null,
242  '$v7/$v8',
243  $points,
244  $precision,
245  true,
246  33,
247  34,
248  33,
250  );
251 
252  // RESULT_CO_FRAC
253  $v9 = clone $v7;
254  $v9->setVariable('$v9');
255  $v10 = clone $v8;
256  $v10->setVariable('$v10');
257 
258  $v11 = clone $v7;
259  $v11->setVariable('$v11');
260  $v12 = clone $v8;
261  $v12->setVariable('$v12');
262 
263  $r9 = new assFormulaQuestionResult(
264  '$r9',
265  0,
266  0,
267  0,
268  null,
269  '$v9/$v10',
270  $points,
271  $precision,
272  true,
273  33,
274  34,
275  33,
277  );
278 
279  $r10 = new assFormulaQuestionResult(
280  '$r10',
281  0,
282  0,
283  0,
284  null,
285  '$v11/$v12',
286  $points,
287  $precision,
288  true,
289  33,
290  34,
291  33,
293  );
294 
295  // RESULT_NO_SELECTION
296  $v13 = new assFormulaQuestionVariable('$v13', 1, 20, null, 1);
297  $v14 = new assFormulaQuestionVariable('$v14', 1, 10, null, 1);
298  $v13->setValue(1);
299  $v14->setValue(3);
300  $r11 = new assFormulaQuestionResult(
301  '$r11',
302  0,
303  0,
304  0,
305  null,
306  '$v13/$v14',
307  $points,
308  $precision,
309  true,
310  33,
311  34,
312  33,
314  );
315 
316  $v15 = new assFormulaQuestionVariable('$v15', 200, 800, null, 0);
317  $v16 = new assFormulaQuestionVariable('$v16', 50, 250, null, 0);
318  $v17 = new assFormulaQuestionVariable('$v17', 3, 18, null, 0);
319  $v15->setIntprecision(25);
320  $v16->setIntprecision(5);
321  $v17->setIntprecision(1);
322  $v15->setValue(225);
323  $v16->setValue(85);
324  $v17->setValue(10);
325  $r12 = new assFormulaQuestionResult(
326  '$r12',
327  0,
328  0,
329  0,
330  null,
331  '1/(2*pi)*sqrt($v16*1000/$v15)+$v17-$v17',
332  $points,
333  1,
334  true,
335  33,
336  34,
337  33,
339  );
340 
341  $variables = [
342  $v1->getVariable() => $v1,
343  $v2->getVariable() => $v2,
344  $v3->getVariable() => $v3,
345  $v4->getVariable() => $v4,
346  $v5->getVariable() => $v5,
347  $v6->getVariable() => $v6,
348  $v7->getVariable() => $v7,
349  $v8->getVariable() => $v8,
350  $v9->getVariable() => $v9,
351  $v10->getVariable() => $v10,
352  $v11->getVariable() => $v11,
353  $v12->getVariable() => $v12,
354  $v13->getVariable() => $v13,
355  $v14->getVariable() => $v14,
356  $v15->getVariable() => $v15,
357  $v16->getVariable() => $v16,
358  $v17->getVariable() => $v17,
359  ];
360 
361  $results = [
362  $r1->getResult() => $r1,
363  $r2->getResult() => $r2,
364  $r3->getResult() => $r3,
365  $r4->getResult() => $r4,
366  $r5->getResult() => $r5,
367  $r6->getResult() => $r6,
368  $r7->getResult() => $r7,
369  $r8->getResult() => $r8,
370  $r9->getResult() => $r9,
371  $r10->getResult() => $r10,
372  $r11->getResult() => $r11,
373  $r12->getResult() => $r12,
374  ];
375 
376  return [
377  //result, all variables, all results, user solution, unit chosen by user for solution
378  [$r1, $variables, $results, '129.36', $newtoncentimeter, true],
379  [$r2, $variables, $results, '1.29', $newtonmetre, true],
380  [$r3, $variables, $results, '1.29', $newtonmetre, true],
381  [$r4, $variables, $results, '129.36', $newtoncentimeter, true],
382  [$r5, $variables, $results, '1.29', null, true],
383  [$r6, $variables, $results, '129.36', null, true],
384  // RESULT_FRAC
385  [$r7, $variables, $results, '1/3', null, true],
386  [$r8, $variables, $results, '4/8', null, true],
387  // RESULT_CO_FRAC
388  [$r9, $variables, $results, '1/2', null, true],
389  [$r10, $variables, $results, '4/8', null, false],
390  // RESULT_NO_SELECTION
391  [$r11, $variables, $results, '1/3', null, true],
392  // Test for #22381
393  [$r12, $variables, $results, '3.1', null, true],
394  ];
395  }
396 }
$result
Class assBaseTestCase.
setGlobalVariable($name, $value)
$lng
isCorrect($variables, $results, $value, $unit=null)
$results
testSimpleRatedFormulaQuestionCalculations(assFormulaQuestionResult $result, array $variables, array $results, $userResult, $userResultUnit, $expectedResult)
simpleRatedCalculationsData