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


PHP Calculator类代码示例

本文整理汇总了PHP中Calculator的典型用法代码示例。如果您正苦于以下问题:PHP Calculator类的具体用法?PHP Calculator怎么用?PHP Calculator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Calculator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAdd

 public function testAdd()
 {
     require 'Calculator.php';
     $Controller = new Calculator();
     $expected = 5;
     $this->assertEquals($expected, $Controller->add(3, 2));
 }
开发者ID:Juli55,项目名称:mvc-framework,代码行数:7,代码来源:testCalculator.php

示例2: 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

示例3: testAddWithMultipleArgsAndLineBreaks

 public function testAddWithMultipleArgsAndLineBreaks()
 {
     $calc = new Calculator();
     $expected = 6;
     $value = $calc->add("1\n2,3");
     $this->assertEqual($expected, $value);
 }
开发者ID:remosu,项目名称:Enero-String-Calculator,代码行数:7,代码来源:testCalculator.php

示例4: testAdd

 public function testAdd()
 {
     $calc = new Calculator();
     $result = $calc->add(30, 12);
     // assert that your calculator added the numbers correctly!
     $this->assertEquals(42, $result);
 }
开发者ID:zouxinjiang,项目名称:baseOfSymfony,代码行数:7,代码来源:CalculatorTest.php

示例5: testDivide

 public function testDivide()
 {
     $calc = new Calculator();
     $quotient = $calc->divide(10, 2);
     $this->assertEquals(5, $quotient);
     //check if 10/2 is equal to 5
 }
开发者ID:sampletestorg1,项目名称:sample_php,代码行数:7,代码来源:calculator_test.php

示例6: shouldThrowExceptionForDivisionByZero

 /**
  * @test
  * @expectedException InvalidArgumentException
  */
 public function shouldThrowExceptionForDivisionByZero()
 {
     // given
     $calculator = new \Calculator();
     // when
     $calculator->divide(10, 0);
     // then
     $this->fail('exception should be thrown');
 }
开发者ID:DevSKiller,项目名称:devskiller-sample-php-calculator,代码行数:13,代码来源:IllegalArgumentsTest.php

示例7: shouldDivideTwoNumbers

 /**
  * @test
  */
 public function shouldDivideTwoNumbers()
 {
     // given
     $calculator = new \Calculator();
     // when
     $result = $calculator->divide(10, 5);
     // then
     $this->assertEquals(2, $result);
 }
开发者ID:DevSKiller,项目名称:devskiller-sample-php-calculator,代码行数:12,代码来源:CalculatorTest.php

示例8: 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

示例9: 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

示例10: shouldDivideTwoNumbers

 /**
  * @test
  */
 public function shouldDivideTwoNumbers()
 {
     // given
     $a = rand(0, 100);
     $b = rand(1, 100);
     $calculator = new \Calculator();
     // when
     $result = $calculator->divide($a, $b);
     // then
     $this->assertEquals(round($a / $b), $result);
 }
开发者ID:DevSKiller,项目名称:devskiller-sample-php-calculator,代码行数:14,代码来源:RandomNumbersTest.php

示例11: 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

示例12: 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

示例13: showSinglestat

 public function showSinglestat($statID)
 {
     if (Auth::check()) {
         return Redirect::route('connect.connect');
     } else {
         try {
             $user = User::find(1);
             Auth::login($user);
             $currentMetrics = Calculator::currentMetrics();
             $metricValues = Metric::where('user', Auth::user()->id)->where('date', '<', Carbon::now())->orderBy('date', 'desc')->take(31)->get();
             foreach ($currentMetrics as $metricID => $statClassName) {
                 if ($metricID == $statID) {
                     $metricsArray = array();
                     foreach ($metricValues as $metric) {
                         $metricsArray[$metric->date] = $metric->{$metricID};
                     }
                     ksort($metricsArray);
                     $allMetrics[$metricID] = $metricsArray;
                 }
             }
             if (isset($currentMetrics[$statID])) {
                 return View::make('demo.single_stat', array('data' => $currentMetrics[$statID]['metricClass']::show($allMetrics[$statID], true), 'metricDetails' => $currentMetrics[$statID], Auth::logout()));
             }
             return Redirect::route('demo.dashboard')->with('error', 'Statistic does not exist.');
         } catch (Exception $e) {
             Auth::logout();
             Log::error($e);
             return Redirect::route('demo.dashboard')->with('error', 'Something went wrong, we will return shortly.');
         }
     }
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:31,代码来源:DemoController.php

示例14: run

 public function run()
 {
     DB::table('events')->delete();
     $currentDay = time();
     $user = User::find(1);
     // days generated before the current date
     $generatedDay = $currentDay - 370 * 24 * 60 * 60;
     // generating data for ~2 years
     for ($i = 0; $i < 750; $i++) {
         // timestamp of the current day
         $dailyTimeStamp = $generatedDay + $i * 24 * 60 * 60;
         $date = date('Y-m-d', $dailyTimeStamp);
         $monthStats = EventSeeder::monthlyStats($dailyTimeStamp);
         $eventTimes = EventSeeder::generateEventTimes($monthStats, $dailyTimeStamp);
         foreach ($eventTimes as $event) {
             $temparray = EventSeeder::getEventType($monthStats, $event);
             if ($temparray) {
                 DB::table('events')->insert(array('user' => $user->id, 'created' => date('Y-m-d H:i:s', $event), 'eventID' => $temparray['id'], 'type' => $temparray['type'], 'object' => $temparray['object'], 'provider' => 'stripe', 'previousAttributes' => $temparray['previousAttributes'], 'date' => date('Y-m-d', $event)));
             }
         }
         // set time to last timestamp +1
         $event++;
         // calculate all
         Calculator::calculateMetrics($user, $event);
     }
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:26,代码来源:EventSeeder.php

示例15: power

 public function power($n, $p)
 {
     $obj = new Calculator();
     if ($n < 0 || $p < 0) {
         throw new Exception("n and p should be non-negative");
     } else {
         if ($p === 0) {
             return 1;
         }
     }
     $ans = $obj->power($n, intval($p / 2));
     $ans *= $ans;
     if ($p % 2 === 1) {
         $ans *= $n;
     }
     return $ans;
 }
开发者ID:vivek-23,项目名称:30-Days-of-Code-on-HackerRank,代码行数:17,代码来源:day_17.php


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