function testGenerate() { $this->clearAll(); $this->clearTemp(); $importer = $this->createXmlImporter($this->path); $importer->parseFile('q0.xml'); //Create the quiz $qz = $this->createQuiz("Some Quiz", $this->permissions_group); //Add tested concept to quiz $this->addTestedConcept($qz, 'Concept_0', 3); My_Logger::clearLog(); $this->clearMysqlLog(); My_Logger::log('**** BEGIN ******'); // Get the Question XML $file = $this->config->xml->import_path . "/q0.xml"; //Apparently this creates nothing. Actual compilation occurrs when specific setters are called on view code $mQuestion = new Model_Shell_GenericQuestion($file); //My_Logger::log( __METHOD__ . ' **********'); $this->assertEquals('output', $mQuestion->getFriendlyType()); $this->assertTrue(in_array('Concept_0', $mQuestion->getConcepts())); $this->assertEquals('1', $mQuestion->getDifficulty()); //Here comes the compilation. After this single call, all the artifacts are produced $this->assertEquals('What is printed on the screen?', $mQuestion->getInstructions()); //return; //for fun let's ourselves load the xml $xml = simplexml_load_file($file); My_Logger::log(__METHOD__ . ": simpleXml " . print_r($xml, true)); My_Logger::log(__METHOD__ . ": substitution " . print_r($xml->substitutions->substitution[0], true)); My_Logger::log(__METHOD__ . ": substitution " . (string) $xml->substitutions->substitution[0]->attributes()->{'val'}); My_Logger::log(__METHOD__ . ": substitution " . (string) $xml->substitutions->substitution[0]); //My_Logger::log( __METHOD__. "problem:" . (string)$xml->problem); //My_Logger::log( __METHOD__. "actual:" . $mQuestion->getProblem()); //$this->assertEquals((string)$xml->problem, $mQuestion->getProblem()); //apparently some CR is introduced, so we have to trim $this->assertEquals(trim((string) $xml->problem), trim($mQuestion->getProblem())); $this->assertEquals('System.out.print("Hello World!");', trim($mQuestion->getProblemNoHiddenLines())); //$this->clearTemp(); $this->assertEquals('Hello World!', $mQuestion->getCorrectOutput()); //Model_Shell_Debug::getInstance()->saveToDisk(); }
function qualityTest($data) { //Will try to generate n questions, and show a ratio of success/total compilations $total = 10; $success = $errors = 0; $config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV); $xml_path = $config->xml->import_path; $selected_xml = $this->get($data['file']); if (empty($selected_xml)) { throw new Exception("Please save file first."); } $full_filename = $xml_path . "/" . $selected_xml . ".xml"; My_Logger::log(__METHOD__ . " full_filename: " . $full_filename); if (!file_exists($full_filename)) { throw new Exception("File does not exist."); } for ($i = 1; $i <= $total; $i++) { try { $mQuestion = new Model_Shell_GenericQuestion($full_filename); $mQuestion->getProblemNoHiddenLines(); $mQuestion->getCorrectOutput(); $success++; } catch (Exception $e) { //throw $e; $errors++; } } My_Logger::log("total: {$total}, error: {$errors}, success: {$success}"); $ratio = round($success / $total * 100, 2); return array('result' => 'success', 'title' => 'Compilation results', 'msg' => 'Success Ratio:' . $ratio . '%'); }