diff --git a/clock/clock_test.php b/clock/clock_test.php new file mode 100644 index 00000000..678093d0 --- /dev/null +++ b/clock/clock_test.php @@ -0,0 +1,113 @@ +assertEquals('08:00', $clock->__toString()); + } + + public function testPastTheHour() + { + $this->markTestSkipped(); + + $clock = new Clock(11, 9); + + $this->assertEquals('11:09', $clock->__toString()); + } + + public function testAddingAFewMinutes() + { + $this->markTestSkipped(); + + $clock = new Clock(10); + + $clock = $clock->add(3); + + $this->assertEquals('10:03', $clock->__toString()); + } + + public function testAddingOverAnHour() + { + $this->markTestSkipped(); + + $clock = new Clock(10); + + $clock = $clock->add(61); + + $this->assertEquals('11:01', $clock->__toString()); + } + + public function testWrapAroundAtMidnight() + { + $this->markTestSkipped(); + + $clock = new Clock(23, 30); + + $clock = $clock->add(60); + + $this->assertEquals('00:30', $clock->__toString()); + } + + public function testSubtractMinutes() + { + $this->markTestSkipped(); + + $clock = new Clock(10); + + $clock = $clock->sub(90); + + $this->assertEquals('08:30', $clock->__toString()); + } + + public function testWrapAroundBackwards() + { + $this->markTestSkipped(); + + $clock = new Clock(0, 30); + + $clock = $clock->sub(60); + + $this->assertEquals('23:30', $clock->__toString()); + } + + public function testWrapAroundDay() + { + $this->markTestSkipped(); + + $clock = new Clock(5, 32); + + $clock = $clock->add(25 * 60); + + $this->assertEquals('06:32', $clock->__toString()); + } + + public function testWrapAroundDayBackwards() + { + $this->markTestSkipped(); + + $clock = new Clock(5, 32); + + $clock = $clock->sub(25 * 60); + + $this->assertEquals('04:32', $clock->__toString()); + } + + public function testEquivalentClocks() + { + $this->markTestSkipped(); + + $this->assertEquals(new Clock(15, 37), new Clock(15, 37)); + } + + public function testInequivalentClocks() + { + $this->markTestSkipped(); + + $this->assertNotEquals(new Clock(01, 01), new Clock(18, 32)); + } +} diff --git a/clock/example.php b/clock/example.php new file mode 100644 index 00000000..720510e7 --- /dev/null +++ b/clock/example.php @@ -0,0 +1,61 @@ +minutes = $hour * 60 + $minutes; + } + + /** + * Returns a new Clock incremented by $minutes + * + * @param int $minutes + * @return Clock + */ + public function add($minutes) + { + return $this->build($this->minutes + $minutes); + } + + /** + * Returns a new Clock deincremented by $minutes + * + * @param int $minutes + * @return Clock + */ + public function sub($minutes) + { + return $this->build($this->minutes - $minutes); + } + + /** + * Returns the string representation of the receiver + * + * @return string + */ + public function __toString() + { + return sprintf('%02d:%02d', $this->minutes / 60, $this->minutes % 60); + } + + /** + * @param $minutes + * @return Clock + */ + private function build($minutes) + { + if ($minutes < 60) { + $minutes += 24 * 60; + } + + $hour = floor($minutes / 60); + return new Clock($hour < 24 ? $hour : $hour - 24, $minutes % 60); + } +} diff --git a/config.json b/config.json index 516dbedb..054f4b3b 100644 --- a/config.json +++ b/config.json @@ -5,7 +5,8 @@ "active": false, "problems": [ "trinary", - "wordy" + "wordy", + "clock" ], "deprecated": [