本文整理汇总了PHP中Calculator::calculate方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::calculate方法的具体用法?PHP Calculator::calculate怎么用?PHP Calculator::calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator::calculate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calculate
function calculate($problem)
{
$operationFactory = new OperationFactory();
$parser = new ProblemParser($operationFactory);
$calculator = new Calculator($parser);
return $calculator->calculate($problem);
}
示例2: run
public static function run()
{
require_once dirname(__FILE__) . '/model.php';
$sum = Calculator::calculate();
require_once dirname(__FILE__) . '/view.php';
CalculatorView::build($sum, Calculator::getFirstVariable(), Calculator::getSecondVariable());
}
示例3: check
/**
* Check if the given data is ok for the given codice fiscale.
*
* @returns Returns true if the codice fiscale is ok, false otherwise.
*/
public function check()
{
$calculator = new Calculator($this->subject, array('omocodiaLevel' => $this->omocodiaLevel));
if ($this->omocodiaLevel == self::ALL_OMOCODIA_LEVELS) {
$values = $calculator->calculateAllPossibilities();
} else {
$values = array($calculator->calculate());
}
return in_array($this->codiceFiscaleToCheck, $values);
}
示例4: testCalculate
public function testCalculate()
{
$calculator = new Calculator(32);
$p1Elo = 1613;
$p2Elo = 1388;
$win = -1;
list($newP1Elo, $newP2Elo) = $calculator->calculate($p1Elo, $p2Elo, $win);
$this->assertEquals(1620, $newP1Elo);
$this->assertEquals(1381, $newP2Elo);
$this->assertEquals($newP1Elo - $p1Elo, -($newP2Elo - $p2Elo));
}
示例5: testCalculate
public function testCalculate()
{
$calc = new Calculator('2*5+3*10*2-4*3');
$this->assertEquals(58, $calc->calculate());
$calc = new Calculator('(2+3)*(4-5)');
$this->assertEquals(-5, $calc->calculate());
$calc = new Calculator('-(2+3)*(4-5)');
$this->assertEquals(5, $calc->calculate());
$calc = new Calculator('-4*(2+3)*(4-5)');
$this->assertEquals(20, $calc->calculate());
$calc = new Calculator('-4*(2+3)*(4-5)/4');
$this->assertEquals(5, $calc->calculate());
}
示例6: Calculator
<?php
require_once 'init.php';
$c = new Calculator();
$c->setOperation(new Adder());
$c->calculate(10, 50);
$c->setOperation(new Subtractor());
$c->calculate(30);
$c->setOperation(new Multiplier());
$c->calculate(5);
$c->setOperation(new Divider());
$c->calculate(2);
echo $c->getResult();
示例7: exit
<?php
/**
* Created by PhpStorm.
* User: theki
* Date: 13.09.14
* Time: 14:35
*/
require_once 'Calculator.php';
if ($argc < 2) {
exit('Usage: php calc.php [formula]' . PHP_EOL);
}
$calculator = new Calculator($argv[1]);
echo $calculator->calculate() . PHP_EOL;
示例8: getPrice
public function getPrice($variant, $quantity = 1, $group_id = '', $date = '')
{
//let us take the basic price
if (!$variant) {
return false;
}
$pricing_calculator = isset($variant->pricing_calculator) ? $variant->pricing_calculator : 'standard';
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/calculators/calculator.php';
$config = array();
$config['variant'] = $variant;
$config['quantity'] = $quantity;
$config['group_id'] = $group_id;
$config['date'] = $date;
$calculator = new Calculator($pricing_calculator, $config);
$pricing = $calculator->calculate();
J2Store::plugin()->event('AfterGetPrice', array(&$pricing, $variant, $quantity, $group_id, $date));
return $pricing;
}
示例9: Calculator
<?php
require_once 'init.php';
$c = new Calculator();
$c->setOperation(new Adder());
$c->calculate(10, 50);
$c->setOperation(new Subtractor());
$c->calculate(30);
$c->setOperation(new Divider());
$c->calculate(10);
$c->setOperation(new Multiplier());
$c->calculate(1000);
echo $c->getResult();
示例10: Calculator
<?php
require 'class/operatorInterface.php';
require 'class/Calculator.php';
require 'class/Adder.php';
$calcObj = new Calculator();
$calcObj->setOperation(new Adder());
$calcObj->calculate(1, 2, 3, 4, 5);
echo $calcObj->getResult();
示例11: Calculator
<?php
//require_once 'classes/calculator.php';
//require_once 'classes/operatorInterface.php';
//require_once 'classes/adder.php';
//require_once 'classes/subtractor.php';
//require_once 'classes/multiplier.php';
//require_once 'classes/divider.php';
require_once 'init.php';
$calc = new Calculator();
$calc->setOperation(new Adder());
$calc->calculate(50, 50);
//100
$calc->setOperation(new Subtractor());
$calc->calculate(30);
//70
$calc->setOperation(new Multiplier());
$calc->calculate(3);
//210
$calc->setOperation(new Divider());
$calc->calculate(2);
//105
echo $calc->getResult();
示例12: testCalculate
/**
* Test for calculate.
*
* @dataProvider calculateProvider
*/
public function testCalculate($subject, $omocodiaLevel, $expectedCodiceFiscale)
{
$calculator = new Calculator($subject, array('omocodiaLevel' => $omocodiaLevel));
$actual = $calculator->calculate();
$this->assertEquals($expectedCodiceFiscale, $actual);
}
示例13: calculate
protected $operator = '^';
/**
* Object method to raise one number to the power of another
*
* @var double $a The first operand
* @var double $b The second operand
* @return double The product
*/
public function calculate($a, $b)
{
return pow($a, $b);
}
}
$calc = new Calculator([new AbsoluteValue(), new NaturalLog(), new Exponent(), new Multiply(), new Divide(), new Modulus(), new Add(), new Subtract()]);
// printLn($calc->calculate('---2'), 'should be -2');
printLn($calc->calculate('|-2|'), 'should be 2');
printLn($calc->calculate('ln 2'), 'should be approximately 0.6931471805599453');
printLn($calc->calculate('4 ^ 2'), 'should be 16');
printLn($calc->calculate('4 + 1'), 'should be 5');
printLn($calc->calculate('4 - 3'), 'should be 1');
printLn($calc->calculate('3 * 2'), 'should be 6');
printLn($calc->calculate('5 / 2'), 'should be 2.5');
printLn($calc->calculate('5 % 2'), 'should be 1');
printLn($calc->calculate('4 + -1'), 'should be 3');
printLn($calc->calculate('4 - -3'), 'should be 7');
printLn($calc->calculate('-3 * 2'), 'should be -6');
printLn($calc->calculate('+5 / -2'), 'should be -2.5');
printLn($calc->calculate('5 % -2'), 'should be -1');
printLn($calc->calculate('4 + 5 / 2'), 'should be 6.5');
printLn($calc->calculate('4 - 5 * 2'), 'should be -6');
printLn($calc->calculate('1 + 11 - 2 * 3 / 4'), 'should be 10.5');
示例14: Calculator
<?php
require_once '/vendor/autoload.php';
$multi = new Calculator();
$multi->setOperation(new Multiplication());
$multi->setOperands(3, 5);
$multi->calculate();
var_dump($multi->getResult());
$add = new Calculator();
$add->setOperation(new Addition());
$add->setOperands(12, 14);
$add->calculate();
var_dump($add->getResult());
$subtract = new Calculator();
$subtract->setOperation(new Subtraction());
$subtract->setOperands(15, 6);
$subtract->calculate();
var_dump($subtract->getResult());