This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aggiunto codice mutable, spec e benchmark, ottimizzato esercizio K in
tutte le librerie
- Loading branch information
1 parent
9d009dd
commit ec612f8
Showing
7 changed files
with
372 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
namespace LambdaRoma\KataZero; | ||
|
||
/** | ||
* Class KataZeroFP | ||
* @package LambdaRoma\KataZero | ||
*/ | ||
class KataZeroFP | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function kataZeroA(): array | ||
{ | ||
return range(1, 3); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function kataZeroB(): array | ||
{ | ||
return range(0, 10, 2); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function kataZeroC(): array | ||
{ | ||
return range(7, 100, 7); | ||
} | ||
|
||
/** | ||
* @param array $menNames | ||
* @return array | ||
*/ | ||
public function kataZeroD(array $menNames): array | ||
{ | ||
return array_values(array_filter($menNames, function ($item) { | ||
return strtolower($item[0]) === 'c'; | ||
})); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function kataZeroE(): int | ||
{ | ||
$range = range(8, 100, 8); | ||
return array_sum($range) / count($range); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function kataZeroF(): int | ||
{ | ||
return array_sum(range(6, 1000, 6)); | ||
} | ||
|
||
/** | ||
* @param array $menNames | ||
* @return array | ||
*/ | ||
public function kataZeroG(array $menNames): array | ||
{ | ||
$menNamesToSort = $menNames; | ||
sort($menNamesToSort); | ||
return $menNamesToSort; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function kataZeroH(): int | ||
{ | ||
$range = range(41, 1000, 41); | ||
return $range[array_rand($range)]; | ||
} | ||
|
||
/** | ||
* @param array $menNames | ||
* @return string | ||
*/ | ||
public function kataZeroI(array $menNames): string | ||
{ | ||
return implode(', ', $menNames); | ||
} | ||
|
||
/** | ||
* @param array $menNames | ||
* @return array | ||
*/ | ||
public function kataZeroJ(array $menNames): array | ||
{ | ||
return array_unique($menNames); | ||
} | ||
|
||
/** | ||
* @param array $womenNames | ||
* @return array | ||
*/ | ||
public function kataZeroK(array $womenNames): array | ||
{ | ||
return array_reduce($womenNames, function ($carry, $item) { | ||
$index = strlen($item); | ||
$carry[$index] = isset($carry[$index]) | ||
? array_merge($carry[$index], [$item]) | ||
: [$item]; | ||
return $carry; | ||
}, []); | ||
} | ||
|
||
/** | ||
* @param array $womenNames | ||
* @return array | ||
*/ | ||
public function kataZeroL(array $womenNames): array | ||
{ | ||
return array_map(function ($item) { | ||
return strlen($item); | ||
}, $womenNames); | ||
} | ||
|
||
/** | ||
* @param $womenNames | ||
* @return array | ||
*/ | ||
public function kataZeroM($womenNames): array | ||
{ | ||
return array_map(function ($item) { | ||
return $item[0]; | ||
}, $womenNames); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
namespace benchmarks\LambdaRoma\KataZero; | ||
|
||
use LambdaRoma\KataZero\KataZeroFP; | ||
|
||
/** | ||
* Class KataZeroQaribuBench | ||
* @Groups({"functional", "mutable"}) | ||
* @BeforeMethods({"init"}) | ||
* @Revs(1000) | ||
* @Iterations(2) | ||
*/ | ||
class KataZeroFPBench | ||
{ | ||
private $subject; | ||
private $men = ["Tizio", "Caio", "Sempronio", "Mevio", "Filano", "Calpurnio"]; | ||
private $women = ["Anna", "Carla", "Angela", "Chiara", "Emma", "Maria", "Sara"]; | ||
|
||
public function init() | ||
{ | ||
$this->subject = new KataZeroFP(); | ||
} | ||
|
||
public function benchKataZeroA() | ||
{ | ||
$this->subject->kataZeroA(); | ||
} | ||
|
||
public function benchKataZeroB() | ||
{ | ||
$this->subject->kataZeroB(); | ||
} | ||
|
||
public function benchKataZeroC() | ||
{ | ||
$this->subject->kataZeroC(); | ||
} | ||
|
||
public function benchKataZeroD() | ||
{ | ||
$this->subject->kataZeroD($this->men); | ||
} | ||
|
||
public function benchKataZeroE() | ||
{ | ||
$this->subject->kataZeroE(); | ||
} | ||
|
||
public function benchKataZeroF() | ||
{ | ||
$this->subject->kataZeroF(); | ||
} | ||
|
||
public function benchKataZeroG() | ||
{ | ||
$this->subject->kataZeroG($this->men); | ||
} | ||
|
||
public function benchKataZeroI() | ||
{ | ||
$this->subject->kataZeroI($this->men); | ||
} | ||
|
||
public function benchKataZeroJ() | ||
{ | ||
$this->subject->kataZeroJ($this->men); | ||
} | ||
|
||
public function benchKataZeroK() | ||
{ | ||
$this->subject->kataZeroK($this->women); | ||
} | ||
|
||
public function benchKataZeroL() | ||
{ | ||
$this->subject->kataZeroL($this->women); | ||
} | ||
|
||
public function benchKataZeroM() | ||
{ | ||
$this->subject->kataZeroM($this->women); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.