-
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.
Combination calculate + Combination Test
- Loading branch information
Iman Abbasi
committed
Feb 8, 2023
1 parent
3c86e4f
commit 8fabc1a
Showing
2 changed files
with
133 additions
and
3 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 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,102 @@ | ||
<?php | ||
|
||
namespace Graphita\Mathematics\Tests; | ||
|
||
use Graphita\Mathematics\Combination; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CombinationTest extends TestCase | ||
{ | ||
public function testGetAndSetRepetitions() | ||
{ | ||
$combination = new Combination(); | ||
|
||
$this->assertFalse($combination->canRepetitions()); | ||
|
||
$combination->setRepetitions(true); | ||
|
||
$this->assertTrue($combination->canRepetitions()); | ||
} | ||
|
||
public function testGetAndSetItems() | ||
{ | ||
$combination = new Combination(); | ||
|
||
$this->assertIsArray($combination->getItems()); | ||
$this->assertEmpty($combination->getItems()); | ||
$this->assertEquals(0, $combination->countItems()); | ||
|
||
$combination->setItems([1, 2, 3]); | ||
|
||
$this->assertIsArray($combination->getItems()); | ||
$this->assertCount(3, $combination->getItems()); | ||
$this->assertEquals(3, $combination->countItems()); | ||
} | ||
|
||
public function testGetAndSetSelection() | ||
{ | ||
$combination = new Combination(); | ||
|
||
$this->assertEquals(0, $combination->getSelection()); | ||
|
||
$combination->setSelection(2); | ||
|
||
$this->assertEquals(2, $combination->getSelection()); | ||
} | ||
|
||
public function testGetPossibilitiesWithoutItemsAndSelection() | ||
{ | ||
$combination = new Combination(); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertEmpty($combination->getPossibilities()); | ||
$this->assertEquals(0, $combination->countPossibilities()); | ||
|
||
$combination->calculate(); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertEmpty($combination->getPossibilities()); | ||
$this->assertEquals(0, $combination->countPossibilities()); | ||
} | ||
|
||
public function testGetPossibilitiesWithItemsAndWithoutSelection() | ||
{ | ||
$combination = new Combination(); | ||
$combination->setItems([1, 2, 3]); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertEmpty($combination->getPossibilities()); | ||
$this->assertEquals(0, $combination->countPossibilities()); | ||
|
||
$combination->calculate(); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertCount(1, $combination->getPossibilities()); | ||
$this->assertEquals(1, $combination->countPossibilities()); | ||
} | ||
|
||
public function testGetPossibilitiesWithItemsAndSelection() | ||
{ | ||
$combination = new Combination(); | ||
$combination->setItems([1, 2, 3]); | ||
$combination->setSelection(2); | ||
$combination->calculate(); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertCount(3, $combination->getPossibilities()); | ||
$this->assertEquals(3, $combination->countPossibilities()); | ||
} | ||
|
||
public function testGetPossibilitiesWithItemsAndSelectionAndRepetitions() | ||
{ | ||
$combination = new Combination(); | ||
$combination->setItems([1, 2, 3]); | ||
$combination->setSelection(2); | ||
$combination->setRepetitions(true); | ||
$combination->calculate(); | ||
|
||
$this->assertIsArray($combination->getPossibilities()); | ||
$this->assertCount(6, $combination->getPossibilities()); | ||
$this->assertEquals(6, $combination->countPossibilities()); | ||
} | ||
} |