From aadbbb704451e65b21d8f1c40670941863f764fd Mon Sep 17 00:00:00 2001 From: Huw Jones Date: Sat, 26 Oct 2019 19:40:43 +0100 Subject: [PATCH] FIx time conversion into seconds/hundredths --- composer.json | 5 ++++ src/Time.php | 4 +-- tests/TimeTest.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/TimeTest.php diff --git a/composer.json b/composer.json index 735e59b..5ef4488 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,11 @@ "RankingsDB\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "RankingsDB\\Tests\\": "tests/" + } + }, "require": { "php": ">=5.5", "ext-soap": "*" diff --git a/src/Time.php b/src/Time.php index f0b3850..effbcbb 100644 --- a/src/Time.php +++ b/src/Time.php @@ -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; } /** @@ -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() diff --git a/tests/TimeTest.php b/tests/TimeTest.php new file mode 100644 index 0000000..1b3b239 --- /dev/null +++ b/tests/TimeTest.php @@ -0,0 +1,72 @@ +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)); + } +}