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