Files
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

102 lines
2.2 KiB
PHP

<?php
/**
* EvalMathTest.php
*
* @author dbojdo - Daniel Bojdo <daniel.bojdo@8x8.com>
* Created on 02 12, 2016, 17:17
* Copyright (C) 8x8
*/
namespace Webit\Util\EvalMath\Tests;
use Webit\Util\EvalMath\EvalMath;
class EvalMathTest extends \PHPUnit_Framework_TestCase
{
/**
* @var EvalMath
*/
private $evalMath;
protected function setUp()
{
$this->evalMath = new EvalMath();
}
/**
* @test
* @dataProvider moduloOperatorData
*/
public function shouldSupportModuloOperator($formula, $values, $expectedResult)
{
foreach ($values as $k => $v) {
$this->evalMath->v[$k] = $v;
}
$this->assertEquals($expectedResult, $this->evalMath->evaluate($formula));
}
public function moduloOperatorData()
{
return array(
array(
'a%b', // 9%3 => 0
array('a' => 9, 'b' => 3),
0
),
array(
'a%b', // 10%3 => 1
array('a' => 10, 'b' => 3),
1
),
array(
'10-a%(b+c*d)', // 10-10%(7-2*2) => 9
array('a' => '10', 'b' => 7, 'c'=> -2, 'd' => 2),
9
)
);
}
/**
* @test
* @dataProvider doubleMinusData
*/
public function shouldConsiderDoubleMinusAsPlus($formula, $values, $expectedResult)
{
foreach ($values as $k => $v) {
$this->evalMath->v[$k] = $v;
}
$this->assertEquals(
$expectedResult,
$this->evalMath->evaluate($formula)
);
}
public function doubleMinusData()
{
return array(
array(
'a+b*c--d', // 1+2*3--4 => 1+6+4 => 11
array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4
),
11
),
array(
'a+b*c--d', // 1+2*3---4 => 1+6-4 => 3
array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => -4
),
3
)
);
}
}