Answer test Completed Square with fractions

Answer test Completed Square with fractions

by Stephan Bach -
Number of replies: 2
Hello,

I wanted to use the answer test CompletedSquare with the coefficient of the quadratic term being a fraction, e.g. \(\frac{3}{2}x^2 + 6x +12\). But I don't manage to answer anything, which is accepted as correct (see screenshots below). Even though the test works without problems for integer coefficients.

Is the test not supporting a fraction as the coefficient of the quadratic term?

Stephan

Average of ratings: -
In reply to Stephan Bach

Re: Answer test Completed Square with fractions

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Sorry Stephan,

I didn't include this case.  The code for the test itself is here:

https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/stackmaxima.mac#L2537

And the testcases (unit tests) are here:

https://github.com/maths/moodle-qtype_stack/blob/master/tests/fixtures/answertestfixtures.class.php#L809

Could you, as a minimum, suggest more test cases of what you do and do not want to pass here?  e.g. I think some people might not accept (3*(x+1)^2+6)/2, i.e. the fraction outside the whole thing. I may be wrong here!  If you can specify the test cases, with a rationale, then it will be much easier to code to this.

Chris


In reply to Christopher Sangwin

Re: Answer test Completed Square with fractions

by Stephan Bach -
Hello Chris,
thanks for your quick reply. It will helps to understand the whole thing and will help me to create my own answer test if necessary.

The main cases I would like to cover are

array('CompSquare', 'x', '3/2*(x-1)^2+1', '3/2*(x-1)^2+1', 1, 'ATCompSquare_true.', ''),
array('CompSquare', 'x', '3*(x-1)^2/2+1', '3/2*(x-1)^2+1', 1, 'ATCompSquare_true.', ''),
array('CompSquare', 'x', '-3/2*(x-1)^2+1', '-3/2*(x-1)^2+1', 1, 'ATCompSquare_true.', ''),
array('CompSquare', 'x', '-3*(x-1)^2/2+1', '-3/2*(x-1)^2+1', 1, 'ATCompSquare_true.', ''),
array('CompSquare', 'x', '1-3*(x-1)^2/2', '-3/2*(x-1)^2+1', 1, 'ATCompSquare_true.', '')

(Is this what you are thinking of?)

I don't want to accept the version with the fraction factored out.
(The reason why I tried it out, is that as an example comp_square(2*x^2+4*x+4,x) evaluates to 2*((x+1)^2+1). But I now realized that the anwer test CompletedSquare does not accept this expression for 2*(x+1)^2+2 anyways.)

Stephan