Skip to content

Commit

Permalink
PHPUnit code coverage (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliance authored Jan 10, 2017
1 parent 217fbd0 commit 78d8b4f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Simple bitmask implementation
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Packagist](https://img.shields.io/packagist/v/aliance/bitmask.svg)](https://packagist.org/packages/aliance/bitmask)
[![Build Status](https://travis-ci.org/Aliance/Bitmask.svg?branch=master)](https://travis-ci.org/Aliance/Bitmask)
[![Code Coverage](https://scrutinizer-ci.com/g/Aliance/Bitmask/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Aliance/Bitmask/?branch=master)

Installation
---
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
57 changes: 56 additions & 1 deletion tests/BitmaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ class BitmaskTest extends TestCase
*/
private $Bitmask;

/**
* @covers \Aliance\Bitmask\Bitmask::__construct
* @covers \Aliance\Bitmask\Bitmask::create
*/
public function testBitmaskCreation()
{
$this->assertInstanceOf(Bitmask::class, $this->Bitmask);
$this->assertInstanceOf(Bitmask::class, Bitmask::create());
}

/**
* @covers \Aliance\Bitmask\Bitmask::getSetBitsCount
* @covers \Aliance\Bitmask\Bitmask::getMask
*/
public function testEmptyBitmask()
{
$this->assertEquals(0, $this->Bitmask->getSetBitsCount());
Expand All @@ -20,20 +34,60 @@ public function testEmptyBitmask()
}

/**
* @covers \Aliance\Bitmask\Bitmask::setBit
* @covers \Aliance\Bitmask\Bitmask::checkBit
* @expectedException \InvalidArgumentException
*/
public function testThatTooBigBitCauseAnException()
{
$this->Bitmask->setBit(Bitmask::MAX_BIT + 1);
}

public function testMask()
/**
* @covers \Aliance\Bitmask\Bitmask::setMask
*/
public function testMaskSetting()
{
$this->assertEquals(0, $this->Bitmask->getMask());
$this->Bitmask->setMask(1024);
$this->assertEquals(1024, $this->Bitmask->getMask());
}

/**
* @covers \Aliance\Bitmask\Bitmask::addMask
*/
public function testMaskAdding()
{
$this->assertEquals(0, $this->Bitmask->getMask());

// adding 10 bit
$this->Bitmask->addMask(1024);
$this->assertEquals(1024, $this->Bitmask->getMask());

// adding 3 bit
$this->Bitmask->addMask(8);
$this->assertEquals(1032, $this->Bitmask->getMask());
}

/**
* @covers \Aliance\Bitmask\Bitmask::deleteMask
*/
public function testMaskDeleting()
{
$this->assertEquals(0, $this->Bitmask->getMask());

// adding 3 & 10 bits
$this->Bitmask->setMask(1032);
$this->assertEquals(1032, $this->Bitmask->getMask());

// deleting 10 bit
$this->Bitmask->deleteMask(1024);
$this->assertEquals(8, $this->Bitmask->getMask());
}

/**
* @covers \Aliance\Bitmask\Bitmask::unsetBit
*/
public function testBits()
{
$this->assertFalse($this->Bitmask->issetBit(3));
Expand All @@ -55,6 +109,7 @@ public function testBits()
}

/**
* @covers \Aliance\Bitmask\Bitmask::issetBit
* @dataProvider getBitsWithMaskPairs
* @param int[] $bits
* @param int $expectedMask
Expand Down

0 comments on commit 78d8b4f

Please sign in to comment.