Skip to content

Commit

Permalink
FIx time conversion into seconds/hundredths
Browse files Browse the repository at this point in the history
  • Loading branch information
huwcbjones authored Oct 26, 2019
1 parent 0d15184 commit aadbbb7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"RankingsDB\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"RankingsDB\\Tests\\": "tests/"
}
},
"require": {
"php": ">=5.5",
"ext-soap": "*"
Expand Down
4 changes: 2 additions & 2 deletions src/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function event()
*/
public function getTimeInSeconds()
{
return $this->_seconds * 60 + $this->_seconds + $this->_hundredths / 100;
return $this->_minutes * 60 + $this->_seconds + $this->_hundredths / 100;
}

/**
Expand All @@ -85,7 +85,7 @@ public function getTimeInSeconds()
*/
public function getTimeInHundredths()
{
return 100 * ($this->_seconds * 60 + $this->_seconds) + $this->_hundredths;
return 100 * ($this->_minutes * 60 + $this->_seconds) + $this->_hundredths;
}

public function __toString()
Expand Down
72 changes: 72 additions & 0 deletions tests/TimeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Author: huw
* Since: 2019-10-26
*/

namespace RankingsDB\Tests;

use PHPUnit\Framework\TestCase;
use RankingsDB\Event;
use RankingsDB\Stroke;
use RankingsDB\Time;

class TimeTest extends TestCase
{

public function testGetTimeInSecondsHundredths()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "000012");
$this->assertEquals(0.12, $time->getTimeInSeconds());
}

public function testGetTimeInSecondsSeconds()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "001234");
$this->assertEquals(12.34, $time->getTimeInSeconds());
}

public function testGetTimeInSecondsMinutes()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "123456");
$this->assertEquals(754.56, $time->getTimeInSeconds());
}

public function testGetTimeInHundredthsHundredths()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "000012");
$this->assertEquals(12, $time->getTimeInHundredths());
}

public function testGetTimeInHundredthsSeconds()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "001234");
$this->assertEquals(1234, $time->getTimeInHundredths());
}

public function testGetTimeInHundredthssMinutes()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "123456");
$this->assertEquals(75456, $time->getTimeInHundredths());
}

public function testGetTimeNoLeadingZeroes()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "003456");
$this->assertEquals("34.56", $time->getTime(false));
}

public function testGetTimeWithLeadingZeroes()
{
$event = new Event(Stroke::FREESTYLE, 50);
$time = new Time($event, "003456");
$this->assertEquals("0:34.56", $time->getTime(true));
}
}

0 comments on commit aadbbb7

Please sign in to comment.