From: Chris S. <san...@us...> - 2005-07-01 15:22:49
|
Update of /cvsroot/stack/stack-1-0/scripts/install In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32203/scripts/install Added Files: testsuite.php Log Message: Problems with trig expansions in the Int Answer test. --- NEW FILE: testsuite.php --- <?php /** * This file runs a testsuite against a particular answer test. * */ session_start(); require_once('../../../stackstd.php'); $docs = $stack_root.'/doc/en_doc.php'; include($docs); /** * Construct a test suite array object. */ function stack_testsuite_construct($at,$sa,$ta,$mark,$atops='',$notes=''){ $ts = array('AnswerTest'=>$at, 'SAns'=>$sa, 'TAns'=>$ta, 'AnsTestOpt'=>$atops, 'ExpectedScore'=> $mark, 'Notes' =>$notes,); return $ts; } // AlgEquiv Answer tests. $testsuite[] = stack_testsuite_construct('AlgEquiv','1/0','x^2-2*x+1',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','4^(-1/2)','1/2',1,'','Numbers'); $testsuite[] = stack_testsuite_construct('AlgEquiv','4^(1/2)','sqrt(4)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','0.5','1/2',0,'','Mix of floats and rational numbers'); $testsuite[] = stack_testsuite_construct('AlgEquiv','0.333333333333333','1/3',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','SQRT(-1)','%I',1,'','Powers and roots'); $testsuite[] = stack_testsuite_construct('AlgEquiv','x^(1/2)','sqrt(x)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','x','sqrt(x^2)',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','abs(x)','sqrt(x^2)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','x-1','(x^2-1)/(x+1)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','(x-1)^2','x^2-2*x+1',1,'','Polynomials and rational function'); $testsuite[] = stack_testsuite_construct('AlgEquiv','(x-1)*(x^2+x+1)','x^3-1',1,'x',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','(x-1)^(-2)','1/(x^2-2*x+1)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','1/n-1/(n+1)','1/(n*(n+1))',1,'x',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','cos(x)','cos(-x)',1,'','Trig functions'); $testsuite[] = stack_testsuite_construct('AlgEquiv','cos(x)^2+sin(x)^2','1',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','2*cos(x)^2-1','cos(2*x)',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','EXP(%i*%pi)','-1',1,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','LOG(a^2*b)','2*LOG(a)+LOG(b)',1,'','Logarithms'); $testsuite[] = stack_testsuite_construct('AlgEquiv','x','[1,2,3]',0,'','Lists'); $testsuite[] = stack_testsuite_construct('AlgEquiv','[1,2]','[1,2,3]',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','[1,2,4]','[1,2,3]',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','x','{1,2,3}',0,'','Sets'); $testsuite[] = stack_testsuite_construct('AlgEquiv','{1,2}','{1,2,3}',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','[1,2,4]','[1,2,3]',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','matrix([1,2],[2,3])','matrix([1,2],[2,3])',1,'','Matrices'); $testsuite[] = stack_testsuite_construct('AlgEquiv','matrix([1,2],[2,3])','matrix([1,2,3],[2,3,3])',0,'',''); $testsuite[] = stack_testsuite_construct('AlgEquiv','matrix([1,2],[2,3])','matrix([1,2],[2,5])',0,'',''); // Integration test $testsuite[] = stack_testsuite_construct('Int','1/0','x^2-2*x+1',0,'',''); $testsuite[] = stack_testsuite_construct('Int','1/0','x^2-2*x+1',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','x^3/3','x^3/3',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','x^3/3+1','x^3/3',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','x^3/3+c','x^3/3',1,'x',''); $testsuite[] = stack_testsuite_construct('Int','2*x','x^3/3',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','sin(2*x)','x^3/3',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','(t-1)^5/5+c','(t-1)^5/5',1,'t',''); $testsuite[] = stack_testsuite_construct('Int','2*sin(x)*cos(x)','sin(2*x)+c',0,'x',''); $testsuite[] = stack_testsuite_construct('Int','-2*COS(3*x)/3-3*COS(2*x)/2','-2*COS(3*x)/3-3*COS(2*x)/2+c',0,'x',''); //$testsuite[] = stack_testsuite_construct('Int','-2*COS(3*x)/3-3*COS(2*x)/2+1','-2*COS(3*x)/3-3*COS(2*x)/2+c',0,'x',''); //$testsuite[] = stack_testsuite_construct('Int','-2*COS(3*x)/3-3*COS(2*x)/2+c','-2*COS(3*x)/3-3*COS(2*x)/2+c',1,'x',''); // Differentiation test $testsuite[] = stack_testsuite_construct('Diff','1/0','3*x^2',0,'',''); $testsuite[] = stack_testsuite_construct('Diff','1/0','3*x^2',0,'x',''); $testsuite[] = stack_testsuite_construct('Diff','3*x^2','3*x^2',1,'x',''); $testsuite[] = stack_testsuite_construct('Diff','x^4/4','3*x^2',0,'x',''); $testsuite[] = stack_testsuite_construct('Diff','x^4/4+1','3*x^2',0,'x',''); $testsuite[] = stack_testsuite_construct('Diff','x^4/4+c','3*x^2',0,'x',''); // Factored form $testsuite[] = stack_testsuite_construct('FacForm','1/0','x^2-2*x+1',0,'',''); $testsuite[] = stack_testsuite_construct('FacForm','1/0','x^2-2*x+1',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','2*(x-1)','2*x-2',1,'x','Linear integer factors'); $testsuite[] = stack_testsuite_construct('FacForm','2*x-2','2*x-2',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','2*(x+1)','2*x-2',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','2*x+2','2*x-2',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','2*(x+0.5)','2*x+1',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','t*(2*x+1)','t*(2*x+1)',1,'x','Linear factors'); $testsuite[] = stack_testsuite_construct('FacForm','t*x+t','t*(x+1)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','2*x*(x-3)','2*x^2-6*x',1,'x','Quadratic, with no const'); $testsuite[] = stack_testsuite_construct('FacForm','2*(x^2-3*x)','2*x*(x-3)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','x*(2*x-6)','2*x*(x-3)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(x+2)*(x+3)','(x+2)*(x+3)',1,'x','Quadratic'); $testsuite[] = stack_testsuite_construct('FacForm','(x+2)*(2*x+6)','2*(x+2)*(x+3)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(z*x+z)*(2*x+6)','2*z*(x+1)*(x+3)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(x+t)*(x-t)','x^2-t^2',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','t^2-1','(t-1)*(t+1)',0,'t',''); $testsuite[] = stack_testsuite_construct('FacForm','(2-x)*(3-x)','(x-2)*(x-3)',1,'x','These are delicate cases!'); $testsuite[] = stack_testsuite_construct('FacForm','(1-x)^2','(x-1)^2',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','-(1-x)^2','-(x-1)^2',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','4*(1-x/2)^2','(x-2)^2',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(x-1)*(x^2+x+1)','x^3-1',1,'x','Cubics'); $testsuite[] = stack_testsuite_construct('FacForm','(1-x)*(2-x)*(3-x)','-x^3+6*x^2-11*x+6',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(x^2-3*x+2)*(3-x)','-x^3+6*x^2-11*x+6',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(sin(x)+1)*(sin(x)-1)','sin(x)^2-1',0,'sin(x)','Not polynomials in a variable'); $testsuite[] = stack_testsuite_construct('FacForm','7','7',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','24*(x-1/4)','24*x-6',1,'x','Factors over other fields'); $testsuite[] = stack_testsuite_construct('FacForm','(x-sqrt(2))*(x+sqrt(2))','x^2-2',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(%i*x-2*%i)','%i*(x-2)',0,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','%i*(x-2)','(%i*x-2*%i)',1,'x',''); $testsuite[] = stack_testsuite_construct('FacForm','(x-%i)*(x+%i)','x^2+1',1,'x',''); //$testsuite[] = stack_testsuite_construct('FacForm','(x-1)*(x+(1+sqrt(3)*%i)/2)*(x+(1-sqrt(3)*%i)/2)','x^3-1',1,'x',''); $testsuite[] = stack_testsuite_construct('SA_factored','1/0','0',0,'x',''); $testsuite[] = stack_testsuite_construct('SA_factored','2*(x-2)','0',1,'x','Linear integer factors'); $testsuite[] = stack_testsuite_construct('SA_factored','2*x-2','0',0,'x',''); $testsuite[] = stack_testsuite_construct('SA_factored','2*(x+0.5)','0',0,'x',''); $testsuite[] = stack_testsuite_construct('SA_factored','(2-x)*(3-x)','0',1,'x','These are delicate cases!'); $testsuite[] = stack_testsuite_construct('SA_factored','(1-x)^2','(x-1)^2',1,'x',''); $testsuite[] = stack_testsuite_construct('SA_expanded','1/0','0',1,'',''); $testsuite[] = stack_testsuite_construct('SA_expanded','x^2-1','0',1,'',''); $testsuite[] = stack_testsuite_construct('SA_expanded','(x-1)*(x+1)','0',0,'',''); //$AnswerTestlist = array('AlgEquiv','Diff','Int','FacForm','SA_factored','SA_expanded'); $AnswerTestlist = array('Int'); //$AnswerTestlist = array('FacForm','SA_factored'); // Now perform the tests, and display the results. $disp = 'LaTeX'; $errors = array(); echo "<h1>Test suite for the AnswerTests</h1>\n"; foreach( $AnswerTestlist as $atest) { echo "<h2>$atest</h2>\n"; echo $stackAnswerTest[$atest]['doc']; $all_passed = TRUE; echo "<table border='1' cellpadding='2'>\n\n"; // (4) Sort out and display the output echo "<tr> <th> pass? </th> <th> TAns </th> <th> SAns </th> <th> Ans </th> <th> Errors </th> <th> RawMark </th> <th> Expected </th> <th> FeedBack </th> <th> AnswerNote </th></tr>"; foreach ($testsuite as $ts) { // (0) Check this is the required AnswerTest. if ($ts['AnswerTest'] == $atest) { $err = ''; // (1) Apply the AnswerTest $this_attempt = stack_apply_answertest($ts['SAns'],$ts['TAns'],$ts['AnswerTest'],$ts['AnsTestOpt'],$disp,$err); // (2) Process $this_attempt $dispans = ''; $errans = ''; if (array_key_exists('Ans',$this_attempt)) { if (array_key_exists('display',$this_attempt['Ans'])) { $dispans=$this_attempt['Ans']['display']; } if (array_key_exists('error',$this_attempt['Ans'])) { $errans='<font color="red">'.$this_attempt['Ans']['error'].'</font>'; } } if (array_key_exists('Valid',$this_attempt)) { if ('false' == $this_attempt['Valid']) { $errans .= ' <font color="red">[invalid]</font>'; } } if (''!=$dispans) { $locs = array(); $dispans = stack_castext_to_display('$$'.$dispans.'$$', $locs , $disp,$errors); // Remove <br clear="all" /> from the beginning. if ('<br clear="all" />'==substr($dispans,0,18)) { $dispans = substr($dispans,18); } } $feedback = ''; if (array_key_exists('FeedBack',$this_attempt)) { $locs = array(); $feedback = stack_castext_to_display($this_attempt['FeedBack'], $locs , $disp,$errors); } if (array_key_exists('RawMark',$this_attempt)) { $rawmark = $this_attempt['RawMark']; } else { $rawmark = NULL; } if ( $ts['ExpectedScore'] == $rawmark ) { $outcome = '<font color="green">pass</font>'; } else { $all_passed = FALSE; $outcome = '<font color="red">fail</font>'; } // (3) Echo notes. echo "<tr>\n"; echo " <td colspan = \"9\">{$ts['Notes']}</td>\n"; echo "</tr>\n"; // (4) Construct the row. echo " <td> $outcome </td>\n"; echo " <td nowrap=\"nowrap\">".stack_s($ts['TAns'])." </td>\n "; echo " <td nowrap=\"nowrap\">".stack_s($ts['SAns'])." </td>\n "; echo " <td> $dispans </td>\n "; echo " <td> $errans </td>\n "; echo " <td> $rawmark </td>\n "; echo " <td> {$ts['ExpectedScore']} </td>\n"; echo " <td> $feedback </td>\n "; if (array_key_exists('AnswerNote',$this_attempt)) { echo " <td> {$this_attempt['AnswerNote']} </td>\n "; } else { echo " <td>   </td>\n "; } echo "</tr>\n"; } // End of check for which AnswerTest this is. } echo "</table></p>\n\n"; // (7) Overall, did all the tests pass if ( $all_passed ) { echo '<h2><font color="green">All tests passed!</font></h2>'; } else { echo '<h2><font color="red">Not all tests passed!</font></h2>'; } echo "<hr />\n"; } ?> |