Skip to content

Commit

Permalink
Adapted tests to Boolean conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Rafael Azevedo committed May 25, 2019
1 parent 69af8e7 commit 258a738
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 38 deletions.
38 changes: 0 additions & 38 deletions tests/Unit/Scalar/ImmutableFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Hradigital\Datatypes\Scalar\ImmutableFloat;
use Hradigital\Datatypes\Scalar\MutableFloat;
use Hradigital\Tests\Datatypes\AbstractBaseTestCase;
use Hradigital\Datatypes\Scalar\ReadonlyBoolean;

/**
* Immutable Float Unit testing.
Expand Down Expand Up @@ -123,43 +122,6 @@ public function testCanConvertInstanceToInteger(): void
);
}

/**
* Tests that the instance can be converted to a Boolean.
*
* @since 1.0.0
* @return void
*/
public function testCanConvertInstanceToBoolean(): void
{
// Performs test.
$true = $this->initializeInstance(123.0);
$false = $this->initializeInstance(0.0);
$trueBoolean = $true->toBoolean();
$falseBoolean = $false->toBoolean();

// Performs assertions.
$this->assertInstanceOf(
ReadonlyBoolean::class,
$trueBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'True',
$trueBoolean->toString(),
'Instance value is not correct.'
);
$this->assertInstanceOf(
ReadonlyBoolean::class,
$falseBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'False',
$falseBoolean->toString(),
'Instance value is not correct.'
);
}

/**
* Tests that the instance can be converted to a String.
*
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/Scalar/ReadonlyFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Hradigital\Datatypes\Scalar\ReadonlyInteger;
use Hradigital\Datatypes\Scalar\ReadonlyString;
use Hradigital\Tests\Datatypes\AbstractBaseTestCase;
use Hradigital\Datatypes\Scalar\ReadonlyBoolean;

/**
* Readonly Float Unit testing.
Expand Down Expand Up @@ -468,4 +469,41 @@ public function testCanConvertToInteger(): void
"Returned instance should have been of type ReadonlyInteger."
);
}

/**
* Tests that the instance can be converted to a Boolean.
*
* @since 1.0.0
* @return void
*/
public function testCanConvertInstanceToBoolean(): void
{
// Performs test.
$true = ReadonlyFloat::fromFloat(123.0);
$false = ReadonlyFloat::fromFloat(0.0);
$trueBoolean = $true->toBoolean();
$falseBoolean = $false->toBoolean();

// Performs assertions.
$this->assertInstanceOf(
ReadonlyBoolean::class,
$trueBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'True',
$trueBoolean->toString(),
'Instance value is not correct.'
);
$this->assertInstanceOf(
ReadonlyBoolean::class,
$falseBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'False',
$falseBoolean->toString(),
'Instance value is not correct.'
);
}
}
38 changes: 38 additions & 0 deletions tests/Unit/Scalar/ReadonlyIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Hradigital\Datatypes\Scalar\ReadonlyInteger;
use Hradigital\Datatypes\Scalar\ReadonlyString;
use Hradigital\Tests\Datatypes\AbstractBaseTestCase;
use Hradigital\Datatypes\Scalar\ReadonlyBoolean;

/**
* Readonly Integer Unit testing.
Expand Down Expand Up @@ -466,4 +467,41 @@ public function testCanConvertToFloat(): void
"Returned instance should have been of type ReadonlyFloat."
);
}

/**
* Tests that the instance can be converted to a Boolean.
*
* @since 1.0.0
* @return void
*/
public function testCanConvertInstanceToBoolean(): void
{
// Performs test.
$true = ReadonlyInteger::fromInteger(123);
$false = ReadonlyInteger::fromInteger(0);
$trueBoolean = $true->toBoolean();
$falseBoolean = $false->toBoolean();

// Performs assertions.
$this->assertInstanceOf(
ReadonlyBoolean::class,
$trueBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'True',
$trueBoolean->toString(),
'Instance value is not correct.'
);
$this->assertInstanceOf(
ReadonlyBoolean::class,
$falseBoolean,
'Instance type, does not match ReadonlyBoolean.'
);
$this->assertEquals(
'False',
$falseBoolean->toString(),
'Instance value is not correct.'
);
}
}

0 comments on commit 258a738

Please sign in to comment.