Added PHPUnit
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
output/
|
||||
.*.cache/
|
||||
vendor/
|
||||
tools/
|
4
.phive/phars.xml
Normal file
4
.phive/phars.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phive xmlns="https://phar.io/phive">
|
||||
<phar name="phpunit" version="^12.2.2" installed="12.2.2" location="./tools/phpunit" copy="false"/>
|
||||
</phive>
|
9
solutions/Generic/MultiTable/desc.yml
Normal file
9
solutions/Generic/MultiTable/desc.yml
Normal file
@ -0,0 +1,9 @@
|
||||
title: Multiplication table
|
||||
|
||||
|
||||
desc: Building a multiplication table in C
|
||||
|
||||
solutions:
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
@ -8,12 +8,12 @@ class Numerical
|
||||
{
|
||||
public static function isPandigital(int $input): bool
|
||||
{
|
||||
return self::isDigitsPresent($input, [49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]);
|
||||
return self::isDigitsPresent($input, [0x31 => 1, 0x32 => 1, 0x33 => 1, 0x34 => 1, 0x35 => 1, 0x36 => 1, 0x37 => 1, 0x38 => 1, 0x39 => 1]);
|
||||
}
|
||||
|
||||
public static function isPandigitalWithZero(int $input): bool
|
||||
{
|
||||
return self::isDigitsPresent($input, [48 => 0, 49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]);
|
||||
return self::isDigitsPresent($input, [0x30 => 1, 0x31 => 1, 0x32 => 1, 0x33 => 1, 0x34 => 1, 0x35 => 1, 0x36 => 1, 0x37 => 1, 0x38 => 1, 0x39 => 1]);
|
||||
}
|
||||
|
||||
private static function isDigitsPresent(int $input, array $count): bool
|
||||
|
@ -12,12 +12,20 @@ use CodingTests\Prime;
|
||||
#[CoversClass(Prime::class)]
|
||||
final class PrimeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function isPandigital(): void
|
||||
static $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
|
||||
public function testisPrime(): void
|
||||
{
|
||||
$primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
|
||||
for ($test = -100; $test <= 100; $test++) {
|
||||
$ret = Prime::isPrime($test);
|
||||
$this->assertEquals(in_array($test, $primes), $ret, "Testing $test");
|
||||
$this->assertEquals(in_array($test, self::$primes), $ret, "Testing $test");
|
||||
}
|
||||
}
|
||||
|
||||
public function testis_prime(): void
|
||||
{
|
||||
for ($test = -100; $test <= 100; $test++) {
|
||||
$ret = Prime::isPrime($test);
|
||||
$this->assertEquals(in_array($test, self::$primes), $ret, "Testing $test");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user