當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。