Implement recursive algorithm to find Spots

master
Peter Babič 8 years ago
parent d76f5f230b
commit 72b4370c40
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 241
      .idea/workspace.xml
  2. 44
      index.php
  3. 49
      src/Coffee/Map.php
  4. 7
      src/Coffee/Spot.php
  5. 111
      src/Coffee/Table.php
  6. 91
      tests/Coffee/TableTest.php

@ -4,23 +4,10 @@
<option name="ANALYZE_TEST_SOURCES" value="false" />
</component>
<component name="ChangeListManager">
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Rework Table constructor">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/coffeetable.iml" afterPath="$PROJECT_DIR$/.idea/coffeetable.iml" />
<list default="true" id="65f95bb6-3a86-4ed6-841e-441936291ad4" name="Default" comment="Implement recursive algoritm to find one large spot">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/composer.json" afterPath="$PROJECT_DIR$/composer.json" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/composer.lock" afterPath="$PROJECT_DIR$/composer.lock" />
<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/Position.php" afterPath="$PROJECT_DIR$/src/Coffee/Position.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Spot.php" afterPath="$PROJECT_DIR$/src/Coffee/Spot.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Table.php" afterPath="$PROJECT_DIR$/src/Coffee/Table.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/src/Coffee/Tile.php" afterPath="$PROJECT_DIR$/src/Coffee/Tile.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/MapTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/MapTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/PositionTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/PositionTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/SpotTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/SpotTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/index.php" afterPath="$PROJECT_DIR$/index.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/TableTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/TableTest.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/tests/Coffee/TileTest.php" afterPath="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
</list>
<ignored path="coffeetable.iws" />
<ignored path=".idea/workspace.xml" />
@ -46,71 +33,71 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="Table.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<file leaf-file-name="index.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-17.703703">
<caret line="68" column="0" selection-start-line="68" selection-start-column="0" selection-end-line="68" selection-end-column="0" />
<state vertical-scroll-proportion="0.45721924">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Spot.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<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="-12.37037">
<caret line="39" column="7" selection-start-line="39" selection-start-column="7" selection-end-line="39" selection-end-column="7" />
<state vertical-scroll-proportion="-57.703705">
<caret line="91" column="5" selection-start-line="91" selection-start-column="5" selection-end-line="91" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Position.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<file leaf-file-name="TableTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.703704">
<caret line="175" column="23" selection-start-line="175" selection-start-column="23" selection-end-line="175" selection-end-column="23" />
<state vertical-scroll-proportion="6.296296">
<caret line="47" column="56" selection-start-line="47" selection-start-column="56" selection-end-line="47" selection-end-column="56" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Map.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<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="-7.3333335">
<caret line="35" column="7" selection-start-line="35" selection-start-column="7" selection-end-line="35" selection-end-column="7" />
<state vertical-scroll-proportion="-20.0">
<caret line="35" column="19" selection-start-line="35" selection-start-column="19" selection-end-line="35" selection-end-column="19" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<file leaf-file-name="Position.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.28877005">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<state vertical-scroll-proportion="-11.0">
<caret line="175" column="23" selection-start-line="175" selection-start-column="23" selection-end-line="175" selection-end-column="23" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="SpotTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/SpotTest.php">
<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="-0.0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<state vertical-scroll-proportion="-33.037037">
<caret line="147" column="0" selection-start-line="147" selection-start-column="0" selection-end-line="147" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="TableTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<file leaf-file-name="MapTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.6666665">
<caret line="10" column="22" selection-start-line="10" selection-start-column="22" selection-end-line="10" selection-end-column="22" />
<state vertical-scroll-proportion="-8.0">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
@ -119,8 +106,8 @@
<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="-0.6666667">
<caret line="38" column="6" selection-start-line="38" selection-start-column="6" selection-end-line="38" selection-end-column="6" />
<state vertical-scroll-proportion="-48.0">
<caret line="72" column="20" selection-start-line="72" selection-start-column="20" selection-end-line="72" selection-end-column="20" />
<folding />
</state>
</provider>
@ -136,16 +123,6 @@
</provider>
</entry>
</file>
<file leaf-file-name="PositionTest.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tests/Coffee/PositionTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-18.660378">
<caret line="103" column="76" selection-start-line="103" selection-start-column="76" selection-end-line="103" selection-end-column="76" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FrameworkCommandLineHistory">
@ -179,7 +156,6 @@
<option value="$PROJECT_DIR$/tests/Table.php" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="/usr/share/nginx/html/coffeetable/tests/TableTest.php" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/tests/PositionTest.php" />
<option value="$PROJECT_DIR$/tests/MapTest.php" />
<option value="$PROJECT_DIR$/tests/TableTest.php" />
@ -190,18 +166,19 @@
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/src/Coffee/Position.php" />
<option value="/usr/share/nginx/html/coffeetable/src/Coffee/Spot.php" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.php" />
<option value="/usr/share/nginx/html/coffeetable/index.php" />
<option value="$PROJECT_DIR$/src/Coffee/Tile.php" />
<option value="$PROJECT_DIR$/src/Coffee/Table.php" />
<option value="$PROJECT_DIR$/index.php" />
<option value="$PROJECT_DIR$/composer.json" />
<option value="$PROJECT_DIR$/tests/Coffee/PositionTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/tests/Coffee/MapTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/SpotTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TableTest.php" />
<option value="$PROJECT_DIR$/tests/Coffee/TileTest.php" />
<option value="$PROJECT_DIR$/src/Coffee/Map.php" />
<option value="$PROJECT_DIR$/src/Coffee/Spot.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/Coffee/TableTest.php" />
<option value="$PROJECT_DIR$/index.php" />
</list>
</option>
</component>
@ -466,7 +443,7 @@
<property name="options.splitter.main.proportions" value="0.3" />
<property name="options.splitter.details.proportions" value="0.2" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="SearchEverywhereHistoryKey" value="reform&#9;ACTION&#9;ReformatCode&#10;replace in pa&#9;ACTION&#9;ReplaceInPath&#10;hist&#9;ACTION&#9;Vcs.ShowTabbedFileHistory&#10;paste&#9;ACTION&#9;EditorPasteSimple&#10;rear &#9;ACTION&#9;RearrangeCode&#10;histor&#9;ACTION&#9;Vcs.ShowTabbedFileHistory&#10;rep in pa&#9;ACTION&#9;ReplaceInPath&#10;replace in&#9;ACTION&#9;ReplaceInPath&#10;rearr&#9;ACTION&#9;RearrangeCode&#10;rea&#9;ACTION&#9;RearrangeCode&#10;orde&#9;null&#9;null&#10;next hi&#9;ACTION&#9;GotoNextError&#10;next&#9;ACTION&#9;GotoNextError&#10;comm cha&#9;ACTION&#9;ChangesView.Commit&#10;comple&#9;ACTION&#9;CodeCompletionGroup&#10;complet&#9;ACTION&#9;CodeCompletionGroup&#10;sear&#9;ACTION&#9;SearchEverywhere&#10;breakpoint&#9;ACTION&#9;ToggleLineBreakpoint&#10;comm ch&#9;ACTION&#9;ChangesView.Commit&#10;smart&#9;ACTION&#9;SmartTypeCompletion&#10;para&#9;ACTION&#9;IntroduceParameter&#10;keyma&#9;ACTION&#9;ChangeKeymap&#10;commit&#9;ACTION&#9;Vcs.CheckCommitMessageSpelling&#10;commit &#9;ACTION&#9;Vcs.CheckCommitMessageSpelling&#10;phpunit&#9;null&#9;null&#10;exte&#9;ACTION&#9;EditorSelectWord&#10;composer&#9;ACTION&#9;ComposerGroup&#10;test&#9;ACTION&#9;RerunTests&#10;rer&#9;ACTION&#9;RerunTests&#10;tests&#9;ACTION&#9;RerunTests&#10;hpunit&#9;ACTION&#9;PhpUnitGenerateTestMethod&#10;phpuni&#9;ACTION&#9;PhpUnitNewTest&#10;rear&#9;ACTION&#9;RearrangeCode" />
<property name="SearchEverywhereHistoryKey" value="colum&#9;ACTION&#9;EditorToggleColumnMode&#10;reform&#9;ACTION&#9;ReformatCode&#10;replace in pa&#9;ACTION&#9;ReplaceInPath&#10;hist&#9;ACTION&#9;Vcs.ShowTabbedFileHistory&#10;paste&#9;ACTION&#9;EditorPasteSimple&#10;rear &#9;ACTION&#9;RearrangeCode&#10;histor&#9;ACTION&#9;Vcs.ShowTabbedFileHistory&#10;rep in pa&#9;ACTION&#9;ReplaceInPath&#10;replace in&#9;ACTION&#9;ReplaceInPath&#10;rearr&#9;ACTION&#9;RearrangeCode&#10;rea&#9;ACTION&#9;RearrangeCode&#10;orde&#9;null&#9;null&#10;next hi&#9;ACTION&#9;GotoNextError&#10;next&#9;ACTION&#9;GotoNextError&#10;comm cha&#9;ACTION&#9;ChangesView.Commit&#10;comple&#9;ACTION&#9;CodeCompletionGroup&#10;complet&#9;ACTION&#9;CodeCompletionGroup&#10;sear&#9;ACTION&#9;SearchEverywhere&#10;breakpoint&#9;ACTION&#9;ToggleLineBreakpoint&#10;comm ch&#9;ACTION&#9;ChangesView.Commit&#10;smart&#9;ACTION&#9;SmartTypeCompletion&#10;para&#9;ACTION&#9;IntroduceParameter&#10;keyma&#9;ACTION&#9;ChangeKeymap&#10;commit&#9;ACTION&#9;Vcs.CheckCommitMessageSpelling&#10;commit &#9;ACTION&#9;Vcs.CheckCommitMessageSpelling&#10;phpunit&#9;null&#9;null&#10;exte&#9;ACTION&#9;EditorSelectWord&#10;composer&#9;ACTION&#9;ComposerGroup&#10;test&#9;ACTION&#9;RerunTests&#10;rer&#9;ACTION&#9;RerunTests&#10;tests&#9;ACTION&#9;RerunTests&#10;hpunit&#9;ACTION&#9;PhpUnitGenerateTestMethod&#10;phpuni&#9;ACTION&#9;PhpUnitNewTest&#10;rear&#9;ACTION&#9;RearrangeCode" />
<property name="settings.editor.selected.configurable" value="preferences.sourceCode.PHP" />
<property name="settings.editor.splitter.proportion" value="0.2" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../coffeetable_branch" />
@ -495,7 +472,7 @@
<recent name="$PROJECT_DIR$/Tests" />
</key>
</component>
<component name="RunManager" selected="PHP Script.index.php">
<component name="RunManager" selected="PHPUnit.Tests">
<configuration default="false" name="index.php" type="PhpLocalRunConfigurationType" factoryName="PHP Console" temporary="true" path="$PROJECT_DIR$/index.php">
<method />
</configuration>
@ -735,38 +712,50 @@
<option name="project" value="LOCAL" />
<updated>1458293898715</updated>
</task>
<option name="localTasksCounter" value="31" />
<task id="LOCAL-00031" summary="Composer update">
<created>1458296131700</created>
<option name="number" value="00031" />
<option name="project" value="LOCAL" />
<updated>1458296131700</updated>
</task>
<task id="LOCAL-00032" summary="Implement recursive algoritm to find one large spot">
<created>1458304427895</created>
<option name="number" value="00032" />
<option name="project" value="LOCAL" />
<updated>1458304427895</updated>
</task>
<option name="localTasksCounter" value="33" />
<servers />
</component>
<component name="TestHistory">
<history-entry file="Tests - 2016.03.18 at 09h 48m 57s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 37m 41s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 09h 50m 46s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 38m 00s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 10m 56s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 38m 16s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 24m 30s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 38m 20s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 24m 41s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 38m 43s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 24m 51s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 39m 11s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 25m 01s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 39m 40s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 27m 25s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 40m 07s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 27m 31s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 40m 23s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
<history-entry file="Tests - 2016.03.18 at 10h 28m 06s.xml">
<history-entry file="Tests - 2016.03.18 at 13h 42m 32s.xml">
<configuration name="Tests" configurationId="PHPUnitRunConfigurationType" />
</history-entry>
</component>
@ -795,28 +784,6 @@
<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="Ant Build" 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="1" side_tool="false" content_ui="tabs" />
</layout>
<layout-to-restore>
<window_info id="TODO" 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="6" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Messages" 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="Message" 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="0" side_tool="false" content_ui="tabs" />
<window_info id="PHP-CGI Server" 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="9" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" 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="12" side_tool="true" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3990025" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Command Line Tools Console" 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="11" side_tool="false" content_ui="tabs" />
<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="8" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32668328" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" x="0" y="355" width="1446" height="188" />
<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="10" 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.16875" 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="true" show_stripe_button="true" weight="0.32917705" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.24964234" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" 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="1" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3840399" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
</layout-to-restore>
</component>
<component name="UpdateCopyrightCheckinHandler">
<option name="UPDATE_COPYRIGHT" value="true" />
@ -834,8 +801,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="USE_COMMIT_MESSAGE_MARGIN" value="true" />
<MESSAGE value="Refactor coordinates in Tile from X,Y to col,row" />
<MESSAGE value="Refactor Table.isValidFortile to couldContainTile" />
<MESSAGE value="Split Table and Map to the separate classes for decoupling" />
<MESSAGE value="Introduce index.php and require autoload.php in tests" />
<MESSAGE value="Implement Tile.getNeighbors" />
@ -859,23 +824,36 @@
<MESSAGE value="Rework Tile constructor" />
<MESSAGE value="BLA BLA BLA" />
<MESSAGE value="Rework Table constructor" />
<option name="LAST_COMMIT_MESSAGE" value="Rework Table constructor" />
<MESSAGE value="Composer update" />
<MESSAGE value="Implement recursive algoritm to find one large spot" />
<option name="LAST_COMMIT_MESSAGE" value="Implement recursive algoritm to find one large spot" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="true" />
<option name="REARRANGE_BEFORE_PROJECT_COMMIT" value="true" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="php">
<url>file://$PROJECT_DIR$/tests/Coffee/TableTest.php</url>
<line>45</line>
<option name="timeStamp" value="37" />
</line-breakpoint>
</breakpoints>
<breakpoints-dialog>
<breakpoints-dialog />
</breakpoints-dialog>
<option name="time" value="36" />
<option name="time" value="38" />
</breakpoint-manager>
<watches-manager>
<configuration name="PhpLocalRunConfigurationType">
<watch expression="$map-&gt;getUnVisitedTiles()" language="PHP" />
<watch expression="$map-&gt;getNeighboursOfTile($currentTile)" language="PHP" />
</configuration>
<configuration name="PHPUnitRunConfigurationType">
<watch expression="$map-&gt;getUnVisitedTiles()" language="PHP" />
<watch expression="$map-&gt;getNeighboursOfTile($currentTile)" language="PHP" />
</configuration>
</watches-manager>
</component>
<component name="editorHistoryManager">
@ -1012,13 +990,6 @@
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.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>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/phpunit.xml">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.36096257">
@ -1120,14 +1091,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.0">
<caret line="9" column="21" selection-start-line="9" selection-start-column="21" selection-end-line="9" selection-end-column="21" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/composer.json">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.29752067">
@ -1152,10 +1115,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.6666665">
<caret line="10" column="22" selection-start-line="10" selection-start-column="22" selection-end-line="10" selection-end-column="22" />
<state vertical-scroll-proportion="-8.0">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
@ -1168,17 +1131,25 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-48.0">
<caret line="72" column="20" selection-start-line="72" selection-start-column="20" selection-end-line="72" selection-end-column="20" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Map.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.3333335">
<caret line="35" column="7" selection-start-line="35" selection-start-column="7" selection-end-line="35" selection-end-column="7" />
<state vertical-scroll-proportion="-33.037037">
<caret line="147" column="0" selection-start-line="147" selection-start-column="0" selection-end-line="147" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Position.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-9.703704">
<state vertical-scroll-proportion="-11.0">
<caret line="175" column="23" selection-start-line="175" selection-start-column="23" selection-end-line="175" selection-end-column="23" />
<folding />
</state>
@ -1186,32 +1157,40 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Spot.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-12.37037">
<caret line="39" column="7" selection-start-line="39" selection-start-column="7" selection-end-line="39" selection-end-column="7" />
<state vertical-scroll-proportion="-20.0">
<caret line="35" column="19" selection-start-line="35" selection-start-column="19" selection-end-line="35" selection-end-column="19" />
<folding />
</state>
</provider>
</entry>
<entry file="file:///usr/share/nginx/html/coffeetable/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7222222">
<caret line="102" column="26" selection-start-line="102" selection-start-column="26" selection-end-line="102" selection-end-column="26" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Table.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-17.703703">
<caret line="68" column="0" selection-start-line="68" selection-start-column="0" selection-end-line="68" selection-end-column="0" />
<state vertical-scroll-proportion="-57.703705">
<caret line="91" column="5" selection-start-line="91" selection-start-column="5" selection-end-line="91" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Coffee/Tile.php">
<entry file="file://$PROJECT_DIR$/tests/Coffee/TableTest.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-0.6666667">
<caret line="38" column="6" selection-start-line="38" selection-start-column="6" selection-end-line="38" selection-end-column="6" />
<state vertical-scroll-proportion="6.296296">
<caret line="47" column="56" selection-start-line="47" selection-start-column="56" selection-end-line="47" selection-end-column="56" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tests/Coffee/MapTest.php">
<entry file="file://$PROJECT_DIR$/index.php">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.28877005">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<state vertical-scroll-proportion="0.45721924">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<folding />
</state>
</provider>

@ -5,40 +5,20 @@ namespace Coffee;
require __DIR__ . '/vendor/autoload.php';
try {
$map = new Map([
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 1]
]);
$description = [
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 1]
];
$table = new Table($map);
$map = new Map($description);
$table = new Table($map);
var_dump($table->getSpots());
var_dump($table->getSpots());
//
// // Foreach cannot be used, we need re-evaluation
//// while (list(, $currentTile) = each($map->getUnVisitedTiles())) {
//// while (($currentTile = $map->getUnvisitedTile()) == true) {
// while (isset($map->getUnVisitedTiles()[0]) && ($currentTile = $map->getUnVisitedTiles()[0]) == true) {
// $currentTile->visit();
//
// if ($currentTile->isRepresentingSpot()) {
// $spot = new Spot($currentTile->getPosition());
//
// foreach ($map->getNeighboursOfTile($currentTile) as $neighbouringTile) {
// $neighbouringTile->visit();
//
// if ($neighbouringTile->isRepresentingSpot()) {
// $spot->addPosition($neighbouringTile->getPosition());
// }
// }
//
// $table->addSpot($spot);
// }
// }
//
// var_dump($table);
}
catch (\Exception $e) {
echo 'Caught exception: ' . $e->getMessage() . "\n";
echo 'Caught exception: ' . $e->getMessage() . "\n";
}

@ -145,54 +145,5 @@ class Map {
public function getWidth() {
return $this->width;
}
//
// /**
// * @param Position $position
// * @return bool
// */
// public function visitPosition(Position $position) {
// if ($this->hasValidPosition($position)) {
// foreach ($this->tiles as $unVisitedTileIndex => $unVisitedTile) {
// if ($unVisitedTile->isTheSamePosition($position)) {
//
// // Move Tile from one group to another and reorder
// $this->visitedTiles[] = $unVisitedTile;
// array_splice($this->tiles, $unVisitedTileIndex, 1);
//
// return true;
// }
// }
// }
//
// return false;
// }
//
// /**
// * Test the upper bound
// *
// * @param Position $position
// * @return bool
// */
// public function hasValidPosition(Position $position) {
// if ($position->getRow() > $this->getHeight() || $position->getColumn() > $this->getWidth()) {
// return false;
// }
//
// return true;
// }
//
// /**
// * @param $position
// * @return bool
// */
// public function isVisitedPosition(Position $position) {
// foreach ($this->visitedTiles as $visitedTile) {
// if ($visitedTile->isTheSamePosition($position)) {
// return true;
// }
// }
//
// return false;
// }
}

@ -8,11 +8,6 @@
namespace Coffee;
/**
* Class Spot
*
* @package Coffee
*/
/**
* Class Spot
*
@ -31,7 +26,9 @@ class Spot {
* @param Position $position
*/
public function __construct(Position $position) {
// if (!is_null($position)) {
$this->positions[] = $position;
// }
}
/**

@ -2,11 +2,11 @@
namespace Coffee;
/**
* Class Table
*
* @package Coffee
*/
/**
* Class Table
*
* @package Coffee
*/
/**
* Class Table
*
@ -19,33 +19,25 @@ class Table {
*/
private $spots = [];
/**
* @var Map
*/
private $map;
/**
* @var Spot
*/
private $currentSpot = null;
/**
* Table constructor.
*
* @param Map $map
*/
public function __construct(Map $map) {
foreach ($map->getTiles() as $currentTile) {
if (!$currentTile->isVisited()) {
$currentTile->visit();
if ($currentTile->isRepresentingSpot()) {
$spot = new Spot($currentTile->getPosition());
foreach ($map->getNeighboursOfTile($currentTile) as $neighbouringTile) {
$neighbouringTile->visit();
$this->map = $map;
if ($neighbouringTile->isRepresentingSpot()) {
$spot->addPosition($neighbouringTile->getPosition());
}
}
$this->addSpot($spot);
}
}
}
$this->recur();
}
/**
@ -63,16 +55,77 @@ class Table {
}
/**
* @param Spot $spot
* @param Tile|null $tile
*/
protected function recur($tile = null) {
$tiles = $this->getNextTile($tile);
foreach ($tiles as $currentTile) {
if (!$currentTile->isVisited()) {
$currentTile->visit();
if ($currentTile->isRepresentingSpot()) {
$this->updateCurrentSpot($currentTile->getPosition());
// Recursion?
// $tiles = $this->getNextTile($currentTile);
// foreach ($tiles as $neighbouringTile) {
//
// if (!$neighbouringTile->isVisited()) {
// $neighbouringTile->visit();
//
// if ($neighbouringTile->isRepresentingSpot()) {
// $this->updateCurrentSpot($neighbouringTile->getPosition());
// }
//
// }
// }
$this->recur($currentTile);
$this->addCurrentSpot();
}
}
}
}
protected function updateCurrentSpot(Position $position) {
if (is_null($this->currentSpot)) {
$this->currentSpot = new Spot($position);
}
else {
$this->currentSpot->addPosition($position);
}
}
/**
* @return bool
*/
protected function addSpot(Spot $spot) {
if (is_null($spot)) {
protected function addCurrentSpot() {
if (is_null($this->currentSpot)) {
return false;
}
$this->spots[] = $spot;
$this->spots[] = $this->currentSpot;
$this->currentSpot = null;
return true;
}
/**
* @param $tile
* @return Tile[]
*/
private function getNextTile($tile = null) {
if (is_null($tile)) {
$tiles = $this->map->getTiles();
return $tiles;
}
else {
$tiles = $this->map->getNeighboursOfTile($tile);
return $tiles;
}
}
}

@ -7,37 +7,100 @@ require __DIR__ . '/../../vendor/autoload.php';
class TableTest extends \PHPUnit_Framework_TestCase {
//
// public function testGetSpots() {
// $table = new Table();
// $table->addSpot($spot);
// $this->assertEquals([$spot], $table->getSpots());
// }
public function testZeroSpotsCount() {
$description = [
$map = new Map([
[0, 0],
[0, 0],
];
]);
$map = new Map($description);
$table = new Table($map);
$this->assertEquals(0, $table->getSpotsCount());
}
public function testTwoSingleSpotsCount() {
$description = [
$map = new Map([
[0, 1, 0],
[0, 0, 0],
[0, 0, 1],
[1, 0, 0],
[0, 0, 0],
];
[0, 1, 0],
]);
$map = new Map($description);
$table = new Table($map);
$this->assertEquals(2, $table->getSpotsCount());
}
public function testMultipleLargeSpotsCount() {
$map = new Map([
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 1],
[0, 1, 0, 0, 1],
[1, 1, 0, 0, 0],
[1, 0, 0, 1, 1],
[0, 0, 0, 0, 1],
[0, 1, 0, 0, 0],
]);
$table = new Table($map);
$this->assertEquals(4, $table->getSpotsCount());
}
public function testOneSmallSpot() {
$map = new Map([
[0, 1, 1],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
]);
$table = new Table($map);
$spot = new Spot(new Position(1, 2));
$spot->addPosition(new Position(1, 3));
$this->assertEquals([$spot], $table->getSpots());
}
public function testOneLargeSpot() {
$map = new Map([
[0, 1, 1],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
]);
$table = new Table($map);
$spot = new Spot(new Position(1, 2));
$spot->addPosition(new Position(1, 3));
$spot->addPosition(new Position(2, 3));
$spot->addPosition(new Position(3, 2));
$spot->addPosition(new Position(4, 1));
$this->assertEquals([$spot], $table->getSpots());
}
public function testMultipleLargeSpots() {
$map = new Map([
[0, 1, 1, 0, 0],
[0, 0, 1, 0, 1],
[0, 1, 0, 0, 1],
[1, 0, 0, 1, 0],
]);
$table = new Table($map);
$spotA = new Spot(new Position(1, 2));
$spotA->addPosition(new Position(1, 3));
$spotA->addPosition(new Position(2, 3));
$spotA->addPosition(new Position(3, 2));
$spotA->addPosition(new Position(4, 1));
$spotB = new Spot(new Position(2, 5));
$spotB->addPosition(new Position(3, 5));
$spotB->addPosition(new Position(4, 4));
$this->assertEquals([$spotA, $spotB], $table->getSpots());
}
}

Loading…
Cancel
Save