Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
* [Absolutemin](./Maths/AbsoluteMin.php)
* [Armstrongnumber](./Maths/ArmstrongNumber.php)
* [Basex](./Maths/BaseX.php)
* [CheckEven](./Maths/CheckEven.php)
* [Checkpalindrome](./Maths/CheckPalindrome.php)
* [Checkprime](./Maths/CheckPrime.php)
* [CheckOdd](./Maths/CheckOdd.php)
* [Eratosthenessieve](./Maths/EratosthenesSieve.php)
* [Factorial](./Maths/Factorial.php)
* [Fastexponentiation](./Maths/FastExponentiation.php)
Expand Down
13 changes: 13 additions & 0 deletions Maths/CheckEven.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* This function checks whether
* the provided integer is even.
*
* @param int $number An integer input
* @return bool whether the number is even or not
*/
function isEven(int $number): bool
{
return $number % 2 === 0;
}
13 changes: 13 additions & 0 deletions Maths/CheckOdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* This function checks whether
* the provided integer is odd.
*
* @param int $number An integer input
* @return bool whether the number is odd or not
*/
function isOdd(int $number): bool
{
return $number % 2 !== 0;
}
20 changes: 20 additions & 0 deletions tests/Maths/MathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
require_once __DIR__ . '/../../Maths/AbsoluteMax.php';
require_once __DIR__ . '/../../Maths/ArmstrongNumber.php';
require_once __DIR__ . '/../../Maths/AbsoluteMin.php';
require_once __DIR__ . '/../../Maths/CheckEven.php';
require_once __DIR__ . '/../../Maths/CheckPalindrome.php';
require_once __DIR__ . '/../../Maths/CheckPrime.php';
require_once __DIR__ . '/../../Maths/CheckOdd.php';
require_once __DIR__ . '/../../Maths/Factorial.php';
require_once __DIR__ . '/../../Maths/FastExponentiation.php';
require_once __DIR__ . '/../../Maths/Fibonacci.php';
Expand Down Expand Up @@ -40,6 +42,15 @@ public function testFactorial()
factorial(-25);
}

public function testIsEven()
{
$this->assertTrue(isEven(2));
$this->assertTrue(isEven(0));
$this->assertFalse(isEven(3));
$this->assertFalse(isEven(17));
$this->assertTrue(isEven(-4));
}

public function testIsNumberArmstrong()
{
$this->assertTrue(isNumberArmstrong(153));
Expand All @@ -56,6 +67,15 @@ public function testIsNumberPalindromic()
$this->assertFalse(isNumberPalindromic(2468));
}

public function testIsOdd()
{
$this->assertTrue(isOdd(3));
$this->assertTrue(isOdd(17));
$this->assertFalse(isOdd(4));
$this->assertFalse(isOdd(0));
$this->assertTrue(isOdd(-5));
}

public function testIsPrime()
{
$this->assertTrue(isPrime(73));
Expand Down
Loading