Skip to content

Commit

Permalink
Dev: Collect all expression tests in one list
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 25, 2017
1 parent 2e13489 commit 6c97050
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 222 deletions.
3 changes: 3 additions & 0 deletions tests/helpers/ExpressionCoreAux.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public function getDummyNodeSetup()
{
if (is_string($this->value)) {
$value = "'{$this->value}'";
} else {
$value = $this->value;
}

list($surveyId, $groupId, /* questionId */) = explode('X', $this->sgqa, 3);
return <<<EOT
// Dummy jQuery.
Expand Down
244 changes: 22 additions & 222 deletions tests/helpers/ExpressionCoreHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,31 @@ public function notes()
public function testAllExpressions()
{
$sgqa = '563168X136X5376';

$expressions = [
// Value and expression.
['', '((563168X136X5376.NAOK == " "))']
['', '((563168X136X5376.NAOK == " "))'],
['0', '((563168X136X5376.NAOK == " "))'],
['', '((563168X136X5376.NAOK != " "))'],
['3', '((563168X136X5376.NAOK != " "))'],
['3', '((563168X136X5376.NAOK != ""))'],
['', '((563168X136X5376.NAOK != ""))'],
['', '((563168X136X5376.NAOK < " "))'],
['3', '((563168X136X5376.NAOK < " "))'],
['3', '((563168X136X5376.NAOK < "A"))'],
[ '3', '((563168X136X5376.NAOK <= " "))'],
[ '3', '((563168X136X5376.NAOK <= ""))'],
[ '', '((563168X136X5376.NAOK <= " "))'],
[ '', '((563168X136X5376.NAOK > " "))'],
[ '3', '((563168X136X5376.NAOK > " "))'],
[ ' ', '((563168X136X5376.NAOK > " "))'],
[ '', '((563168X136X5376.NAOK >= ""))'],
[ '', '((563168X136X5376.NAOK >= " "))'],
[ '3', '((563168X136X5376.NAOK >= " "))'],
[ 3, '((563168X136X5376.NAOK + "2"))'],
[ 3, '((563168X136X5376.NAOK + 2))']
];

foreach ($expressions as $expr) {
$test = new ExpressionCoreAux($expr[1], $sgqa, $expr[0]);
$test->onlynum = 1;
Expand All @@ -84,227 +105,6 @@ public function testAllExpressions()
}
}

/**
* Expression: '' == ' '
*/
public function testCompareEmptyEqSpace()
{
}

/**
* Expression: '0' == ' '
*/
public function testCompareZeroEqSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK == " "))';
$value = '0';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' != ' '
*/
public function testCompareEmptyNeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK != " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' != ' '
*/
public function testCompareNumberNeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK != " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' != ''
*/
public function testCompareNumberNeEmpty()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK != ""))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' != ''
*/
public function testCompareEmptyNeEmpty()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK != ""))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' < ' '
*/
public function testCompareEmptyLtSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK < " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' < ' '
*/
public function testCompareNumberLtSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK < " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' < 'A'
*/
public function testCompareNumberLtLetter()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK < "A"))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '3' <= ' '
*/
public function testCompareNumberLeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '3' <= ''
*/
public function testCompareNumberLeEmpty()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= ""))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* '' <= ' '
*/
public function testCompareEmptyLeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK <= " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' > ' '
*/
public function testCompareEmptyGtSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK > " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '3' > ' '
*/
public function testCompareNumberGtSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK > " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: ' ' > ' '
*/
public function testCompareSpaceGtSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK > " "))';
$value = ' ';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: '' >= ''
*/
public function testCompareEmptyGeEmpty()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK >= ""))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}


/**
* Expression: '' >= ' '
*/
public function testCompareEmptyGeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK >= " "))';
$value = '';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* When constructing condition, empty string is represented
* as "No answer".
* Expression: '3' >= ' '
*/
public function testCompareNumberGeSpace()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK >= " "))';
$value = '3';
$this->compareExpression($sgqa, $value, $expression);
}

/**
* Expression: 3 + '2'
*/
public function testCompareNumberPlusString()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK + "2"))';
$value = 3;
$jsonEncodeResult = false;
$this->compareExpression($sgqa, $value, $expression, $jsonEncodeResult);
}

/**
* Expression: 3 + 2
*/
public function testCompareNumberPlusNumber()
{
$sgqa = '563168X136X5376';
$expression = '((563168X136X5376.NAOK + 2))';
$value = 3;
$jsonEncodeResult = true;
$this->compareExpression($sgqa, $value, $expression, $jsonEncodeResult);
}

/**
*
*/
Expand Down

3 comments on commit 6c97050

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;)

@olleharstedt
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a long list in the end! :D

Please sign in to comment.