当前位置: 首页>>代码示例>>PHP>>正文


PHP Calculator::calculate方法代码示例

本文整理汇总了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);
}
开发者ID:karptonite,项目名称:exercism-exercises,代码行数:7,代码来源:wordy.php

示例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());
 }
开发者ID:piiskop,项目名称:pstk,代码行数:7,代码来源:controller.php

示例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);
 }
开发者ID:davidepastore,项目名称:codice-fiscale,代码行数:15,代码来源:Checker.php

示例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));
 }
开发者ID:hafeez3000,项目名称:lichess,代码行数:11,代码来源:CalculatorTest.php

示例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());
 }
开发者ID:theki,项目名称:Calculator,代码行数:13,代码来源:CalculatorTest.php

示例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();
开发者ID:aaron1986,项目名称:TestGitHub,代码行数:13,代码来源:index.php

示例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;
开发者ID:theki,项目名称:Calculator,代码行数:14,代码来源:calc.php

示例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;
 }
开发者ID:afend,项目名称:RULug,代码行数:18,代码来源:product.php

示例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();
开发者ID:Makiss,项目名称:Calculator-PHP-,代码行数:13,代码来源:index.php

示例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();
开发者ID:rahulpr,项目名称:_rpr,代码行数:9,代码来源:index.php

示例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();
开发者ID:Addeuz,项目名称:calculator,代码行数:23,代码来源:index.php

示例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);
 }
开发者ID:davidepastore,项目名称:codice-fiscale,代码行数:11,代码来源:CalculatorTest.php

示例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');
开发者ID:webbower,项目名称:sparkcentral-challenge,代码行数:31,代码来源:calc.php

示例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());
开发者ID:LoveAndHappiness,项目名称:php_oop_calculator,代码行数:18,代码来源:index.php


注:本文中的Calculator::calculate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。