-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved combinatorial and minor bugs
- Loading branch information
Showing
6 changed files
with
175 additions
and
35 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 |
---|---|---|
|
@@ -2,12 +2,14 @@ | |
|
||
[![Build Status](https://travis-ci.org/GuilleGF/SecretSantaPHP.svg?branch=master)](https://travis-ci.org/GuilleGF/SecretSantaPHP) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/GuilleGF/SecretSantaPHP/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/GuilleGF/SecretSantaPHP/?branch=master) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/GuilleGF/SecretSantaPHP/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/GuilleGF/SecretSantaPHP/?branch=master) | ||
[![Dependency Status](https://www.versioneye.com/user/projects/5821ae0d89f0a91d55eb9600/badge.svg)](https://www.versioneye.com/user/projects/5821ae0d89f0a91d55eb9600) | ||
[![Latest Stable Version](https://poser.pugx.org/guillegf/secret-santa/v/stable)](https://packagist.org/packages/guillegf/secret-santa) | ||
[![Total Downloads](https://poser.pugx.org/guillegf/secret-santa/downloads)](https://packagist.org/packages/guillegf/secret-santa) | ||
[![License](https://poser.pugx.org/guillegf/secret-santa/license)](https://packagist.org/packages/guillegf/secret-santa) | ||
|
||
* Repository: https://github.com/GuilleGF/SecretSantaPHP | ||
* Version: 1.0.3 | ||
* Version: 1.1.0 | ||
* License: MIT, see [LICENSE](LICENSE) | ||
|
||
## Description | ||
|
@@ -29,28 +31,27 @@ documentation. | |
To add this dependency using the command, run the following from within your | ||
project directory: | ||
``` | ||
composer require guillegf/secret-santa "~1.0" | ||
composer require guillegf/secret-santa "~1.1" | ||
``` | ||
|
||
Alternatively, add the dependency directly to your `composer.json` file: | ||
```json | ||
"require": { | ||
"guillegf/secret-santa": "~1.0" | ||
"guillegf/secret-santa": "~1.1" | ||
} | ||
``` | ||
## Usage | ||
|
||
```php | ||
<?php | ||
$secretSanta = new SecretSanta(); | ||
$secretSantaPlayers = $secretSanta | ||
->addPlayer('Player', '[email protected]') | ||
->addCouple('Player2', '[email protected]', 'Couple2', '[email protected]') | ||
$secretSanta->addPlayer('Player', '[email protected]') | ||
->addPlayer('Player2', '[email protected]') | ||
->addCouple('Player3', '[email protected]', 'Couple3', '[email protected]') | ||
->play(); | ||
->addCouple('Player4', '[email protected]', 'Couple4', '[email protected]'); | ||
|
||
foreach ($secretSantaPlayers as $player) { | ||
echo ("{$player['name']} {$player['email']}: {$player['secretSanta']}\n"); | ||
foreach ($secretSanta->play() as $player) { | ||
echo ("{$player->name()} ({$player->email()}): {$player->secretSanta()->name()}\n"); | ||
} | ||
``` | ||
|
||
|
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 |
---|---|---|
|
@@ -15,6 +15,14 @@ public function testSortName() | |
Player::create('ab', '[email protected]'); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayerException | ||
*/ | ||
public function testInvalidName() | ||
{ | ||
Player::create([], '[email protected]'); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayerException | ||
*/ | ||
|
@@ -31,4 +39,24 @@ public function testPlayer() | |
$this->assertSame('name', $player->name()); | ||
$this->assertSame('[email protected]', $player->email()); | ||
} | ||
|
||
public function testAddSecretSantaToPlayer() | ||
{ | ||
$player = Player::create('name', '[email protected]'); | ||
$secretSanta = Player::create('name', '[email protected]'); | ||
|
||
$player->setSecretSanta($secretSanta); | ||
|
||
$this->assertSame($secretSanta, $player->secretSanta()); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayerException | ||
*/ | ||
public function testGetSecretSantaBeforeAddToPlayer() | ||
{ | ||
$player = Player::create('name', '[email protected]'); | ||
|
||
$player->secretSanta(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -20,6 +20,18 @@ public function testAddPlayer() | |
$this->assertSame($expectedPlayer, $player); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayersCollectionException | ||
*/ | ||
public function testGetUnKnowPlayer() | ||
{ | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addPlayer($expectedPlayer); | ||
|
||
$playersCollection->player('error-id'); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayersCollectionException | ||
*/ | ||
|
@@ -46,4 +58,31 @@ public function testAddCouple() | |
$this->assertSame($expectedPlayer, $player); | ||
$this->assertSame($expectedCouple, $couple); | ||
} | ||
|
||
public function testShufflePlayers() | ||
{ | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
$expectedCouple = Player::create('nameCouple', '[email protected]'); | ||
|
||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addCouple($expectedPlayer, $expectedCouple); | ||
|
||
$shufflePlayers = $playersCollection->shufflePlayers(); | ||
|
||
$this->assertNotEquals(array_keys($playersCollection->players()), array_keys($shufflePlayers)); | ||
} | ||
|
||
public function testExcludePlayers() | ||
{ | ||
$expectedSinglePlayer = Player::create('nameSingle', '[email protected]'); | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
$expectedCouple = Player::create('nameCouple', '[email protected]'); | ||
|
||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addCouple($expectedPlayer, $expectedCouple); | ||
|
||
$this->assertTrue($playersCollection->areExclude($expectedPlayer, $expectedCouple)); | ||
$this->assertFalse($playersCollection->areExclude($expectedSinglePlayer, $expectedPlayer)); | ||
$this->assertSame(2, $playersCollection->countExcludePlayers()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -59,4 +59,34 @@ public function testFourCouplesAndTwoPlayers() | |
|
||
$this->assertSame(10 , count($combination)); | ||
} | ||
|
||
public function testTenCouplesAndTenPlayers() | ||
{ | ||
$secretSanta = new SecretSanta(); | ||
|
||
$secretSanta->addPlayer('Player', '[email protected]'); | ||
$secretSanta->addPlayer('Player2', '[email protected]'); | ||
$secretSanta->addCouple('Player3', '[email protected]', 'Couple3', '[email protected]'); | ||
$secretSanta->addCouple('Player4', '[email protected]', 'Couple4', '[email protected]'); | ||
$secretSanta->addCouple('Player5', '[email protected]', 'Couple5', '[email protected]'); | ||
$secretSanta->addCouple('Player6', '[email protected]', 'Couple6', '[email protected]'); | ||
$secretSanta->addPlayer('Player7', '[email protected]'); | ||
$secretSanta->addPlayer('Player8', '[email protected]'); | ||
$secretSanta->addPlayer('Player9', '[email protected]'); | ||
$secretSanta->addPlayer('Player10', '[email protected]'); | ||
$secretSanta->addPlayer('Player11', '[email protected]'); | ||
$secretSanta->addPlayer('Player12', '[email protected]'); | ||
$secretSanta->addCouple('Player13', '[email protected]', 'Couple13', '[email protected]'); | ||
$secretSanta->addCouple('Player14', '[email protected]', 'Couple14', '[email protected]'); | ||
$secretSanta->addCouple('Player15', '[email protected]', 'Couple15', '[email protected]'); | ||
$secretSanta->addCouple('Player16', '[email protected]', 'Couple16', '[email protected]'); | ||
$secretSanta->addPlayer('Player17', '[email protected]'); | ||
$secretSanta->addPlayer('Player18', '[email protected]'); | ||
$secretSanta->addCouple('Player19', '[email protected]', 'Couple19', '[email protected]'); | ||
$secretSanta->addCouple('Player20', '[email protected]', 'Couple20', '[email protected]'); | ||
|
||
$combination = $secretSanta->play(); | ||
|
||
$this->assertSame(30 , count($combination)); | ||
} | ||
} |