/** * @param array $map * @param array $position * @param array $actions * @param array $expected * * @dataProvider validNavigateDataProvider */ public function test_navigate_with_valid_itinerary(array $map, array $position, array $actions, array $expected) { list($x, $y) = $map; $this->instance->map($x, $y); list($x, $y, $d) = $position; $this->instance->initialPosition($x, $y, $d); $this->instance->navigate($actions); list($x, $y, $d) = $expected; $this->assertEquals(array('x' => $x, 'y' => $y), $this->instance->getCurrentPosition()); $this->assertEquals($d, $this->instance->getCurrentDirection()); }
USAGE; exit($errorMessage ? 1 : 0); } /* * Start script execution */ if ($argc !== 2 || !file_exists($argv[1])) { sendRover_echoUsage('parameters missing or invalid'); } $config = (require $argv[1]); if (!sendRover_validateConfig($config)) { sendRover_echoUsage('Config is not valid'); } list($mapX, $mapY) = $config['map']; $i = 1; foreach ($config['rovers'] as $roverConfig) { $rover = new Rover(); try { $rover->map($mapX, $mapY); list($x, $y, $direction) = $roverConfig['start']; $rover->initialPosition($x, $y, $direction); $actions = strlen($roverConfig['actions']) ? str_split($roverConfig['actions']) : array(); $rover->navigate($actions); $finalPosition = $rover->getCurrentPosition(); $direction = $rover->getCurrentDirection(); echo "Rover #{$i} is at: ({$finalPosition['x']}, {$finalPosition['y']}) {$direction}\n"; } catch (\InvalidArgumentException $e) { echo "Houston, we have a problem, Rover #{$i} got lost into space\n"; } $i++; }