Exemple #1
0
 public function testSum()
 {
     $sum = new Sum(123.0, Sum::CURRENCY_RUB, 1000);
     $this->assertEquals(123.0, $sum->getAmount());
     $this->assertEquals(Sum::CURRENCY_RUB, $sum->getCurrency());
     $this->assertEquals(1000, $sum->getBank());
 }
Exemple #2
0
 public function __construct($node, $parent)
 {
     parent::__construct($node, $parent);
     self::$possible_attributes = array_merge(parent::$possible_attributes, self::$possible_attributes);
     self::$required_attributes = array_merge(parent::$required_attributes, self::$required_attributes);
     self::$possible_children = array_merge(parent::$possible_children, self::$possible_children);
     self::$required_children = array_merge(parent::$required_children, self::$required_children);
 }
Exemple #3
0
 /**
  * Function start
  * 
  * @access public
  * @author Kristine <*****@*****.**>
  * @uses \summa\SumView to build view
  */
 public static function start()
 {
     echo '<pre>';
     var_dump($_GET);
     echo '</pre>';
     require_once dirname(__FILE__) . '/Sum.php';
     $a = isset($_GET['a']) ? $_GET['a'] : 0;
     $b = isset($_GET['b']) ? $_GET['b'] : 0;
     $sum = Sum::calculateSum(array('a' => $a, 'b' => $b));
     require_once dirname(__FILE__) . '/SumView.php';
     \summa\SumView::buildView(array('a' => $a, 'b' => $b, 'sum' => $sum));
 }
Exemple #4
0
 /** @test */
 public function compensateRemovesNumber()
 {
     $sum = new Sum();
     $sum->init();
     $sum->accumulate(4);
     $sum->accumulate(8);
     $sum->compensate(4);
     $this->assertEquals(8, $sum->emit());
 }
Exemple #5
0
				<div class="numbers">
					<form method='post'><input type="submit" name='num' value='1'></form>
					<form method='post'><input type="submit" name='num' value='2'></form>
					<form method='post'><input type="submit" name='num' value='3'></form>
					<form method='post'><input type="submit" name='num' value='4'></form>
					<form method='post'><input type="submit" name='num' value='5'></form>
					<form method='post'><input type="submit" name='num' value='6'></form>
					<form method='post'><input type="submit" name='num' value='7'></form>
					<form method='post'><input type="submit" name='num' value='8'></form>
					<form method='post'><input type="submit" name='num' value='9'></form>
					<form method='post'><input type="submit" name='num' value='0'></form>
					<form method='post'><input type="submit" name='null' value='d' style='visibility: hidden;'></form>
					<form method='post'><input type="submit" name='=' value='='></form>
				</div>
				<div class="operators">
					<form method='post'><input type="submit" name='operator' value='+'></form>
					<form method='post'><input type="submit" name='operator' value='-'></form>
					<form method='post'><input type="submit" name='operator' value='/'></form>
					<form method='post'><input type="submit" name='operator' value='x'></form>
				</div>
        <?php 
if (isset($_POST['='])) {
    $sum = new Sum(12, 3);
    echo "<script>\$('.display span').append('" . $sum->makeSum(12, 3) . "');</script>";
}
?>
			</div>
		</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</html>
 public function testSumTimes()
 {
     $fiveBucks = Money::dollar(5);
     $tenFrancs = Money::franc(10);
     $bank = new Bank();
     $bank->addRate('CHF', 'USD', 2);
     $step1 = new Sum($fiveBucks, $tenFrancs);
     $sum = $step1->times(2);
     $result = $bank->reduce($sum, 'USD');
     $this->assertEquals(Money::dollar(20), $result);
 }
Exemple #7
0
/**
 * A ConcreteClass.
 */
class NonNegativeSubtraction extends BinaryOperation
{
    private $_a;
    private $_b;
    public function __construct($a = 0, $b = 0)
    {
        $this->_a = $a;
        $this->_b = $b;
    }
    protected function _getFirstNumber()
    {
        return $this->_a;
    }
    protected function _getSecondNumber()
    {
        return min($this->_a, $this->_b);
    }
    protected function _operator($a, $b)
    {
        return $a - $b;
    }
}
$sum = new Sum(84, 56);
//140
echo $sum->getOperationResult(), "\n";
$nonNegativeSubtraction = new NonNegativeSubtraction(9, 14);
//0
echo $nonNegativeSubtraction->getOperationResult();
Exemple #8
0
    {
        $this->value += $inc;
    }
    public function getValue()
    {
        return $this->value;
    }
    public function run()
    {
    }
}
class MyThread extends Thread
{
    public $sum;
    public function __construct(Sum $sum)
    {
        $this->sum = $sum;
    }
    public function run()
    {
        for ($i = 0; $i < 10; $i++) {
            $this->sum->add(5);
            echo $this->sum->getValue() . " ";
        }
    }
}
$sum = new Sum();
$thread = new MyThread($sum);
$thread->start();
$thread->join();
echo $sum->getValue();