Mathematics
Algorithms
Logic
Numbers
function calcTokenCost($price, $token){ if ($price == 0 && $token == 0){ return 0; } if ($price < $token){ return $token; } if (fmod($price, $token) < ($token / 2)){ return $price - fmod($price, $token); } return $price + $token - fmod($price, $token); }
function calcTokenCost($price, $token) {- function calcTokenCost($price, $token){
- if ($price == 0 && $token == 0){
- return 0;
- }
- if ($price < $token){
- return $token;
- }
- if (fmod($price, $token) < ($token / 2)){
- return $price - fmod($price, $token);
- }
- return $price + $token - fmod($price, $token);
- }
// PHPUnit Test Examples: // TODO: Replace examples and use TDD development by writing your own tests class MyTestCases extends TestCase { // test function names should start with "test" public function testThatSomethingShouldHappen() { $this->assertEquals(20, calcTokenCost(19.99, 5)); $this->assertEquals(15, calcTokenCost(17.30, 5)); $this->assertEquals(5, calcTokenCost(0.01, 5)); $this->assertEquals(5, calcTokenCost(0, 5)); $this->assertEquals(0, calcTokenCost(0, 0)); } }
- // PHPUnit Test Examples:
- // TODO: Replace examples and use TDD development by writing your own tests
- class MyTestCases extends TestCase
- {
- // test function names should start with "test"
- public function testThatSomethingShouldHappen() {
- $this->assertEquals(20, calcTokenCost(19.99, 5));
- $this->assertEquals(15, calcTokenCost(17.30, 5));
- $this->assertEquals(5, calcTokenCost(0.01, 5));
- $this->assertEquals(5, calcTokenCost(0, 5));
- $this->assertEquals(0, calcTokenCost(0, 0));
- }
- }