Skip to content
Commits on Source (19)
...@@ -7,23 +7,25 @@ ...@@ -7,23 +7,25 @@
* Time: 13:51 * Time: 13:51
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class CompositeBuilderTest extends PHPUnit_Framework_TestCase { class CompositeBuilderTest extends PHPUnit_Framework_TestCase
{
/** /**
* @var CompositeBuilder * @var CompositeBuilder
*/ */
protected $builder; protected $builder;
public function setUp(){ public function setUp()
include_once __DIR__ . '/../classes/CompositeBuilder.php'; {
$this->builder = new CompositeBuilder; include_once __DIR__ . '/../classes/CompositeBuilder.php';
} $this->builder = new CompositeBuilder;
}
public function test_OperatorsWeight() public function test_OperatorsWeight()
{ {
$weight = array('<=','<','=','>=','>','<>','&','|'); $weight = array('<=','<','=','>=','>','<>','&','|');
$operators = $this->readAttribute($this->builder, "operators"); $operators = $this->readAttribute($this->builder, "operators");
$this->assertEmpty(array_diff($weight, $operators)); $this->assertEmpty(array_diff($weight, $operators));
} }
} }
...@@ -8,56 +8,55 @@ include_once __DIR__ . '/../classes/ConditionParser.php'; ...@@ -8,56 +8,55 @@ include_once __DIR__ . '/../classes/ConditionParser.php';
* Date: 25.03.13 * Date: 25.03.13
* Time: 11:05 * Time: 11:05
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ConditionParserProxy extends ConditionParser{ class ConditionParserProxy extends ConditionParser
{
public function fetchExpressions() public function fetchExpressions()
{ {
parent::fetchExpressions(); // TODO: Change the autogenerated stub parent::fetchExpressions(); // TODO: Change the autogenerated stub
} }
public function fetchOperators() public function fetchOperators()
{ {
parent::fetchOperators(); // TODO: Change the autogenerated stub parent::fetchOperators(); // TODO: Change the autogenerated stub
} }
public function cannonicalizeCondition() public function cannonicalizeCondition()
{ {
parent::cannonicalizeCondition(); // TODO: Change the autogenerated stub parent::cannonicalizeCondition(); // TODO: Change the autogenerated stub
} }
public function createNodeArray() public function createNodeArray()
{ {
return parent::createNodeArray(); // TODO: Change the autogenerated stub return parent::createNodeArray(); // TODO: Change the autogenerated stub
} }
public function setCondition($condition) public function setCondition($condition)
{ {
$this->condition = $condition; $this->condition = $condition;
} }
/** /**
* @return string * @return string
*/ */
public function getCondition() public function getCondition()
{ {
return $this->condition; return $this->condition;
} }
/** /**
* @return array * @return array
*/ */
public function getExpressions() public function getExpressions()
{ {
return $this->expressions; return $this->expressions;
} }
/** /**
* @return array * @return array
*/ */
public function getOperators() public function getOperators()
{ {
return $this->operators; return $this->operators;
} }
} }
...@@ -8,159 +8,156 @@ ...@@ -8,159 +8,156 @@
* Time: 16:08 * Time: 16:08
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ConditionParserTest extends \PHPUnit_Framework_TestCase { class ConditionParserTest extends \PHPUnit_Framework_TestCase
{
protected $key_constraint; protected $key_constraint;
protected $type_constraint; protected $type_constraint;
protected $array_constraint; protected $array_constraint;
/** /**
* @var null|ConditionParserProxy * @var null|ConditionParserProxy
*/ */
protected $parser = null; protected $parser = null;
protected static $CONDITION = "Q5 = +32+ & (Q74 <= %9879% | Q5 >= #5#)"; protected static $CONDITION = "Q5 = +32+ & (Q74 <= %9879% | Q5 >= #5#)";
protected static $EXPECTED_EXPRESSIONS = array("Q5","+32+","Q74","%9879%","Q5","#5#"); protected static $EXPECTED_EXPRESSIONS = array("Q5","+32+","Q74","%9879%","Q5","#5#");
protected static $EXPECTED_OPERATORS = array("=","&","<=","|",">="); protected static $EXPECTED_OPERATORS = array("=","&","<=","|",">=");
protected static $CANNONICALIZED_CONDITION = "n o n o (n o n o n o n)"; protected static $CANNONICALIZED_CONDITION = "n o n o (n o n o n o n)";
public function setUp(){ public function setUp()
include_once 'ConditionParserProxy.php'; {
include_once __DIR__ . '/../classes/AbstractComposite.php'; include_once 'ConditionParserProxy.php';
$this->parser = new ConditionParserProxy(); include_once __DIR__ . '/../classes/AbstractComposite.php';
$this->parser = new ConditionParserProxy();
$this->key_constraint = $this->logicalOr(
$this->equalTo("type"), $this->key_constraint = $this->logicalOr(
$this->equalTo("value"), $this->equalTo("type"),
$this->equalTo("negated") $this->equalTo("value"),
); $this->equalTo("negated")
$this->type_constraint = $this->logicalOr( );
$this->equalTo("group"), $this->type_constraint = $this->logicalOr(
$this->equalTo("expression"), $this->equalTo("group"),
$this->equalTo("operator") $this->equalTo("expression"),
); $this->equalTo("operator")
$this->array_constraint = $this->logicalOr( );
$this->equalTo("nodes"), $this->array_constraint = $this->logicalOr(
$this->isType("integer") $this->equalTo("nodes"),
); $this->isType("integer")
} );
}
public function test_construction()
{ public function test_construction()
$this->assertInstanceOf('ConditionParser', $this->parser); {
} $this->assertInstanceOf('ConditionParser', $this->parser);
}
public function test_FetchExpressions()
{ public function test_FetchExpressions()
$this->parser->setCondition(self::$CONDITION); {
$this->parser->fetchExpressions(); $this->parser->setCondition(self::$CONDITION);
$this->parser->fetchExpressions();
foreach(self::$EXPECTED_EXPRESSIONS as $expression){
$this->assertContains($expression, $this->parser->getExpressions()); foreach (self::$EXPECTED_EXPRESSIONS as $expression) {
} $this->assertContains($expression, $this->parser->getExpressions());
} }
}
public function test_FetchOperators()
{ public function test_FetchOperators()
$this->parser->setCondition(self::$CONDITION); {
$this->parser->fetchOperators(); $this->parser->setCondition(self::$CONDITION);
$this->parser->fetchOperators();
foreach(self::$EXPECTED_OPERATORS as $operator){
$this->assertContains($operator, $this->parser->getOperators()); foreach (self::$EXPECTED_OPERATORS as $operator) {
} $this->assertContains($operator, $this->parser->getOperators());
} }
}
public function test_CannonicalizeCondition()
{ public function test_CannonicalizeCondition()
$this->parser->setCondition(self::$CONDITION); {
$this->parser->fetchExpressions(); $this->parser->setCondition(self::$CONDITION);
$this->parser->fetchOperators(); $this->parser->fetchExpressions();
$this->parser->cannonicalizeCondition(); $this->parser->fetchOperators();
$this->assertEquals(self::$CANNONICALIZED_CONDITION, $this->parser->getCondition()); $this->parser->cannonicalizeCondition();
} $this->assertEquals(self::$CANNONICALIZED_CONDITION, $this->parser->getCondition());
}
public function test_CreateNodeArray()
{ public function test_CreateNodeArray()
$this->parser->setCondition(self::$CONDITION); {
$this->parser->fetchExpressions(); $this->parser->setCondition(self::$CONDITION);
$this->parser->fetchOperators(); $this->parser->fetchExpressions();
$this->parser->cannonicalizeCondition(); $this->parser->fetchOperators();
$node_array = $this->parser->createNodeArray(); $this->parser->cannonicalizeCondition();
$node_array = $this->parser->createNodeArray();
$this->recursiveNodeTest($node_array);
} $this->recursiveNodeTest($node_array);
}
public function test_Parse()
{ public function test_Parse()
$composite = $this->parser->parse(self::$CONDITION); {
$this->assertInstanceOf("AbstractComposite", $composite); $composite = $this->parser->parse(self::$CONDITION);
} $this->assertInstanceOf("AbstractComposite", $composite);
}
/**
* @expectedException UnableToParseCondition /**
*/ * @expectedException UnableToParseCondition
public function test_Nonsense() */
{ public function test_Nonsense()
$composite = $this->parser->parse("1 = 1"); {
} $composite = $this->parser->parse("1 = 1");
}
public function test_DescribeComposite()
{ public function test_DescribeComposite()
$composite = $this->parser->parse("Q1[2] & (Q2[1] | Q2[2])"); {
$this->assertInstanceOf("AbstractComposite", $composite); $composite = $this->parser->parse("Q1[2] & (Q2[1] | Q2[2])");
$description = $composite->describe(); $this->assertInstanceOf("AbstractComposite", $composite);
$expected = "(Frage 1 mit Anwort 2 beantwortet und (Frage 2 mit Anwort 1 beantwortet oder Frage 2 mit Anwort 2 beantwortet ) ) "; $description = $composite->describe();
$this->assertEquals($expected, $description); $expected = "(Frage 1 mit Anwort 2 beantwortet und (Frage 2 mit Anwort 1 beantwortet oder Frage 2 mit Anwort 2 beantwortet ) ) ";
} $this->assertEquals($expected, $description);
}
/**
* @expectedException ConditionParserException /**
*/ * @expectedException ConditionParserException
public function test_Issue1338() */
{ public function test_Issue1338()
$condition = "Q85[1]=~nach oben geöffnete Parabel~ &|Q85[2]=#0# | Q85[8]=+2+ !Q85[9]=+2+"; {
$this->parser->setCondition($condition); $condition = "Q85[1]=~nach oben geöffnete Parabel~ &|Q85[2]=#0# | Q85[8]=+2+ !Q85[9]=+2+";
$this->parser->fetchExpressions(); $this->parser->setCondition($condition);
$this->parser->getOperators(); $this->parser->fetchExpressions();
$this->parser->cannonicalizeCondition(); $this->parser->getOperators();
$this->parser->parse($condition); $this->parser->cannonicalizeCondition();
} $this->parser->parse($condition);
}
public function test_Replacing()
{ public function test_Replacing()
$condition = "Q5 = +2+ & !Q2 < #3# | !Q5 <= %100%"; {
$this->parser->setCondition($condition); $condition = "Q5 = +2+ & !Q2 < #3# | !Q5 <= %100%";
$this->parser->fetchExpressions(); $this->parser->setCondition($condition);
$this->parser->getOperators(); $this->parser->fetchExpressions();
$this->parser->cannonicalizeCondition(); $this->parser->getOperators();
$this->parser->cannonicalizeCondition();
$this->assertEquals("n o n o !(n o n) o !(n o n)", $this->parser->getCondition());
} $this->assertEquals("n o n o !(n o n) o !(n o n)", $this->parser->getCondition());
}
private function recursiveNodeTest($nodes){
foreach($nodes as $key => $node) private function recursiveNodeTest($nodes)
{ {
if(!is_array($node)) foreach ($nodes as $key => $node) {
{ if (!is_array($node)) {
$this->assertThat($key, $this->key_constraint); $this->assertThat($key, $this->key_constraint);
if($key == "type") if ($key == "type") {
{ $this->assertThat($node, $this->type_constraint);
$this->assertThat($node, $this->type_constraint); }
} } else {
} $this->assertThat($key, $this->array_constraint);
else $this->recursiveNodeTest($node);
{ }
$this->assertThat($key, $this->array_constraint); }
$this->recursiveNodeTest($node); }
}
} public function test_missingSpaces()
} {
$condition = "Q1=%100%";
public function test_missingSpaces() $composite = $this->parser->parse($condition);
{ $this->assertInstanceOf("AbstractComposite", $composite);
$condition = "Q1=%100%"; }
$composite = $this->parser->parse($condition);
$this->assertInstanceOf("AbstractComposite", $composite);
}
} }
...@@ -7,96 +7,95 @@ ...@@ -7,96 +7,95 @@
* Time: 15:51 * Time: 15:51
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ExpressionTest extends PHPUnit_Framework_TestCase { class ExpressionTest extends PHPUnit_Framework_TestCase
{
public function test_AnswerOfQuestionExpression()
public function test_AnswerOfQuestionExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/AnswerOfQuestionExpression.php';
include_once __DIR__ . '/../../classes/Expressions/AnswerOfQuestionExpression.php'; $expression = new AnswerOfQuestionExpression();
$expression = new AnswerOfQuestionExpression(); $expression->parseValue("Q3672");
$expression->parseValue("Q3672");
$this->assertEquals("Q3672", $expression->getValue());
$this->assertEquals("Q3672", $expression->getValue()); $this->assertEquals(3672, $expression->getQuestionIndex());
$this->assertEquals(3672, $expression->getQuestionIndex()); }
}
public function test_NumberOfResultExpression()
public function test_NumberOfResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/NumberOfResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/NumberOfResultExpression.php'; $expression = new NumberOfResultExpression();
$expression = new NumberOfResultExpression(); $expression->parseValue("+34+");
$expression->parseValue("+34+");
$this->assertEquals("+34+", $expression->getValue());
$this->assertEquals("+34+", $expression->getValue()); $this->assertEquals(34, $expression->getNumericValue());
$this->assertEquals(34, $expression->getNumericValue()); }
}
public function test_NumericResultExpression()
public function test_NumericResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/NumericResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/NumericResultExpression.php'; $expression = new NumericResultExpression();
$expression = new NumericResultExpression(); $expression->parseValue("#-4.5#");
$expression->parseValue("#-4.5#");
$this->assertEquals("#-4.5#", $expression->getValue());
$this->assertEquals("#-4.5#", $expression->getValue()); $this->assertEquals(-4.5, $expression->getNumericValue());
$this->assertEquals(-4.5, $expression->getNumericValue()); }
}
public function test_PercentageResultExpression()
public function test_PercentageResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/PercentageResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/PercentageResultExpression.php'; $expression = new PercentageResultExpression();
$expression = new PercentageResultExpression(); $expression->parseValue("%99.9%");
$expression->parseValue("%99.9%");
$this->assertEquals("%99.9%", $expression->getValue());
$this->assertEquals("%99.9%", $expression->getValue()); $this->assertEquals(99.9, $expression->getNumericValue());
$this->assertEquals(99.9, $expression->getNumericValue()); }
}
public function test_ResultOfAnswerOfQuestionExpression()
public function test_ResultOfAnswerOfQuestionExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/ResultOfAnswerOfQuestionExpression.php';
include_once __DIR__ . '/../../classes/Expressions/ResultOfAnswerOfQuestionExpression.php'; $expression = new ResultOfAnswerOfQuestionExpression();
$expression = new ResultOfAnswerOfQuestionExpression(); $expression->parseValue("Q36[49]");
$expression->parseValue("Q36[49]");
$this->assertEquals("Q36[49]", $expression->getValue());
$this->assertEquals("Q36[49]", $expression->getValue()); $this->assertEquals(36, $expression->getQuestionIndex());
$this->assertEquals(36, $expression->getQuestionIndex()); $this->assertEquals(49, $expression->getAnswerIndex());
$this->assertEquals(49, $expression->getAnswerIndex()); }
}
public function test_StringResultExpression()
public function test_StringResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/StringResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/StringResultExpression.php'; $expression = new StringResultExpression();
$expression = new StringResultExpression(); $expression->parseValue("~Hallo Welt~");
$expression->parseValue("~Hallo Welt~");
$this->assertEquals("~Hallo Welt~", $expression->getValue());
$this->assertEquals("~Hallo Welt~", $expression->getValue()); $this->assertEquals("Hallo Welt", $expression->getText());
$this->assertEquals("Hallo Welt", $expression->getText()); }
}
public function test_MatchingResultExpression()
public function test_MatchingResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/MatchingResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/MatchingResultExpression.php'; $expression = new MatchingResultExpression();
$expression = new MatchingResultExpression(); $expression->parseValue(";14:15;");
$expression->parseValue(";14:15;");
$this->assertEquals(";14:15;", $expression->getValue());
$this->assertEquals(";14:15;", $expression->getValue()); $this->assertEquals(14, $expression->getLeftNumericValue());
$this->assertEquals(14, $expression->getLeftNumericValue()); $this->assertEquals(15, $expression->getRightNumericValue());
$this->assertEquals(15, $expression->getRightNumericValue()); }
}
public function test_OrderingResultExpression()
public function test_OrderingResultExpression() {
{ include_once __DIR__ . '/../../classes/Expressions/OrderingResultExpression.php';
include_once __DIR__ . '/../../classes/Expressions/OrderingResultExpression.php'; $expression = new OrderingResultExpression();
$expression = new OrderingResultExpression();
$expression->parseValue("$14$");
$expression->parseValue("$14$"); $this->assertEquals("$14$", $expression->getValue());
$this->assertEquals("$14$", $expression->getValue()); $this->assertEquals(array(14), $expression->getOrdering());
$this->assertEquals(array(14), $expression->getOrdering());
$expression->parseValue("$14,15$");
$expression->parseValue("$14,15$"); $this->assertEquals("$14,15$", $expression->getValue());
$this->assertEquals("$14,15$", $expression->getValue()); $this->assertEquals(array(14,15), $expression->getOrdering());
$this->assertEquals(array(14,15), $expression->getOrdering());
$expression->parseValue("$14,15,17,18,29,30,30$");
$expression->parseValue("$14,15,17,18,29,30,30$"); $this->assertEquals("$14,15,17,18,29,30,30$", $expression->getValue());
$this->assertEquals("$14,15,17,18,29,30,30$", $expression->getValue()); $this->assertEquals(array(14,15,17,18,29,30,30), $expression->getOrdering());
$this->assertEquals(array(14,15,17,18,29,30,30), $expression->getOrdering()); }
}
} }
...@@ -7,92 +7,92 @@ ...@@ -7,92 +7,92 @@
* Time: 12:30 * Time: 12:30
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase { class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase
{
/** /**
* @var ReflectionClass * @var ReflectionClass
*/ */
protected $reflection; protected $reflection;
/** /**
* @var ExpressionManufacturer * @var ExpressionManufacturer
*/ */
protected $manufacturer; protected $manufacturer;
/** /**
* @var string * @var string
*/ */
protected $expected_pattern = '/%[0-9\.]+%|#-?[0-9\.]+#|\+[0-9]+\+|(Q\d+)(?=\=|<|>|\s|$)|Q[0-9]+\[[0-9]+\]|~.*?~|;[0-9]+:[0-9]+;|\$[0-9]+(?:,[0-9]+)*\$|\*[0-9]+(?:,[0-9]+)*\*/'; protected $expected_pattern = '/%[0-9\.]+%|#-?[0-9\.]+#|\+[0-9]+\+|(Q\d+)(?=\=|<|>|\s|$)|Q[0-9]+\[[0-9]+\]|~.*?~|;[0-9]+:[0-9]+;|\$[0-9]+(?:,[0-9]+)*\$|\*[0-9]+(?:,[0-9]+)*\*/';
public function setUp(){ public function setUp()
include_once __DIR__ . '/../../classes/Factory/ExpressionManufacturer.php'; {
include_once __DIR__ . '/../../classes/Factory/ExpressionManufacturer.php';
$this->reflection = new ReflectionClass("ExpressionManufacturer"); $this->reflection = new ReflectionClass("ExpressionManufacturer");
$this->manufacturer = ExpressionManufacturer::_getInstance(); $this->manufacturer = ExpressionManufacturer::_getInstance();
} }
public function test_NotConstructable() public function test_NotConstructable()
{ {
$this->assertFalse($this->reflection->isInstantiable()); $this->assertFalse($this->reflection->isInstantiable());
$method = $this->reflection->getMethod("__construct"); $method = $this->reflection->getMethod("__construct");
$this->assertTrue($method->isPrivate()); $this->assertTrue($method->isPrivate());
} }
public function test_NotCloneable() public function test_NotCloneable()
{ {
$this->assertFalse($this->reflection->isCloneable()); $this->assertFalse($this->reflection->isCloneable());
$method = $this->reflection->getMethod("__clone"); $method = $this->reflection->getMethod("__clone");
$this->assertTrue($method->isPrivate()); $this->assertTrue($method->isPrivate());
} }
public function test_Singleton() public function test_Singleton()
{ {
$this->assertNotNull($this->manufacturer); $this->assertNotNull($this->manufacturer);
$this->assertEquals($this->manufacturer, ExpressionManufacturer::_getInstance()); $this->assertEquals($this->manufacturer, ExpressionManufacturer::_getInstance());
} }
public function test_GetPattern() public function test_GetPattern()
{ {
$this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern()); $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern());
} }
public function test_MatchPattern() public function test_MatchPattern()
{ {
$subject = 'Q5 Q66 Q52[92] ~Hallo_Welt~ #5# +32+ %098% $3,4,5$ ;2:6;'; $subject = 'Q5 Q66 Q52[92] ~Hallo_Welt~ #5# +32+ %098% $3,4,5$ ;2:6;';
$matches = $this->manufacturer->match($subject); $matches = $this->manufacturer->match($subject);
$tokens = \explode(" ", $subject); $tokens = \explode(" ", $subject);
foreach($tokens as $token) foreach ($tokens as $token) {
{ $this->assertContains($token, $matches);
$this->assertContains($token, $matches); }
} }
}
public function test_SupportedExpressions() public function test_SupportedExpressions()
{ {
$expressions = array( $expressions = array(
"Q736" => 'AnswerOfQuestionExpression', "Q736" => 'AnswerOfQuestionExpression',
"Q52[90]" => "ResultOfAnswerOfQuestionExpression", "Q52[90]" => "ResultOfAnswerOfQuestionExpression",
"%9%" => "PercentageResultExpression", "%9%" => "PercentageResultExpression",
"+14+" => "NumberOfResultExpression", "+14+" => "NumberOfResultExpression",
"#2#" => "NumericResultExpression", "#2#" => "NumericResultExpression",
"~Hello World~" => "StringResultExpression", "~Hello World~" => "StringResultExpression",
";2:5;" => "MatchingResultExpression", ";2:5;" => "MatchingResultExpression",
"$2,3,4,5$" => "OrderingResultExpression" "$2,3,4,5$" => "OrderingResultExpression"
); );
foreach($expressions as $key => $expression) foreach ($expressions as $key => $expression) {
{ include_once __DIR__ . "/../../classes/Expressions/" . $expression . ".php";
include_once __DIR__ . "/../../classes/Expressions/" . $expression . ".php"; $expression_object = $this->manufacturer->manufacture($key);
$expression_object = $this->manufacturer->manufacture($key); $this->assertInstanceOf($expression, $expression_object);
$this->assertInstanceOf($expression, $expression_object); }
} }
}
/** /**
* @expectedException UnsupportedExpression * @expectedException UnsupportedExpression
*/ */
public function test_UnsupportedExpression() public function test_UnsupportedExpression()
{ {
$this->manufacturer->manufacture("%23#"); $this->manufacturer->manufacture("%23#");
} }
} }
...@@ -7,92 +7,92 @@ ...@@ -7,92 +7,92 @@
* Time: 12:30 * Time: 12:30
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class OperationManufacturerTest extends PHPUnit_Framework_TestCase { class OperationManufacturerTest extends PHPUnit_Framework_TestCase
{
/** /**
* @var ReflectionClass * @var ReflectionClass
*/ */
protected $reflection; protected $reflection;
/** /**
* @var OperationManufacturer * @var OperationManufacturer
*/ */
protected $manufacturer; protected $manufacturer;
/** /**
* @var string * @var string
*/ */
protected $expected_pattern = '/[&\|<>=]+/'; protected $expected_pattern = '/[&\|<>=]+/';
public function setUp(){ public function setUp()
include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php'; {
include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php';
$this->reflection = new ReflectionClass("OperationManufacturer"); $this->reflection = new ReflectionClass("OperationManufacturer");
$this->manufacturer = OperationManufacturer::_getInstance(); $this->manufacturer = OperationManufacturer::_getInstance();
} }
public function test_NotConstructable() public function test_NotConstructable()
{ {
$this->assertFalse($this->reflection->isInstantiable()); $this->assertFalse($this->reflection->isInstantiable());
$method = $this->reflection->getMethod("__construct"); $method = $this->reflection->getMethod("__construct");
$this->assertTrue($method->isPrivate()); $this->assertTrue($method->isPrivate());
} }
public function test_NotCloneable() public function test_NotCloneable()
{ {
$this->assertFalse($this->reflection->isCloneable()); $this->assertFalse($this->reflection->isCloneable());
$method = $this->reflection->getMethod("__clone"); $method = $this->reflection->getMethod("__clone");
$this->assertTrue($method->isPrivate()); $this->assertTrue($method->isPrivate());
} }
public function test_Singleton() public function test_Singleton()
{ {
$this->assertNotNull($this->manufacturer); $this->assertNotNull($this->manufacturer);
$this->assertEquals($this->manufacturer, OperationManufacturer::_getInstance()); $this->assertEquals($this->manufacturer, OperationManufacturer::_getInstance());
} }
public function test_GetPattern() public function test_GetPattern()
{ {
$this->assertEquals($this->expected_pattern,$this->manufacturer->getPattern()); $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern());
} }
public function test_MatchPattern() public function test_MatchPattern()
{ {
$subject = '< = > & | <> <= >='; $subject = '< = > & | <> <= >=';
$matches = $this->manufacturer->match($subject); $matches = $this->manufacturer->match($subject);
$tokens = \explode(" ", $subject); $tokens = \explode(" ", $subject);
foreach($tokens as $token) foreach ($tokens as $token) {
{ $this->assertContains($token, $matches);
$this->assertContains($token, $matches); }
} }
}
public function test_SupportedOperations() public function test_SupportedOperations()
{ {
$operations = array( $operations = array(
"<" => 'LesserOperation', "<" => 'LesserOperation',
"<=" => "LesserOrEqualsOperation", "<=" => "LesserOrEqualsOperation",
"=" => "EqualsOperation", "=" => "EqualsOperation",
">=" => "GreaterOrEqualsOperation", ">=" => "GreaterOrEqualsOperation",
">" => "GreaterOperation", ">" => "GreaterOperation",
"<>" => "NotEqualsOperation", "<>" => "NotEqualsOperation",
"&" => "AndOperation", "&" => "AndOperation",
"|" => "OrOperation" "|" => "OrOperation"
); );
foreach($operations as $key => $operation) foreach ($operations as $key => $operation) {
{ include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php";
include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php"; $operation_object = $this->manufacturer->manufacture($key);
$operation_object = $this->manufacturer->manufacture($key); $this->assertInstanceOf($operation, $operation_object);
$this->assertInstanceOf($operation, $operation_object); }
} }
}
/** /**
* @expectedException UnsupportedOperation * @expectedException UnsupportedOperation
*/ */
public function test_UnsupportedOperation() public function test_UnsupportedOperation()
{ {
$this->manufacturer->manufacture("=="); $this->manufacturer->manufacture("==");
} }
} }
...@@ -8,37 +8,41 @@ include_once 'CompositeInterface.php'; ...@@ -8,37 +8,41 @@ include_once 'CompositeInterface.php';
* Date: 25.03.13 * Date: 25.03.13
* Time: 10:05 * Time: 10:05
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
abstract class AbstractComposite implements CompositeInterface { abstract class AbstractComposite implements CompositeInterface
{
/** /**
* @var AbstractComposite[] * @var AbstractComposite[]
*/ */
public $nodes = array(); public $nodes = array();
/** /**
* Adds an CompositeInterface object to the node array which represents the condition tree structure * Adds an CompositeInterface object to the node array which represents the condition tree structure
* *
* @param CompositeInterface $node * @param CompositeInterface $node
*/ */
public function addNode(CompositeInterface $node) public function addNode(CompositeInterface $node)
{ {
$this->nodes[] = $node; $this->nodes[] = $node;
} }
/** /**
* Describes a Composite tree Structure as human readable string * Describes a Composite tree Structure as human readable string
* @return string * @return string
*/ */
public function describe() public function describe()
{ {
$description = ""; $description = "";
if(is_array($this->nodes)) if (is_array($this->nodes)) {
{ if (\count($this->nodes) > 0) {
if(\count($this->nodes) > 0) $description .= "(" . $this->nodes[0]->describe(); $description .= "(" . $this->nodes[0]->describe();
$description .= $this->getDescription(); }
if(\count($this->nodes) > 0) $description .= $this->nodes[1]->describe() . ") "; $description .= $this->getDescription();
} if (\count($this->nodes) > 0) {
return $description; $description .= $this->nodes[1]->describe() . ") ";
} }
}
return $description;
}
} }
...@@ -6,96 +6,89 @@ ...@@ -6,96 +6,89 @@
* Date: 27.03.13 * Date: 27.03.13
* Time: 12:18 * Time: 12:18
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class CompositeBuilder { class CompositeBuilder
{
/** /**
* This array defines the weights and direction of operators.<br /> * This array defines the weights and direction of operators.<br />
* It is required to build the composite tree with the correct depth structure * It is required to build the composite tree with the correct depth structure
* *
* @var array * @var array
*/ */
protected $operators = array('<=','<','=','>=','>','<>','&','|'); protected $operators = array('<=','<','=','>=','>','<>','&','|');
/** /**
* Construct requirements * Construct requirements
*/ */
public function __construct() public function __construct()
{ {
include_once 'Factory/OperationManufacturer.php'; include_once 'Factory/OperationManufacturer.php';
include_once 'Factory/ExpressionManufacturer.php'; include_once 'Factory/ExpressionManufacturer.php';
} }
/** /**
* @param array $nodes * @param array $nodes
* *
* @return array * @return array
*/ */
public function create($nodes) public function create($nodes)
{ {
if($nodes['type'] == 'group') if ($nodes['type'] == 'group') {
{ foreach ($nodes['nodes'] as $key => $child) {
foreach($nodes['nodes'] as $key => $child) $nodes['nodes'][$key] = $this->create($child);
{ }
$nodes['nodes'][$key] = $this->create($child);
} $counted_nodes = 0;
if (is_array($nodes['nodes'])) {
$counted_nodes = 0; $counted_nodes = count($nodes['nodes']);
if(is_array($nodes['nodes'])) }
{
$counted_nodes = count($nodes['nodes']); foreach ($this->operators as $next_operator) {
} do {
$index = -1;
foreach($this->operators as $next_operator) for ($i = 0; $i < $counted_nodes; $i++) {
{ if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) {
do{ $index = $i;
$index = -1; break;
for($i = 0; $i < $counted_nodes; $i++) }
{ }
if(!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) if ($index >= 0) {
{ $operation_manufacture = OperationManufacturer::_getInstance();
$index = $i; $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
break;
}
}
if($index >= 0)
{
$operation_manufacture = OperationManufacturer::_getInstance();
$operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
$operator->setNegated($nodes["negated"]); $operator->setNegated($nodes["negated"]);
$operator->addNode($this->getExpression($nodes, $index-1)); $operator->addNode($this->getExpression($nodes, $index - 1));
$operator->addNode($this->getExpression($nodes, $index+1)); $operator->addNode($this->getExpression($nodes, $index + 1));
$new_nodes = array_slice($nodes['nodes'], 0, $index - 1); $new_nodes = array_slice($nodes['nodes'], 0, $index - 1);
$new_nodes[] = $operator; $new_nodes[] = $operator;
$nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2)); $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2));
} }
}while($index >= 0); } while ($index >= 0);
} }
return $nodes['nodes'][0]; return $nodes['nodes'][0];
} }
return $nodes; return $nodes;
} }
/** /**
* Manufacure an expression from the delivered node and the index. If an expression already exist in the node for<br /> * Manufacure an expression from the delivered node and the index. If an expression already exist in the node for<br />
* for the delivered index, this function will return the existing expression * for the delivered index, this function will return the existing expression
* *
* @param array $node * @param array $node
* @param int $index * @param int $index
* *
* @return CompositeInterface * @return CompositeInterface
*/ */
private function getExpression(array $node, $index) private function getExpression(array $node, $index)
{ {
$manufacturer = ExpressionManufacturer::_getInstance(); $manufacturer = ExpressionManufacturer::_getInstance();
$expression = $node['nodes'][$index]; $expression = $node['nodes'][$index];
if(!($expression instanceof AbstractComposite)) if (!($expression instanceof AbstractComposite)) {
{ $expression = $manufacturer->manufacture($node['nodes'][$index]['value']);
$expression = $manufacturer->manufacture($node['nodes'][$index]['value']); }
} return $expression;
return $expression; }
}
} }
...@@ -6,191 +6,174 @@ ...@@ -6,191 +6,174 @@
* Date: 07.01.14 * Date: 07.01.14
* Time: 13:27 * Time: 13:27
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class CompositeEvaluator { class CompositeEvaluator
{
/**
* @var ilParserQuestionProvider /**
*/ * @var ilParserQuestionProvider
protected $object_loader; */
protected $object_loader;
/**
* @var ilFormATestSession /**
*/ * @var ilFormATestSession
protected $session; */
protected $session;
/**
* @param ilParserQuestionProvider $object_loader /**
* @param ilFormATestSession $session * @param ilParserQuestionProvider $object_loader
*/ * @param ilFormATestSession $session
public function __construct($object_loader, $session) */
{ public function __construct($object_loader, $session)
$this->object_loader = $object_loader; {
$this->session = $session; $this->object_loader = $object_loader;
} $this->session = $session;
}
/**
* @param AbstractComposite $composite /**
* * @param AbstractComposite $composite
* @return bool *
*/ * @return bool
public function evaluate(AbstractComposite $composite) */
{ public function evaluate(AbstractComposite $composite)
if(is_array($composite->nodes) && count($composite->nodes) > 0) {
{ if (is_array($composite->nodes) && count($composite->nodes) > 0) {
$composite->nodes[0] = $this->evaluate($composite->nodes[0]); $composite->nodes[0] = $this->evaluate($composite->nodes[0]);
$composite->nodes[1] = $this->evaluate($composite->nodes[1]); $composite->nodes[1] = $this->evaluate($composite->nodes[1]);
$composite = $this->evaluateSubTree($composite); $composite = $this->evaluateSubTree($composite);
} }
return $composite; return $composite;
} }
/** /**
* @param AbstractComposite $composite * @param AbstractComposite $composite
* *
* @return bool * @return bool
*/ */
private function evaluateSubTree(AbstractComposite $composite) private function evaluateSubTree(AbstractComposite $composite)
{ {
$result = false; $result = false;
if($composite->nodes[0] instanceof ExpressionInterface && if ($composite->nodes[0] instanceof ExpressionInterface &&
$composite->nodes[1] instanceof ExpressionInterface $composite->nodes[1] instanceof ExpressionInterface
){ ) {
$question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex()); $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex());
$rightNode = $composite->nodes[1]; $rightNode = $composite->nodes[1];
$index = ($composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression)? $composite->nodes[0]->getAnswerIndex(): null; $index = ($composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression)? $composite->nodes[0]->getAnswerIndex(): null;
$solutions = $question->getUserQuestionResult($this->session->getActiveId(),$this->session->getPass()); $solutions = $question->getUserQuestionResult($this->session->getActiveId(), $this->session->getPass());
if($question instanceof assClozeTest) if ($question instanceof assClozeTest) {
{ // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
// @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) /**
/** * @var $gap assClozeGap
* @var $gap assClozeGap * @var $answer assAnswerCloze
* @var $answer assAnswerCloze */
*/ $result = $solutions->getSolutionForKey($index);
$result = $solutions->getSolutionForKey($index); $gap = $question->getAvailableAnswerOptions($index - 1);
$gap = $question->getAvailableAnswerOptions($index-1);
if ($rightNode instanceof StringResultExpression) {
if($rightNode instanceof StringResultExpression) if ($gap->getType() == 1) {
{ $answer = $gap->getItem($result['value'] - 1);
if($gap->getType() == 1) $solutions->removeByKey($index);
{ $solutions->addKeyValue($index, $answer->getAnswertext());
$answer = $gap->getItem($result['value'] - 1); }
$solutions->removeByKey($index); } elseif (
$solutions->addKeyValue($index, $answer->getAnswertext()); $rightNode instanceof PercentageResultExpression &&
} $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression) {
} /**
else if( * @var $answers assAnswerCloze[]
$rightNode instanceof PercentageResultExpression && */
$composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression) $answers = $gap->getItems(new ilArrayElementShuffler());
{ $max_points = 0;
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; foreach ($answers as $answer) {
/** if ($max_points < $answer->getPoints()) {
* @var $answers assAnswerCloze[] $max_points = $answer->getPoints();
*/ }
$answers = $gap->getItems(new ilArrayElementShuffler()); }
$max_points = 0;
foreach($answers as $answer) $item = null;
{ $reached_points = null;
if($max_points < $answer->getPoints()) // @todo for Thomas J.: Maybe handle identical scoring for every type
{ switch ($gap->getType()) {
$max_points = $answer->getPoints(); case CLOZE_TEXT:
} for ($order = 0; $order < $gap->getItemCount(); $order++) {
} $answer = $gap->getItem($order);
$item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints());
$item = null; if ($item_points > $reached_points) {
$reached_points = null; $reached_points = $item_points;
// @todo for Thomas J.: Maybe handle identical scoring for every type }
switch($gap->getType()) }
{ break;
case CLOZE_TEXT:
for($order = 0; $order < $gap->getItemCount(); $order++) case CLOZE_NUMERIC:
{ for ($order = 0; $order < $gap->getItemCount(); $order++) {
$answer = $gap->getItem($order); $answer = $gap->getItem($order);
$item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints()); $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound());
if($item_points > $reached_points) $reached_points = $item_points; if ($item_points > $reached_points) {
} $reached_points = $item_points;
break; }
}
case CLOZE_NUMERIC: break;
for($order = 0; $order < $gap->getItemCount(); $order++)
{ case CLOZE_SELECT:
$answer = $gap->getItem($order); if ($result['value'] != null) {
$item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); $answer = $gap->getItem($result['value'] - 1);
if($item_points > $reached_points) $reached_points = $item_points; $reached_points = $answer->getPoints();
} }
break; break;
}
case CLOZE_SELECT:
if($result['value'] != null) $percentage = 0;
{ if ($max_points != 0 && $reached_points !== null) {
$answer = $gap->getItem($result['value'] - 1); $percentage = (int) (($reached_points / $max_points) * 100);
$reached_points = $answer->getPoints(); }
} $solutions->setReachedPercentage($percentage);
break; }
} }
$percentage = 0; if (
if($max_points != 0 && $reached_points !== null) $question instanceof assFormulaQuestion &&
{ $rightNode instanceof PercentageResultExpression &&
$percentage = (int)(($reached_points / $max_points) * 100); $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression
} ) {
$solutions->setReachedPercentage($percentage); // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases)
} $result = $solutions->getSolutionForKey($index);
} $answer = $question->getAvailableAnswerOptions($index - 1);
if( $unit = $solutions->getSolutionForKey($index . "_unit");
$question instanceof assFormulaQuestion && $key = null;
$rightNode instanceof PercentageResultExpression && if (is_array($unit)) {
$composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression $key = $unit['value'];
) }
{
// @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) $max_points = $answer->getPoints();
$result = $solutions->getSolutionForKey($index); $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits());
$answer = $question->getAvailableAnswerOptions($index-1);
$percentage = 0;
$unit = $solutions->getSolutionForKey($index . "_unit"); if ($max_points != 0) {
$key = null; $percentage = (int) (($points / $max_points) * 100);
if(is_array($unit)) }
{ $solutions->setReachedPercentage($percentage);
$key = $unit['value']; }
}
$result = $rightNode->checkResult($solutions, $composite->getPattern(), $index);
$max_points = $answer->getPoints(); } else {
$points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits()); switch ($composite->getPattern()) {
case "&":
$percentage = 0; $result = $composite->nodes[0] && $composite->nodes[1];
if($max_points != 0) break;
{ case "|":
$percentage = (int)(($points/$max_points)*100); $result = $composite->nodes[0] || $composite->nodes[1];
} break;
$solutions->setReachedPercentage($percentage); default:
} $result = false;
}
$result = $rightNode->checkResult($solutions,$composite->getPattern(),$index); }
}
else if ($composite->isNegated()) {
{ return !$result;
switch($composite->getPattern()) }
{ return $result;
case "&": }
$result = $composite->nodes[0] && $composite->nodes[1];
break;
case "|":
$result = $composite->nodes[0] || $composite->nodes[1];
break;
default:
$result = false;
}
}
if($composite->isNegated())
{
return !$result;
}
return $result;
}
} }
...@@ -7,26 +7,27 @@ ...@@ -7,26 +7,27 @@
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
interface CompositeInterface { interface CompositeInterface
{
/** /**
* Adds an CompositeInterface object to the node array which represents the condition tree structure * Adds an CompositeInterface object to the node array which represents the condition tree structure
* *
* @param CompositeInterface $node * @param CompositeInterface $node
*/ */
public function addNode(CompositeInterface $node); public function addNode(CompositeInterface $node);
/** /**
* Describes a Composite tree Structure as human readable string * Describes a Composite tree Structure as human readable string
* *
* @return string * @return string
*/ */
public function describe(); public function describe();
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* *
* @return string * @return string
*/ */
public function getDescription(); public function getDescription();
} }
\ No newline at end of file
...@@ -18,292 +18,254 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ ...@@ -18,292 +18,254 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/
* Date: 04.12.13 * Date: 04.12.13
* Time: 14:19 * Time: 14:19
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class CompositeValidator class CompositeValidator
{ {
/** /**
* @var ilParserQuestionProvider * @var ilParserQuestionProvider
* *
* @todo Needs to be abstract or interface * @todo Needs to be abstract or interface
*/ */
protected $object_loader; protected $object_loader;
/** /**
* @var ilQuestionSetPoolNode * @var ilQuestionSetPoolNode
*/ */
protected $node; protected $node;
/** /**
* @var array * @var array
*/ */
protected $data; protected $data;
/** /**
* @param ilParserQuestionProvider $object_loader * @param ilParserQuestionProvider $object_loader
* @oaram ilQuestionSetPoolNode $node * @oaram ilQuestionSetPoolNode $node
* @param array $data * @param array $data
*/ */
public function __construct($object_loader, $node, $data) public function __construct($object_loader, $node, $data)
{ {
$this->object_loader = $object_loader; $this->object_loader = $object_loader;
$this->node = $node; $this->node = $node;
$this->data = $data; $this->data = $data;
} }
public function validate(AbstractComposite $composite) public function validate(AbstractComposite $composite)
{ {
if(is_array($composite->nodes) && count($composite->nodes) > 0) if (is_array($composite->nodes) && count($composite->nodes) > 0) {
{ $this->validate($composite->nodes[0]);
$this->validate($composite->nodes[0]); $this->validate($composite->nodes[1]);
$this->validate($composite->nodes[1]); $this->validateSubTree($composite);
$this->validateSubTree($composite); }
}
return; return;
} }
private function validateSubTree(AbstractComposite $composite) private function validateSubTree(AbstractComposite $composite)
{ {
if($composite->nodes[0] instanceof QuestionExpressionInterface && if ($composite->nodes[0] instanceof QuestionExpressionInterface &&
$composite->nodes[1] instanceof SolutionExpressionInterface $composite->nodes[1] instanceof SolutionExpressionInterface
){ ) {
$question_expression = $composite->nodes[0]; $question_expression = $composite->nodes[0];
$answer_expression = $composite->nodes[1]; $answer_expression = $composite->nodes[1];
$question_index = $composite->nodes[0]->getQuestionIndex(); $question_index = $composite->nodes[0]->getQuestionIndex();
$answer_index = null; $answer_index = null;
$question = $this->object_loader->getQuestion($question_index); $question = $this->object_loader->getQuestion($question_index);
$this->checkQuestionExists($question, $question_index); $this->checkQuestionExists($question, $question_index);
$this->checkQuestionIsReachable($question, $question_index); $this->checkQuestionIsReachable($question, $question_index);
if($this->isResultOfAnswerExpression($question_expression)) if ($this->isResultOfAnswerExpression($question_expression)) {
{ $answer_index = $question_expression->getAnswerIndex() - 1;
$answer_index = $question_expression->getAnswerIndex()-1; $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index);
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index); }
} if ($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest)) {
if($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest)) $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue() - 1);
{ }
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue()-1);
}
$this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index); $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index);
$this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern); $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern);
if($answer_expression instanceof OrderingResultExpression && if ($answer_expression instanceof OrderingResultExpression &&
($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion ) ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion)
) ) {
{ foreach ($answer_expression->getOrdering() as $order) {
foreach($answer_expression->getOrdering() as $order) $count = 0;
{ foreach ($answer_expression->getOrdering() as $element) {
$count = 0; if ($element == $order) {
foreach($answer_expression->getOrdering() as $element) $count++;
{ }
if($element == $order) }
{ if ($count > 1) {
$count++; throw new DuplicateElement($order);
} }
}
if($count > 1)
{
throw new DuplicateElement($order);
}
$this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order-1); $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order - 1);
} }
} }
if($question instanceof assClozeTest) if ($question instanceof assClozeTest) {
{ $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index);
$this->validateClozeTest($answer_index, $question, $answer_expression, $question_index); } elseif (
} $answer_expression instanceof PercentageResultExpression &&
elseif( $this->isResultOfAnswerExpression($question_expression) &&
$answer_expression instanceof PercentageResultExpression && !($question instanceof assFormulaQuestion)
$this->isResultOfAnswerExpression($question_expression) && ) {
!($question instanceof assFormulaQuestion) throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[" . ($answer_index + 1) . "]");
) }
{ } elseif (
throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[". ($answer_index+1) . "]"); ($composite->nodes[0] instanceof AbstractOperation &&
} $composite->nodes[1] instanceof ExpressionInterface) ||
} ($composite->nodes[0] instanceof ExpressionInterface &&
elseif( $composite->nodes[1] instanceof AbstractOperation) ||
($composite->nodes[0] instanceof AbstractOperation && ($composite->nodes[0] instanceof SolutionExpressionInterface)
$composite->nodes[1] instanceof ExpressionInterface) || ) {
($composite->nodes[0] instanceof ExpressionInterface && throw new UnableToParseCondition("");
$composite->nodes[1] instanceof AbstractOperation) || }
($composite->nodes[0] instanceof SolutionExpressionInterface) }
)
{
throw new UnableToParseCondition("");
}
}
/** /**
* @param int $answer_index * @param int $answer_index
* @param assQuestion|iQuestionCondition $question * @param assQuestion|iQuestionCondition $question
* @param ExpressionInterface $answer_expression * @param ExpressionInterface $answer_expression
* @param int $question_index * @param int $question_index
* *
* @throws AnswerValueNotExist * @throws AnswerValueNotExist
*/ */
private function validateClozeTest($answer_index, $question, $answer_expression, $question_index) private function validateClozeTest($answer_index, $question, $answer_expression, $question_index)
{ {
if($answer_index !== null) if ($answer_index !== null) {
{ $options = $question->getAvailableAnswerOptions($answer_index);
$options = $question->getAvailableAnswerOptions($answer_index); $found = false;
$found = false; switch ($options->getType()) {
switch($options->getType()) case 0: // text
{ if (
case 0: // text $answer_expression instanceof StringResultExpression
if( ) {
$answer_expression instanceof StringResultExpression $found = true;
) }
{
$found = true;
}
break; break;
case 1: // select case 1: // select
if($answer_expression instanceof StringResultExpression) if ($answer_expression instanceof StringResultExpression) {
{ foreach ($options->getItems(new ilArrayElementShuffler()) as $item) {
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; if ($item->getAnswertext() == $answer_expression->getText()) {
foreach($options->getItems(new ilArrayElementShuffler()) as $item) $found = true;
{ }
if($item->getAnswertext() == $answer_expression->getText()) }
{ } elseif ($answer_expression instanceof NumberOfResultExpression) {
$found = true; foreach ($options->getItems(new ilArrayElementShuffler()) as $item) {
} if ($item->getOrder() == $answer_expression->getNumericValue() - 1) {
} $found = true;
} }
elseif($answer_expression instanceof NumberOfResultExpression) }
{ }
require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; break;
foreach($options->getItems(new ilArrayElementShuffler()) as $item) case 2: // numeric
{ if ($answer_expression instanceof NumericResultExpression) {
if($item->getOrder() == $answer_expression->getNumericValue()-1) $found = true;
{ }
$found = true; break;
} }
}
}
break;
case 2: // numeric
if($answer_expression instanceof NumericResultExpression)
{
$found = true;
}
break;
}
if($answer_expression instanceof EmptyAnswerExpression) if ($answer_expression instanceof EmptyAnswerExpression) {
{ $found = true;
$found = true; }
} if (!$found && !($answer_expression instanceof PercentageResultExpression)) {
if(!$found && !($answer_expression instanceof PercentageResultExpression)) throw new AnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index + 1);
{ }
throw new AnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index+1); }
} }
} /**
} * @param iQuestionCondition $question
* @param int $question_index
* @param int $answer_index
*
* @throws AnswerIndexNotExist
*/
private function checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index)
{
$answer_options = $question->getAvailableAnswerOptions($answer_index);
if ($answer_options == null) {
throw new AnswerIndexNotExist($question_index, $answer_index + 1);
}
}
/** /**
* @param iQuestionCondition $question * @param assQuestion|null $question
* @param int $question_index * @param int $index
* @param int $answer_index *
* * @throws QuestionNotExist
* @throws AnswerIndexNotExist */
*/ private function checkQuestionExists($question, $index)
private function checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index) {
{ if ($question == null) {
$answer_options = $question->getAvailableAnswerOptions($answer_index); throw new QuestionNotExist($index);
if($answer_options == null) }
{ }
throw new AnswerIndexNotExist($question_index, $answer_index+1);
}
}
/** /**
* @param assQuestion|null $question * @param ExpressionInterface $expression
* @param int $index *
* * @return bool
* @throws QuestionNotExist */
*/ private function isResultOfAnswerExpression($expression)
private function checkQuestionExists($question, $index) {
{ return $expression instanceof ResultOfAnswerOfQuestionExpression;
if($question == null) }
{
throw new QuestionNotExist($index);
}
}
/** /**
* @param ExpressionInterface $expression * @param array $expressions
* * @param ExpressionInterface $answer_expression
* @return bool * @param int $question_index
*/ *
private function isResultOfAnswerExpression($expression) * @throws ExpressionNotSupportedByQuestion
{ */
return $expression instanceof ResultOfAnswerOfQuestionExpression; private function checkAnswerExpressionExist($expressions, $answer_expression, $question_index)
} {
if (!in_array($answer_expression::$identifier, $expressions)) {
throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index);
}
}
/** /**
* @param array $expressions * @param array $operators
* @param ExpressionInterface $answer_expression * @param ExpressionInterface $answer_expression
* @param int $question_index * @param string $pattern
* *
* @throws ExpressionNotSupportedByQuestion * @throws OperatorNotSupportedByExpression
*/ */
private function checkAnswerExpressionExist($expressions, $answer_expression, $question_index) private function checkOperatorExistForExpression($operators, $answer_expression, $pattern)
{ {
if(!in_array($answer_expression::$identifier, $expressions)) if (!in_array($pattern, $operators)) {
{ throw new OperatorNotSupportedByExpression($answer_expression->getValue(), $pattern);
throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index); }
} }
}
/** /**
* @param array $operators * @param $question
* @param ExpressionInterface $answer_expression * @param $index
* @param string $pattern *
* * @throws QuestionNotReachable
* @throws OperatorNotSupportedByExpression */
*/ private function checkQuestionIsReachable($question, $index)
private function checkOperatorExistForExpression($operators, $answer_expression, $pattern) {
{ $reachable = false;
if(!in_array($pattern, $operators)) foreach ($this->data as $node) {
{ if ($node["node_index"] > $this->node->getIndex()) {
throw new OperatorNotSupportedByExpression($answer_expression->getValue(),$pattern); break;
} }
}
/** if ($node["question_fi"] == $question->getId()) {
* @param $question $reachable = true;
* @param $index break;
* }
* @throws QuestionNotReachable }
*/
private function checkQuestionIsReachable($question, $index)
{
$reachable = false;
foreach($this->data as $node)
{
if($node["node_index"] > $this->node->getIndex())
{
break;
}
if($node["question_fi"] == $question->getId()) if (!$reachable) {
{ throw new QuestionNotReachable($index);
$reachable = true; }
break; }
}
}
if(!$reachable)
{
throw new QuestionNotReachable($index);
}
}
} }
\ No newline at end of file
...@@ -10,249 +10,234 @@ require_once "Exception/ConditionParserException.php"; ...@@ -10,249 +10,234 @@ require_once "Exception/ConditionParserException.php";
* Date: 22.03.13 * Date: 22.03.13
* Time: 13:54 * Time: 13:54
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ConditionParser { class ConditionParser
{
/**
* The condition which should be parsed into a ParserComposite to match a branch condition /**
* * The condition which should be parsed into a ParserComposite to match a branch condition
* @var string *
*/ * @var string
protected $condition; */
protected $condition;
/**
* The expressions which are be matched by the regular expression ConditionParser::$regex_expression in the condition /**
* * The expressions which are be matched by the regular expression ConditionParser::$regex_expression in the condition
* @see Parser::$regex_expression *
* @var array * @see Parser::$regex_expression
*/ * @var array
protected $expressions; */
protected $expressions;
/**
* The operators which are be matched by the regular expression ConditionParser::$regex_operator in the condition /**
* * The operators which are be matched by the regular expression ConditionParser::$regex_operator in the condition
* @see Parser::$regex_operator *
* @var array * @see Parser::$regex_operator
*/ * @var array
protected $operators; */
protected $operators;
/**
* The parser index to save the current position in the condition parser /**
* * The parser index to save the current position in the condition parser
* @var int *
*/ * @var int
protected $index; */
protected $index;
/**
* Counts the number of spaces in a condition /**
* * Counts the number of spaces in a condition
* @var int *
*/ * @var int
protected $spaces; */
protected $spaces;
/**
* Construct requirements /**
*/ * Construct requirements
public function __construct(){ */
include_once __DIR__ . '/Factory/ExpressionManufacturer.php'; public function __construct()
include_once __DIR__ . '/Factory/OperationManufacturer.php'; {
include_once "CompositeBuilder.php"; include_once __DIR__ . '/Factory/ExpressionManufacturer.php';
} include_once __DIR__ . '/Factory/OperationManufacturer.php';
include_once "CompositeBuilder.php";
/** }
* Parses the delivered condition and creates a composite tree Structure
* /**
* @param $condition * Parses the delivered condition and creates a composite tree Structure
* *
* @see CompositeBuilder::create() * @param $condition
* @return array *
*/ * @see CompositeBuilder::create()
public function parse($condition){ * @return array
$this->condition = $condition; */
// $this->checkBrackets(); public function parse($condition)
$this->fetchExpressions(); {
$this->fetchOperators(); $this->condition = $condition;
$this->cannonicalizeCondition(); // $this->checkBrackets();
$this->checkBrackets(); $this->fetchExpressions();
$nodes = $this->createNodeArray(); $this->fetchOperators();
$compositeBuilder = new CompositeBuilder(); $this->cannonicalizeCondition();
return $compositeBuilder->create($nodes); $this->checkBrackets();
} $nodes = $this->createNodeArray();
$compositeBuilder = new CompositeBuilder();
/** return $compositeBuilder->create($nodes);
* Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions }
*
* @see AbstractManufacturer::match() /**
* @see ExpressionManufacturer::getPattern() * Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions
* @see Parser::$expressions *
*/ * @see AbstractManufacturer::match()
protected function fetchExpressions(){ * @see ExpressionManufacturer::getPattern()
$manufacturer = ExpressionManufacturer::_getInstance(); * @see Parser::$expressions
$this->expressions = $manufacturer->match($this->condition); */
} protected function fetchExpressions()
{
/** $manufacturer = ExpressionManufacturer::_getInstance();
* Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators $this->expressions = $manufacturer->match($this->condition);
* }
* @see AbstractManufacturer::match()
* @see OperationManufacturer::getPattern() /**
* @see Parser::$operators * Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators
*/ *
protected function fetchOperators(){ * @see AbstractManufacturer::match()
$manufacturer = OperationManufacturer::_getInstance(); * @see OperationManufacturer::getPattern()
$this->operators = $manufacturer->match($this->condition); * @see Parser::$operators
} */
protected function fetchOperators()
/** {
* Cannonicalize the condition into a more general form. <br /> $manufacturer = OperationManufacturer::_getInstance();
* It replaces all expression with "n" and all orperators with "o" <br /> $this->operators = $manufacturer->match($this->condition);
* so that the result of an condition after cannonicalization could be:<br /> }
* <br />
* (n o n) o (n o n) o n /**
*/ * Cannonicalize the condition into a more general form. <br />
protected function cannonicalizeCondition(){ * It replaces all expression with "n" and all orperators with "o" <br />
$manufacturer = ExpressionManufacturer::_getInstance(); * so that the result of an condition after cannonicalization could be:<br />
$this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition); * <br />
$manufacturer = OperationManufacturer::_getInstance(); * (n o n) o (n o n) o n
$this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition); */
$this->condition = preg_replace("/no/", "n o", $this->condition); protected function cannonicalizeCondition()
$this->condition = preg_replace("/on/", "o n", $this->condition); {
$manufacturer = ExpressionManufacturer::_getInstance();
for($i = 0; $i < strlen($this->condition); $i++) $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
{ $manufacturer = OperationManufacturer::_getInstance();
if($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
{ $this->condition = preg_replace("/no/", "n o", $this->condition);
$this->surroundNegationExpression($i); $this->condition = preg_replace("/on/", "o n", $this->condition);
}
} for ($i = 0; $i < strlen($this->condition); $i++) {
} if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
$this->surroundNegationExpression($i);
public function checkBrackets() }
{ }
$num_brackets_open = substr_count($this->condition, "("); }
$num_brackets_close = substr_count($this->condition, ")");
public function checkBrackets()
if($num_brackets_open > $num_brackets_close) {
{ $num_brackets_open = substr_count($this->condition, "(");
throw new MissingBracket(")"); $num_brackets_close = substr_count($this->condition, ")");
}
if($num_brackets_open < $num_brackets_close) if ($num_brackets_open > $num_brackets_close) {
{ throw new MissingBracket(")");
throw new MissingBracket("("); }
} if ($num_brackets_open < $num_brackets_close) {
} throw new MissingBracket("(");
}
/** }
* Creates an array representing all Nodes in a condition based on the fetched expressions and operators.<br />
* The array has a tree representation which depth is dependent to the bracketing in the condition<br /> /**
* The array contains of four main keys to identify the elements:<br /> * Creates an array representing all Nodes in a condition based on the fetched expressions and operators.<br />
* <br /> * The array has a tree representation which depth is dependent to the bracketing in the condition<br />
* <table> * The array contains of four main keys to identify the elements:<br />
* <tr> * <br />
* <th>Key</th><th>Values</th><th>Description</th> * <table>
* </tr> * <tr>
* <tr> * <th>Key</th><th>Values</th><th>Description</th>
* <td>type</td><td>"group", "expression", "operator"</td><td>The type of the node - Group is used to introduce the next tree depth</td> * </tr>
* </tr> * <tr>
* <tr> * <td>type</td><td>"group", "expression", "operator"</td><td>The type of the node - Group is used to introduce the next tree depth</td>
* <td>value</td><td>mixed</td><td>Contains an extracted expression or operation from a condition</td> * </tr>
* </tr> * <tr>
* <tr> * <td>value</td><td>mixed</td><td>Contains an extracted expression or operation from a condition</td>
* <td>nodes</td><td>array</td><td>Contains an node array</td> * </tr>
* </tr> * <tr>
* </table> * <td>nodes</td><td>array</td><td>Contains an node array</td>
* * </tr>
* @return array * </table>
*/ *
protected function createNodeArray() * @return array
{ */
$expected = array("n", "(", "!"); protected function createNodeArray()
$group = array(); {
$negation = false; $expected = array("n", "(", "!");
$group = array();
while($this->index < strlen($this->condition)) $negation = false;
{
$a = $this->condition[$this->index]; while ($this->index < strlen($this->condition)) {
if(trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) $a = $this->condition[$this->index];
{ if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) {
if ($this->condition[$this->index] == ')') if ($this->condition[$this->index] == ')') {
{ return $group;
return $group; } elseif ($this->condition[$this->index] == 'n') {
} $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions));
else if ($this->condition[$this->index] == 'n') $expected = array("o", ")");
{ } elseif ($this->condition[$this->index] == 'o') {
$group[] = array('type' => 'expression', 'value' => array_shift($this->expressions)); $group[] = array('type' => 'operator', 'value' => array_shift($this->operators));
$expected = array("o", ")"); $expected = array("n", "(", "!");
} } elseif ($this->condition[$this->index] == '(') {
else if ($this->condition[$this->index] == 'o') $this->index++;
{ $elements = $this->createNodeArray();
$group[] = array('type' => 'operator', 'value' => array_shift($this->operators)); $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements);
$expected = array("n", "(", "!"); $negation = false;
} $expected = array("o",")");
else if ($this->condition[$this->index] == '(') } elseif ($this->condition[$this->index] == "!") {
{ $negation = true;
$this->index++; }
$elements = $this->createNodeArray(); } elseif (trim($this->condition[$this->index]) != "") {
$group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements); throw new ConditionParserException($this->index - $this->spaces + 1);
$negation = false; } else {
$expected = array("o",")"); $this->spaces++;
} }
else if($this->condition[$this->index] == "!")
{ $this->index++;
$negation = true; }
} return array('type' => 'group', "negated" => $negation, 'nodes' => $group);
} }
elseif(trim($this->condition[$this->index]) != "")
{ /**
throw new ConditionParserException($this->index-$this->spaces+1); * @return array
} */
else public function getExpressions()
{ {
$this->spaces++; return $this->expressions;
} }
$this->index++; /**
} * @param int $index
return array('type' => 'group', "negated" => $negation, 'nodes' => $group); */
} protected function surroundNegationExpression($index)
{
/** $start = strpos($this->condition, "n", $index + 1);
* @return array $end = false;
*/
public function getExpressions() if ($start !== false) {
{ $end = strpos($this->condition, "n", $start + 1);
return $this->expressions; }
}
if ($start !== false && $end !== false) {
/** $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1);
* @param int $index }
*/ }
protected function surroundNegationExpression($index)
{ /**
$start = strpos($this->condition, "n", $index + 1); * @param int $index
$end = false; *
* @return boolean
if($start !== false) */
{ protected function isNegationSurroundedByBrackets($index)
$end = strpos($this->condition, "n", $start + 1); {
} $next_bracket = strpos($this->condition, "(", $index + 1);
$next_expression = strpos($this->condition, "n", $index + 1);
if($start !== false && $end !== false)
{ return $next_bracket !== false & $next_bracket < $next_expression;
$this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1); }
}
}
/**
* @param int $index
*
* @return boolean
*/
protected function isNegationSurroundedByBrackets($index)
{
$next_bracket = strpos($this->condition, "(", $index+1);
$next_expression = strpos($this->condition, "n", $index+1);
return $next_bracket !== false & $next_bracket < $next_expression;
}
} }
...@@ -2,51 +2,52 @@ ...@@ -2,51 +2,52 @@
/** /**
* Class AnswerIndexNotExist * Class AnswerIndexNotExist
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class AnswerIndexNotExist extends \RuntimeException{ class AnswerIndexNotExist extends \RuntimeException
{
/** /**
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* @var int * @var int
*/ */
protected $answer_index; protected $answer_index;
/** /**
* @param int $question_index * @param int $question_index
* @param int $answer_index * @param int $answer_index
*/ */
public function __construct($question_index, $answer_index) public function __construct($question_index, $answer_index)
{ {
$this->question_index = $question_index; $this->question_index = $question_index;
$this->answer_index = $answer_index; $this->answer_index = $answer_index;
parent::__construct( parent::__construct(
sprintf('The Question with index "Q%s" does not have an answer with the index "%s" ', $this->question_index, $this->answer_index) sprintf('The Question with index "Q%s" does not have an answer with the index "%s" ', $this->question_index, $this->answer_index)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
/** /**
* @return int * @return int
*/ */
public function getAnswerIndex() public function getAnswerIndex()
{ {
return $this->answer_index; return $this->answer_index;
} }
} }
\ No newline at end of file
...@@ -2,72 +2,72 @@ ...@@ -2,72 +2,72 @@
/** /**
* Class QuestionNotReachable * Class QuestionNotReachable
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class AnswerValueNotExist extends \RuntimeException{ class AnswerValueNotExist extends \RuntimeException
{
/** /**
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* @var string * @var string
*/ */
protected $value; protected $value;
/** /**
* @var int * @var int
*/ */
protected $answer_index; protected $answer_index;
/** /**
* @param int $question_index * @param int $question_index
* @param string $value * @param string $value
* @param int $answer_index * @param int $answer_index
*/ */
public function __construct($question_index, $value, $answer_index = null) public function __construct($question_index, $value, $answer_index = null)
{ {
$this->question_index = $question_index; $this->question_index = $question_index;
$this->answer_index = $answer_index; $this->answer_index = $answer_index;
$this->value = $value; $this->value = $value;
$message = 'The value "%s" does not exist for the question Q%s[%s]'; $message = 'The value "%s" does not exist for the question Q%s[%s]';
if($this->answer_index === null) if ($this->answer_index === null) {
{ $message = 'The value "%s" does not exist for the question Q%s';
$message = 'The value "%s" does not exist for the question Q%s'; }
}
parent::__construct( parent::__construct(
sprintf($message, $this->question_index, $value, $this->answer_index) sprintf($message, $this->question_index, $value, $this->answer_index)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
/** /**
* @return int * @return int
*/ */
public function getAnswerIndex() public function getAnswerIndex()
{ {
return $this->answer_index; return $this->answer_index;
} }
/** /**
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return $this->value; return $this->value;
} }
} }
\ No newline at end of file
...@@ -6,33 +6,32 @@ ...@@ -6,33 +6,32 @@
* Date: 02.04.14 * Date: 02.04.14
* Time: 15:40 * Time: 15:40
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ConditionParserException extends \RuntimeException class ConditionParserException extends \RuntimeException
{ {
/** /**
* @var int * @var int
*/ */
protected $column; protected $column;
/** /**
* @param int $column * @param int $column
*/ */
public function __construct($column) public function __construct($column)
{ {
$this->column = $column; $this->column = $column;
parent::__construct( parent::__construct(
sprintf('The expression at position "%s" is not valid', $this->column) sprintf('The expression at position "%s" is not valid', $this->column)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getColumn() public function getColumn()
{ {
return $this->column; return $this->column;
} }
} }
\ No newline at end of file
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
/** /**
* Class DuplicateElement * Class DuplicateElement
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class DuplicateElement extends \RuntimeException{ class DuplicateElement extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $element; protected $element;
/** /**
* @param string $bracket * @param string $bracket
*/ */
public function __construct($element) public function __construct($element)
{ {
$this->element = $element; $this->element = $element;
parent::__construct( parent::__construct(
sprintf('Duplicate key "%s" in condition', $this->element) sprintf('Duplicate key "%s" in condition', $this->element)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getElement() public function getElement()
{ {
return $this->element; return $this->element;
} }
} }
\ No newline at end of file
...@@ -2,51 +2,52 @@ ...@@ -2,51 +2,52 @@
/** /**
* Class ExpressionNotSupportedByQuestion * Class ExpressionNotSupportedByQuestion
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ExpressionNotSupportedByQuestion extends \RuntimeException{ class ExpressionNotSupportedByQuestion extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $expression; protected $expression;
/** /**
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* @param string $expression * @param string $expression
* @param int $question_index * @param int $question_index
*/ */
public function __construct($expression, $question_index) public function __construct($expression, $question_index)
{ {
$this->expression = $expression; $this->expression = $expression;
$this->question_index = $question_index; $this->question_index = $question_index;
parent::__construct( parent::__construct(
sprintf('The expression "%s" is not supported by the question with index "Q%s"', $this->expression, $this->question_index) sprintf('The expression "%s" is not supported by the question with index "Q%s"', $this->expression, $this->question_index)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
/** /**
* @return string * @return string
*/ */
public function getExpression() public function getExpression()
{ {
return $this->expression; return $this->expression;
} }
} }
\ No newline at end of file
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
/** /**
* Class AnswerIndexNotExist * Class AnswerIndexNotExist
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class MissingBracket extends \RuntimeException{ class MissingBracket extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $bracket; protected $bracket;
/** /**
* @param string $bracket * @param string $bracket
*/ */
public function __construct($bracket) public function __construct($bracket)
{ {
$this->bracket = $bracket; $this->bracket = $bracket;
parent::__construct( parent::__construct(
sprintf('There is a bracket "%s" missing in the condition', $this->bracket) sprintf('There is a bracket "%s" missing in the condition', $this->bracket)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getBracket() public function getBracket()
{ {
return $this->bracket; return $this->bracket;
} }
} }
\ No newline at end of file
...@@ -2,51 +2,52 @@ ...@@ -2,51 +2,52 @@
/** /**
* Class OperatorNotSupportedByExpression * Class OperatorNotSupportedByExpression
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class OperatorNotSupportedByExpression extends \RuntimeException{ class OperatorNotSupportedByExpression extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $operator; protected $operator;
/** /**
* @var string * @var string
*/ */
protected $expression; protected $expression;
/** /**
* @param string $expression * @param string $expression
* @param string $operator * @param string $operator
*/ */
public function __construct($expression, $operator) public function __construct($expression, $operator)
{ {
$this->expression = $expression; $this->expression = $expression;
$this->operator = $operator; $this->operator = $operator;
parent::__construct( parent::__construct(
sprintf('The expression "%s" is not supported by the operator "%s"', $this->expression, $this->operator) sprintf('The expression "%s" is not supported by the operator "%s"', $this->expression, $this->operator)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getExpression() public function getExpression()
{ {
return $this->expression; return $this->expression;
} }
/** /**
* @return string * @return string
*/ */
public function getOperator() public function getOperator()
{ {
return $this->operator; return $this->operator;
} }
} }
\ No newline at end of file
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
/** /**
* Class QuestionNotExist * Class QuestionNotExist
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class QuestionNotExist extends \RuntimeException{ class QuestionNotExist extends \RuntimeException
{
/** /**
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* @param int $question_index * @param int $question_index
*/ */
public function __construct($question_index) public function __construct($question_index)
{ {
$this->question_index = $question_index; $this->question_index = $question_index;
parent::__construct( parent::__construct(
sprintf('The Question with index "Q%s" does not exist "', $this->question_index) sprintf('The Question with index "Q%s" does not exist "', $this->question_index)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
} }
\ No newline at end of file