WeBWorK Problems

Problem with test_points

Problem with test_points

by Steven McKay -
Number of replies: 2
Following the example in the code snippet, I have tried to evaluate one of the answers in my problem at integers only. The relevant setup is below:

##############################################################
#
# Setup
#
#
Context("Numeric");
Context()->strings->add('divergent');
Context()->strings->add('-infinity');
Context()->variables->add(n=>'Real');
Context()->variables->set(n=>{limits=>[1,10]});
$a=random(2,9);

$ans1=Compute("1/$a");
$ans2=Compute("1/($a^2)");
$ans3=Compute("2/($a^3)");
$ans4=Compute("6/($a^4)");
$ans5=Compute("(n!)/($a^(n+1))");
$ans5->{test_points}=[[4],[5]];

##############################################################

You'll notice that $ans5 is tested only at 4 and 5 because of the factorial.
At the end of the file I have the usual
ANS($ans5->cmp());


However, I must be doing something stupid, because it doesn't work. When I try the code, it returns "Can't evaluate formula on test point (4)".

I thought it might be the factorial, but if I remove it, the same error is returned.

Can anyone see what I'm doing wrong here?

Thanks in advance for your help,
S.M.
In reply to Steven McKay

Re: Problem with test_points

by Davide Cervone -
The problem is that the Context also includes the variable x in addition to n, and so $ans5 is really a function of two variables (though one is not used). So the test points need to include values for both n and x. That is because student answers can include x (even if the correct answer doesn't) and there needs to be values to be plugged in for those x's. So you either need to make the test points be arrays with two entries (the variables are listed in alphabetical order), or remove the x. If you want to have only n in the context, then use
    Context()->variables->are(n=>'Real');
rather than
    Context()->variables->add(n=>'Real');
(i.e., "are" rather than "add").

Also, you do not need to add -infinity as a string, as the Infinity object already handles negative infinity. You will get better answer previews and better error messages if you leave it an Infinity rather than a String.

Hope that helps.

Davide

In reply to Davide Cervone

Re: Problem with test_points

by Steven McKay -
"The problem is that the Context also includes the variable x in addition to n, and so $ans5 is really a function of two variables (though one is not used). So the test points need to include values for both n and x. That is because student answers can include x (even if the correct answer doesn't) and there needs to be values to be plugged in for those x's. So you either need to make the test points be arrays with two entries (the variables are listed in alphabetical order), or remove the x."

Thank you. I thought it might have been this, so I tried removing the x, but it didn't work. However, that was probably due to a bug in my code. It works fine now :-)


"Also, you do not need to add -infinity as a string, as the Infinity object already handles negative infinity. You will get better answer previews and better error messages if you leave it an Infinity rather than a String. "

Thanks! I tried to look this up in the documentation and couldn't find it. I guess I should have just tried it :-)


I'm learning something new each week!

S.M.