<?php class calc { /** * . * * @var Double */ protected $last; /** * . * * @param Double $a * @param Double $b * @assert (1,2) == 3 * @assert (10,10) == 20 * @assert (1,0) == 1 * @assert (0,0) == 0 */ public function sum($a, $b) { $this->last = $a+$b; return $this->getLast(); } /** * $a $b * * @param Double $a * @param Double $b * @return Double * @assert (6,3) == 2 * @assert (10,5) == 2 * @assert (15,3) == 5 * @assert (15,0) == 0 */ public function div($a,$b) { if ( $b==0) throw new Exception("Division by zero"); $this->last = $a/$b; return $this->getLast(); } /** * * * @return Double */ public function getLast() { return $this->last; } /** * * * @param double $a * @param double $b * @return double * @assert (1,2) == -1 * @assert (10,2) == 8 * @assert (15,2) == 13 * */ public function minus($a, $b) { $this->last = $a-$b; if($a<$b) $this->last=0; // (!!) return $this->getLast(); } /** * * @param double $a * @param double $b * @return double * @assert (10,20) == 200 * @assert (1,20) == 20 * @assert (4,-3) == -12 * @assert (10,0) == 0 */ public function umnojenie($a,$b) { $this->last = $a*$b; if( $this->last == 0 ) $this->last=1; // return $this->getLast(); } /** * * * @param double $a * @param double $b * @assert (1,2) == 1 * @assert (3,2) == 9 * @assert (10,-1) == 0.1 * @assert (10,0) == 1 * @assert (0,0) == 0 */ public function power($a, $b) { $this->last = pow($a,$b); } } ?>
public function power($a, $b) { $this->last = pow($a,$b); return $this->getLast(); }
/** * Generated from @assert (15,0) == 0. * @expectedException Exception */ public function testDiv4() { $this->assertEquals( 0, $this->object->div(15,0) ); }
/** * * * @param double $a * @param double $b * @return double * @assert (1,2) == -1 * @assert (10,2) == 8 * @assert (15,2) == 13 * */ public function minus($a, $b) { $this->last = $a-$b; return $this->getLast(); } /** * * @param double $a * @param double $b * @return double * @assert (10,20) == 200 * @assert (1,20) == 20 * @assert (4,-3) == -12 * @assert (10,0) == 0 */ public function umnojenie($a,$b) { $this->last = $a*$b; return $this->getLast(); }
public function testClass() { $this->assertEquals(30, $this->object->sum( $this->object->umnojenie(5, 5), 5)); }
Source: https://habr.com/ru/post/70046/
All Articles