Implement Map.isValidPosition

master
Peter Babič 8 years ago
parent 285fb1a27b
commit 2e54430432
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 144
      .idea/workspace.xml
  2. 47
      src/Coffee/Map.php
  3. 6
      src/Coffee/Table.php
  4. 21
      tests/MapTest.php
  5. 8
      tests/TableTest.php

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Refactor Spot constructor to ac">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Refactor Table constructor to accept arguments">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.php" afterPath="$PROJECT_DIR$/index.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Map.php" afterPath="$PROJECT_DIR$/src/Coffee/Map.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Table.php" afterPath="$PROJECT_DIR$/src/Coffee/Table.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/MapTest.php" afterPath="$PROJECT_DIR$/tests/MapTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/TableTest.php" afterPath="$PROJECT_DIR$/tests/TableTest.php" />
@ -35,8 +35,8 @@
<file leaf-file-name="index.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.0">
<caret line="21" column="37" selection-start-line="21" selection-start-column="37" selection-end-line="21" selection-end-column="37" />
<state vertical-scroll-proportion="-4.0">
<caret line="6" column="5" selection-start-line="6" selection-start-column="5" selection-end-line="6" selection-end-column="5" />
<folding />
</state>
</provider>
@ -45,18 +45,18 @@
<file leaf-file-name="Table.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.333333">
<caret line="29" column="0" selection-start-line="29" selection-start-column="0" selection-end-line="37" selection-end-column="9" />
<state vertical-scroll-proportion="-0.6666667">
<caret line="1" column="0" selection-start-line="1" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="TableTest.php" pinned="false" current-in-tab="true">
<file leaf-file-name="TableTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.3802817">
<caret line="24" column="0" selection-start-line="24" selection-start-column="2" selection-end-line="27" selection-end-column="10" />
<state vertical-scroll-proportion="-6.6666665">
<caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding />
</state>
</provider>
@ -65,7 +65,7 @@
<file leaf-file-name="Tile.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-41.703705">
<state vertical-scroll-proportion="-60.0">
<caret line="124" column="55" selection-start-line="124" selection-start-column="55" selection-end-line="124" selection-end-column="55" />
<folding />
</state>
@ -75,7 +75,7 @@
<file leaf-file-name="TileTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-32.37037">
<state vertical-scroll-proportion="-28.777779">
<caret line="106" column="27" selection-start-line="106" selection-start-column="27" selection-end-line="106" selection-end-column="27" />
<folding />
</state>
@ -85,18 +85,18 @@
<file leaf-file-name="Map.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-22.37037">
<caret line="127" column="5" selection-start-line="127" selection-start-column="5" selection-end-line="127" selection-end-column="5" />
<state vertical-scroll-proportion="-3.7037036">
<caret line="78" column="31" selection-start-line="78" selection-start-column="31" selection-end-line="78" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="false">
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/tests/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.703704">
<caret line="44" column="0" selection-start-line="44" selection-start-column="0" selection-end-line="44" selection-end-column="0" />
<state vertical-scroll-proportion="1.887324">
<caret line="71" column="10" selection-start-line="71" selection-start-column="10" selection-end-line="71" selection-end-column="10" />
<folding />
</state>
</provider>
@ -105,8 +105,8 @@
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.037037">
<caret line="33" column="0" selection-start-line="33" selection-start-column="0" selection-end-line="41" selection-end-column="9" />
<state vertical-scroll-proportion="-14.0">
<caret line="26" column="0" selection-start-line="26" selection-start-column="0" selection-end-line="26" selection-end-column="0" />
<folding />
</state>
</provider>
@ -115,8 +115,8 @@
<file leaf-file-name="SpotTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-11.333333">
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
<state vertical-scroll-proportion="-2.0">
<caret line="3" column="0" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<folding />
</state>
</provider>
@ -153,16 +153,16 @@
<option value="$PROJECT_DIR$/composer.json" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="/usr/share/nginx/html/coffeetable/tests/TableTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/tests/TileTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.php" />
<option value="$PROJECT_DIR$/tests/SpotTest.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/tests/MapTest.php" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/tests/TableTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/tests/MapTest.php" />
</list>
</option>
</component>
@ -550,38 +550,44 @@
<option name="project" value="LOCAL" />
<updated>1458202504523</updated>
</task>
<option name="localTasksCounter" value="9" />
<task id="LOCAL-00009" summary="Refactor Table constructor to accept arguments">
<created>1458204604411</created>
<option name="number" value="00009" />
<option name="project" value="LOCAL" />
<updated>1458204604411</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers />
</component>
<component name="TestHistory">
<history-entry file="Tests - 2016.03.17 at 09h 11m 56s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 20m 26s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 12m 12s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 45m 27s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 12m 39s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 46m 35s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 12m 51s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 48m 35s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 20m 26s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 48m 41s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 45m 27s.xml">
<history-entry file="Tests - 2016.03.17 at 09h 49m 48s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 46m 35s.xml">
<history-entry file="Tests - 2016.03.17 at 10h 27m 41s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 48m 35s.xml">
<history-entry file="Tests - 2016.03.17 at 10h 42m 45s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 48m 41s.xml">
<history-entry file="Tests - 2016.03.17 at 10h 43m 07s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.17 at 09h 49m 48s.xml">
<history-entry file="Tests - 2016.03.17 at 10h 43m 18s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
@ -595,7 +601,7 @@
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.40149626" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.19375" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.19375" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
@ -653,18 +659,12 @@
<MESSAGE value="Introduce index.php and require autoload.php in tests" />
<MESSAGE value="Implement Tile.getNeighbors" />
<MESSAGE value="Refactor Tile constructor to accept parameters&#10;" />
<option name="LAST_COMMIT_MESSAGE" value="Refactor Tile constructor to accept parameters&#10;" />
<MESSAGE value="Refactor Table constructor to accept arguments" />
<option name="LAST_COMMIT_MESSAGE" value="Refactor Table constructor to accept arguments" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="php">
<url>file://$PROJECT_DIR$/src/Coffee/Map.php</url>
<line>77</line>
<option name="timeStamp" value="18" />
</line-breakpoint>
</breakpoints>
<option name="time" value="19" />
</breakpoint-manager>
<watches-manager>
@ -983,82 +983,82 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-22.37037">
<caret line="127" column="5" selection-start-line="127" selection-start-column="5" selection-end-line="127" selection-end-column="5" />
<state vertical-scroll-proportion="0.3319838">
<caret line="35" column="0" selection-start-line="35" selection-start-column="0" selection-end-line="35" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/MapTest.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.703704">
<caret line="44" column="0" selection-start-line="44" selection-start-column="0" selection-end-line="44" selection-end-column="0" />
<state vertical-scroll-proportion="-60.0">
<caret line="124" column="55" selection-start-line="124" selection-start-column="55" selection-end-line="124" selection-end-column="55" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-41.703705">
<caret line="124" column="55" selection-start-line="124" selection-start-column="55" selection-end-line="124" selection-end-column="55" />
<state vertical-scroll-proportion="-2.0">
<caret line="3" column="0" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/TileTest.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-32.37037">
<caret line="106" column="27" selection-start-line="106" selection-start-column="27" selection-end-line="106" selection-end-column="27" />
<state vertical-scroll-proportion="-14.0">
<caret line="26" column="0" selection-start-line="26" selection-start-column="0" selection-end-line="26" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<entry file="file://$PROJECT_DIR$/tests/TileTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.037037">
<caret line="33" column="0" selection-start-line="33" selection-start-column="0" selection-end-line="41" selection-end-column="9" />
<state vertical-scroll-proportion="-28.777779">
<caret line="106" column="27" selection-start-line="106" selection-start-column="27" selection-end-line="106" selection-end-column="27" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.php">
<entry file="file://$PROJECT_DIR$/tests/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.3319838">
<caret line="35" column="0" selection-start-line="35" selection-start-column="0" selection-end-line="35" selection-end-column="0" />
<state vertical-scroll-proportion="-6.6666665">
<caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-14.0">
<caret line="21" column="37" selection-start-line="21" selection-start-column="37" selection-end-line="21" selection-end-column="37" />
<state vertical-scroll-proportion="-0.6666667">
<caret line="1" column="0" selection-start-line="1" selection-start-column="0" selection-end-line="1" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/SpotTest.php">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-11.333333">
<caret line="17" column="0" selection-start-line="17" selection-start-column="0" selection-end-line="17" selection-end-column="0" />
<state vertical-scroll-proportion="-4.0">
<caret line="6" column="5" selection-start-line="6" selection-start-column="5" selection-end-line="6" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.333333">
<caret line="29" column="0" selection-start-line="29" selection-start-column="0" selection-end-line="37" selection-end-column="9" />
<state vertical-scroll-proportion="-3.7037036">
<caret line="78" column="31" selection-start-line="78" selection-start-column="31" selection-end-line="78" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/TableTest.php">
<entry file="file://$PROJECT_DIR$/tests/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.3802817">
<caret line="24" column="0" selection-start-line="24" selection-start-column="2" selection-end-line="27" selection-end-column="10" />
<state vertical-scroll-proportion="1.887324">
<caret line="71" column="10" selection-start-line="71" selection-start-column="10" selection-end-line="71" selection-end-column="10" />
<folding />
</state>
</provider>

@ -21,6 +21,8 @@ class Map {
*/
private $description = [];
// private $visited = [];
/**
* @var int
*/
@ -69,20 +71,23 @@ class Map {
return $this->width;
}
// /**
// * @param $row
// * @param $column
// * @return bool
// */
// public function removeFromDescription($row, $column) {
// if (!isset($this->description[$row][$column])) {
//// throw new Exception('Could not remove from description at R: '.$row.', C: '.$column);
// return false;
// }
//
// array_splice($this->description[$row], $column, 1);
// return true;
// }
/**
* @param $row
* @param $column
* @return bool
*/
public function isValidPosition($row, $column) {
if ($row < 0 || $column < 0) {
return false;
}
// Map dimensions start from 1 but row/col positions start from 0, need to compensate
if ($row >= $this->getHeight() || $column >= $this->getWidth()) {
return false;
}
return true;
}
/**
* @param $description
@ -110,21 +115,9 @@ class Map {
return $widestRow;
}
// /**
// * @param Tile $tile
// * @return bool
// */
// public function couldContainTile(Tile $tile) {
// if ($tile->getColumn() < 0 || $tile->getRow() < 0) {
// return false;
// }
// public function visitPosition($row, $column) {
//
// // Dimensions start from 1 but coordinates from 0, need to compensate
// if ($tile->getColumn() > ($this->getWidth() - 1) || $tile->getRow() > ($this->getHeight() - 1)) {
// return false;
// }
//
// return true;
// }
}

@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: delmadord
* Date: 3/16/16
* Time: 7:56 AM
*/
namespace Coffee;

@ -42,8 +42,29 @@ class MapTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(4, $map->getWidth());
}
public function testValidPosition() {
$description = [
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 1]
];
$map = new Map($description);
$this->assertTrue($map->isValidPosition(3, 0));
}
public function testInvalidPosition() {
$description = [
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 1]
];
$map = new Map($description);
$this->assertFalse($map->isValidPosition(3, 4));
}
// public function testTileLiesOnTable() {
// $tableMap = [
// [1, 0],

@ -8,10 +8,6 @@ require __DIR__ . '/../vendor/autoload.php';
class TableTest extends \PHPUnit_Framework_TestCase {
public function testGetSpots() {
// $tableMap = [
// [1, 0],
// [0, 1],
// ];
$tile = new Tile(0, 0);
$spot = new Spot();
@ -22,10 +18,6 @@ class TableTest extends \PHPUnit_Framework_TestCase {
}
public function testSpotsCount() {
// $tableMap = [
// [1, 0],
// [0, 1],
// ];
$tile = new Tile(0, 0);
$spot = new Spot();

Loading…
Cancel
Save