mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 07:08:13 +01:00
meta: add tests/Ciphers; change ciphers dir to Ciphers for consistency
This commit is contained in:
parent
edb7ef5d54
commit
69e86faafc
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
use function PHPUnit\Framework\assertEquals;
|
||||
use function PHPUnit\Framework\assertFalse;
|
||||
use function PHPUnit\Framework\assertNotEquals;
|
||||
use function PHPUnit\Framework\assertTrue;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../ciphers/XORCipher.php';
|
||||
|
||||
class CipherTest extends TestCase
|
||||
{
|
||||
public function testXor_cipher()
|
||||
{
|
||||
$inp_str = "test@string";
|
||||
$key = "test-key";
|
||||
$invalid_key = "wrong-key";
|
||||
assertEquals( $inp_str, xor_cipher( xor_cipher( $inp_str , $key) , $key));
|
||||
assertNotEquals( $inp_str, xor_cipher( xor_cipher( $inp_str , $key) , $invalid_key));
|
||||
}
|
||||
}
|
28
tests/Ciphers/CiphersTest.php
Executable file
28
tests/Ciphers/CiphersTest.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use function PHPUnit\Framework\assertEquals;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../../Ciphers/CaesarCipher.php';
|
||||
require_once __DIR__ . '/../../Ciphers/XORCipher.php';
|
||||
|
||||
class CiphersTest extends TestCase
|
||||
{
|
||||
public function testCaesarCipher()
|
||||
{
|
||||
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7));
|
||||
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7 + 26));
|
||||
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7));
|
||||
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7 + 26));
|
||||
}
|
||||
|
||||
public function testXorCipher()
|
||||
{
|
||||
$input_str = "test@string";
|
||||
$key = "test-key";
|
||||
$invalid_key = "wrong-key";
|
||||
assertEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $key));
|
||||
assertNotEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $invalid_key));
|
||||
}
|
||||
}
|
@ -3,12 +3,12 @@
|
||||
use function PHPUnit\Framework\assertEquals;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../ciphers/morseCode.php';
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../../Ciphers/MorseCode.php';
|
||||
|
||||
class MorseCodeTest extends TestCase
|
||||
{
|
||||
public function testCaesarCipher()
|
||||
public function testMorseCodeCipher()
|
||||
{
|
||||
assertEquals('TEST 123', decode(encode('TEST 123')));
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
use function PHPUnit\Framework\assertEquals;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../ciphers/caesarCipher.php';
|
||||
|
||||
class CiphersTest extends TestCase
|
||||
{
|
||||
public function testCaesarCipher()
|
||||
{
|
||||
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7));
|
||||
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7 + 26));
|
||||
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7));
|
||||
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7 + 26));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user