本文整理汇总了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));
}
示例2: calculate
function calculate($problem)
{
$operationFactory = new OperationFactory();
$parser = new ProblemParser($operationFactory);
$calculator = new Calculator($parser);
return $calculator->calculate($problem);
}
示例3: testAddWithMultipleArgsAndLineBreaks
public function testAddWithMultipleArgsAndLineBreaks()
{
$calc = new Calculator();
$expected = 6;
$value = $calc->add("1\n2,3");
$this->assertEqual($expected, $value);
}
示例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);
}
示例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
}
示例6: shouldThrowExceptionForDivisionByZero
/**
* @test
* @expectedException InvalidArgumentException
*/
public function shouldThrowExceptionForDivisionByZero()
{
// given
$calculator = new \Calculator();
// when
$calculator->divide(10, 0);
// then
$this->fail('exception should be thrown');
}
示例7: shouldDivideTwoNumbers
/**
* @test
*/
public function shouldDivideTwoNumbers()
{
// given
$calculator = new \Calculator();
// when
$result = $calculator->divide(10, 5);
// then
$this->assertEquals(2, $result);
}
示例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);
}
示例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));
}
示例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);
}
示例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());
}
示例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());
}
示例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.');
}
}
}
示例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);
}
}
示例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;
}