Skip to content

Commit

Permalink
Add Odd and Even Check Functions (#165)
Browse files Browse the repository at this point in the history
* Add CheckOdd and CheckEven functions

* code style improved

* code corrected
  • Loading branch information
vishalvnair124 authored Oct 1, 2024
1 parent c7c83c3 commit e0be0fd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,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

0 comments on commit e0be0fd

Please sign in to comment.