-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
059ddd5
commit 68ba2f2
Showing
54 changed files
with
6,355 additions
and
7,559 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
This file was deleted.
Oops, something went wrong.
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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
use CondorcetPHP\Condorcet\{Candidate, Election, Vote}; | ||
use CondorcetPHP\Condorcet\Utils\CondorcetUtil; | ||
test('readme quick example', function () { | ||
$myElection1 = new Election; | ||
|
||
// Create your own candidate object | ||
$candidate1 = new Candidate('Candidate 1'); | ||
$candidate2 = new Candidate('Candidate 2'); | ||
$candidate3 = new Candidate('Candidate 3'); | ||
|
||
// Register your candidates | ||
$myElection1->addCandidate($candidate1); | ||
$myElection1->addCandidate($candidate2); | ||
$myElection1->addCandidate($candidate3); | ||
$candidate4 = $myElection1->addCandidate('Candidate 4'); | ||
|
||
// Add some votes, by some ways | ||
$myElection1->addVote( | ||
[ | ||
$candidate2, // 1 | ||
[$candidate1, $candidate4], // 2 - Tie | ||
// Last rank is optionnal. Here it's : $candidate3 | ||
] | ||
); | ||
|
||
$myElection1->addVote('Candidate 2 > Candidate 3 > Candidate 4 = Candidate 1'); | ||
|
||
// last rank can also be omitted | ||
$myElection1->parseVotes( | ||
'tagX || Candidate 1 > Candidate 2 = Candidate 4 > Candidate 3 * 4 | ||
tagX, tagY || Candidate 3 > Candidate 1 * 3' | ||
); | ||
|
||
// Powerfull, it add 7 votes | ||
$myElection1->addVote(new Vote( | ||
[ | ||
$candidate4, | ||
$candidate2, | ||
// You can ignore the over. They will be at the last rank in the contexte of each election. | ||
] | ||
)); | ||
|
||
// Get Result | ||
// Natural Condorcet Winner | ||
$myWinner = $myElection1->getCondorcetWinner(); | ||
// Return a candidate object | ||
expect('My winner is ' . $myWinner->getName() . '<br>')->toEqual('My winner is Candidate 1<br>'); | ||
|
||
// Natural Condorcet Loser | ||
$myLoser = $myElection1->getCondorcetLoser(); | ||
// Return a candidate object | ||
expect('My loser is ' . $myLoser->getName())->toEqual('My loser is Candidate 3'); | ||
|
||
// Schulze Ranking | ||
$myResultBySchulze = $myElection1->getResult('Schulze'); | ||
|
||
// Return a multi-dimensional array, filled with objects Candidate (multi-dimensional if tie on a rank) | ||
# Echo it easily | ||
expect(CondorcetUtil::format($myResultBySchulze))->toBe([1 => 'Candidate 1', 2 => 'Candidate 2', 3 => 'Candidate 4', 4 => 'Candidate 3']); | ||
|
||
// Get Schulze advanced computing data & stats | ||
$mySchulzeStats = $myElection1->getResult('Schulze')->getStats(); | ||
|
||
// Get Copeland Ranking | ||
$myResultByCopeland = $myElection1->getResult('Copeland'); | ||
|
||
// Get Pairwise | ||
$myPairwise = $myElection1->getPairwise(); | ||
|
||
// How long computation time behind us? | ||
$timer = $myElection1->getGlobalTimer(); | ||
|
||
// SHA-2 checksum and sleep | ||
$myChecksum = $myElection1->getChecksum(); | ||
$toStore = serialize($myElection1); | ||
$comeBack = unserialize($toStore); | ||
|
||
expect($myChecksum)->toBe($comeBack->getChecksum()); | ||
}); |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use CondorcetPHP\Condorcet\Condorcet; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
// expect()->extend('toBeOne', function () { | ||
// return $this->toBe(1); | ||
// }); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
// function something() | ||
// { | ||
// // .. | ||
// } | ||
|
||
|
||
function getMethodList(): array | ||
{ | ||
$methods = Condorcet::getAuthMethods(withNonDeterministicMethods: false); | ||
array_walk($methods, static fn(&$m): array => $m = [$m]); | ||
|
||
return $methods; | ||
} |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
// | ||
} |
Oops, something went wrong.