forked from TheAlgorithms/PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConversionsTest.php
72 lines (63 loc) · 2.74 KB
/
ConversionsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use function PHPUnit\Framework\assertEquals;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../Conversions/BinaryToDecimal.php';
require_once __DIR__ . '/../../Conversions/DecimalToBinary.php';
require_once __DIR__ . '/../../Conversions/OctalToDecimal.php';
require_once __DIR__ . '/../../Conversions/HexadecimalToDecimal.php';
class ConversionsTest extends TestCase
{
public function testBinaryToDecimal()
{
assertEquals(binaryToDecimal(111), 7);
assertEquals(binaryToDecimal(101), 5);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Binary Number for Converting it to a Decimal Number.');
binaryToDecimal("this is a string");
}
public function testDecimalToBinary()
{
assertEquals(decimalToBinary(7), 111);
assertEquals(decimalToBinary(5), 101);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Decimal Number for Converting it to a Binary Number.');
decimalToBinary("this is a string");
}
public function testOctalToDecimal()
{
assertEquals(octalToDecimal(10), 8);
assertEquals(octalToDecimal(11), 9);
assertEquals(octalToDecimal(1115), 589);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Octal Number for Converting it to a Decimal Number.');
octalToDecimal("this is a string");
}
public function testDecimalToOctal()
{
assertEquals(decimalToOctal(8), 10);
assertEquals(decimalToOctal(9), 11);
assertEquals(decimalToOctal(589), 1115);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Decimal Number for Converting it to an Octal Number.');
decimalToOctal("this is a string");
}
public function testDecimalToHex()
{
assertEquals(decimalToHex(10), 'A');
assertEquals(decimalToHex(489201875), '1D28A0D3');
assertEquals(decimalToHex(171), 'AB');
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Decimal Number for Converting it to a Hexadecimal Number.');
decimalToHex("this is a string");
}
public function testHexToDecimal()
{
assertEquals(hexToDecimal('A'), 10);
assertEquals(hexToDecimal('1D28A0D3'), 489201875);
assertEquals(hexToDecimal('AB'), 171);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Please pass a valid Hexadecimal Number for Converting it to a Decimal Number.');
hexToDecimal("this is a string");
}
}