• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Calculator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: runMath

 public function runMath($value)
 {
     $calc = new Calculator();
     $calc->setValue($value[1], $value[3]);
     $result = "";
     if ($value[2] == iCalc::iMathSignalPlus) {
         $result = $calc->getPlus();
     } else {
         if ($value[2] == iCalc::iMathSignalDivi) {
             $result = $calc->getDivide();
         } else {
             if ($value[2] == iCalc::iMathSignalMulti) {
                 $result = $calc->getMultiply();
             } else {
                 if ($value[2] == iCalc::iMathSignalMinus) {
                     $result = $calc->getMinus();
                 } else {
                     if ($value[2] == iCalc::iMathSignalModu) {
                         $result = $calc->getModule();
                     } else {
                         $result = iCalc::iHelpMessage;
                     }
                 }
             }
         }
     }
     return $result;
 }
开发者ID:marcosptf,项目名称:phpCalc,代码行数:28,代码来源:Math.php


示例17: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     Log::info('GetEvents fired');
     // going through the users
     foreach (User::all() as $user) {
         // saving events
         Calculator::saveEvents($user);
     }
     Log::info('GetEvents finished');
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:15,代码来源:GetEvents.php


示例18: fire

 public function fire($job, $data)
 {
     // we only get the user ID, get the user from it
     $user = User::find($data['userID']);
     Calculator::calculateMetricsOnConnect($user);
     Log::info('Sending "ready" email for user: ' . $user->email);
     $email = Mailman::make('emails.connected')->to($user->email)->subject('Your metrics are ready!')->send();
     $user->ready = 'connected';
     $user->save();
     $job->delete();
 }
开发者ID:raschan,项目名称:fruit-dashboard,代码行数:11,代码来源:CalculateFirstTime.php


示例19: calculate

 /**
  * This function calculates the sum of 2 variables
  * @access public
  * @author Eleri<[email protected]>
  * @return number result
  */
 public static function calculate()
 {
     if (isset($_GET['first'])) {
         Calculator::$firstVariable = filter_var($_GET['first'], FILTER_VALIDATE_FLOAT);
     }
     if (isset($_GET['second'])) {
         Calculator::$secondVariable = filter_var($_GET['second'], FILTER_VALIDATE_FLOAT);
     }
     $result = Calculator::$firstVariable + Calculator::$secondVariable;
     return $result;
 }
开发者ID:piiskop,项目名称:pstk,代码行数:17,代码来源:model.php


示例20: test_numbers

 public function test_numbers()
 {
     $a = new Calculator();
     $this->assertEquals(0, $a->Add(""));
     $this->assertEquals(2, $a->Add("2"));
     $this->assertEquals(5, $a->Add("2,3"));
     $this->assertEquals(30, $a->Add("10,2,3,15"));
     $this->assertEquals(30, $a->Add("10,2\n3,15"));
     $this->assertEquals(30, $a->Add("//[;;;]\n10;;;20"));
 }
开发者ID:antkahn,项目名称:CalculTest,代码行数:10,代码来源:CalculTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Calendar类代码示例发布时间:2022-05-20
下一篇:
PHP CakeTime类代码示例发布时间:2022-05-20
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap