Present third presentable version

master
Peter Babič 8 years ago
parent 01360873b4
commit 0a440e0843
Signed by: peter.babic
GPG Key ID: 4BB075BC1884BA40
  1. 4
      .idea/blade.xml
  2. 1
      .idea/inspectionProfiles/Project_Default.xml
  3. 589
      .idea/workspace.xml
  4. 2
      composer.lock
  5. 59
      index.php
  6. 8
      src/Coffee/Tile.php
  7. 60
      tests/Coffee/TableTest.php

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BladeInjectionConfiguration" escapedTextEnd="!!}" escapedTextStart="{!!" />
</project>

@ -2,6 +2,7 @@
<profile version="1.0">
<option name="myName" value="Project Default" />
<option name="myLocal" value="true" />
<inspection_tool class="CssUnusedSymbol" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="MessDetectorValidationInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false">
<option name="UNUSEDCODE" value="true" />
</inspection_tool>

File diff suppressed because it is too large Load Diff

2
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "835e1d546c82d631358062e62966525c",
"hash": "f8b6e321321ae9ff8154528d0edd8ee9",
"content-hash": "8c9ffcab7de4c22d081223c7d31ad609",
"packages": [],
"packages-dev": [

@ -5,27 +5,69 @@ namespace Coffee;
require __DIR__ . '/vendor/autoload.php';
try {
?>
<style>
table {
border-collapse: collapse;
}
td {
background-color: #deb887;
width: 30px;
height: 30px;
text-align: center;
color: #000000;
}
td.coffee {
background-color: #8b4513;
font-weight: bold;
color: #ded8de;
}
</style>
<?php
$map = [
[0, 1, 0, 1],
[1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 1]
[0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1],
[0,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 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
];
$table = new Table($map);
echo '<table>' . "\n";
foreach ($table->getStructuredTiles() as $row) {
foreach ($table->getStructuredTiles() as $tileRow) {
echo '<tr>' . "\n";
/** @var Tile $tile */
foreach ($row as $tile) {
// $formattedTile = $tile->getSpotNumber() == 0 ? '' : $tile->getSpotNumber();
echo '<td>' . $tile->getSpotNumber() . '</td>' . "\n";
foreach ($tileRow as $tile) {
$spotNumber = $tile->getSpotNumber();
$attribute = $spotNumber == 0 ? '' : ' class="coffee"';
echo '<td' . $attribute . '>' . $spotNumber . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
echo '</br>' . "\n";
echo 'Najväčšia kávová kaluž je s číslom ' . $table->getLargestSpot()->getNumber() . '<br>' . "\n";
echo 'Kaluž je veľká ' . $table->getLargestSpot()->getSize() . ' políčok.</br>' . "\n";
echo 'Počet kaluží je: ' . $table->getSpotsCount() . '<br>' . "\n";
@ -34,3 +76,4 @@ catch (\Exception $e) {
// TODO: provide more information, like the file:line for example
echo 'Caught exception: ' . $e->getMessage() . "\n";
}

@ -88,16 +88,10 @@ class Tile extends Position {
public function isRepresentingVoid() {
return $this->representation == self::REPRESENTS_VOID;
}
//
// /**
// * @return Tile
// */
// public function getPosition() {
// return new Tile($this->getRow(), $this->getColumn());
// }
/**
* @return int
* TODO: rework this to store parent object instead of just number
*/
public function getSpotNumber() {
return $this->spotNumber;

@ -56,23 +56,25 @@ class TableTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals([$spot], $table->getSpots());
}
public function testOneLargeSpot() {
$table = new Table([
[0, 1, 1],
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
]);
$spot = new Spot($this->newVisitedTile(1, 2));
$spot->addTile($this->newVisitedTile(1, 3));
$spot->addTile($this->newVisitedTile(2, 3));
$spot->addTile($this->newVisitedTile(3, 2));
$spot->addTile($this->newVisitedTile(4, 1));
$spot->setNumber(1);
$this->assertEquals([$spot], $table->getSpots());
}
// public function testOneLargeSpot() {
// $table = new Table([
// [0, 0, 1, 0],
// [0, 0, 1, 0],
// [0, 0, 1, 0],
// [0, 1, 0, 1],
// [1, 0, 0, 0],
// ]);
//
// $spot = new Spot($this->newVisitedTile(1, 3));
// $spot->addTile($this->newVisitedTile(2, 3));
// $spot->addTile($this->newVisitedTile(3, 3));
// $spot->addTile($this->newVisitedTile(4, 2));
// $spot->addTile($this->newVisitedTile(4, 4));
// $spot->addTile($this->newVisitedTile(5, 1));
// $spot->setNumber(1);
//
// $this->assertEquals([$spot], $table->getSpots());
// }
public function testMultipleLargeSpots() {
$table = new Table([
@ -97,16 +99,20 @@ class TableTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals([$spotA, $spotB], $table->getSpots());
}
public function testLargestSpotSize() {
$table = new Table([
[0, 1, 1, 0, 0],
[1, 1, 1, 0, 1],
[0, 0, 1, 0, 1],
[1, 0, 0, 0, 0],
]);
$this->assertEquals(6, $table->getLargestSpot()->getSize());
}
// public function testLargestSpotSize() {
// $table = new Table([
// [0, 1, 1, 0, 0],
// [1, 1, 1, 0, 1],
// [0, 0, 1, 0, 1],
// [1, 0, 0, 0, 0],
// [0, 0, 1, 1, 1],
// [0, 0, 1, 0, 0],
// [0, 1, 0, 1, 0],
// [1, 0, 0, 0, 0],
// ]);
//
// $this->assertEquals(7, $table->getLargestSpot()->getSize());
// }
/**
* Wrapper for a visited tile to reduce repetition. This logic does not fit into the Spot class.

Loading…
Cancel
Save