forked from SykesCottages/RomanNumeralTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
41 lines (37 loc) · 899 Bytes
/
index.php
File metadata and controls
41 lines (37 loc) · 899 Bytes
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
<?php
namespace PhpNwSykes;
require_once __DIR__ . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
$positiveTests = [
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'MMX' => 2010,
'III' => 3,
'CD' => 400
];
$negativeTests = [
'Bad',
'XI Something',
'Something MM',
'-X',
''
];
?>
<h2>Valid Tests</h2>
<?php
foreach ($positiveTests as $numerial => $expected) {
printf('<p>%s should be %s - Result %s</p>', $numerial, $expected, ((new RomanNumeral($numerial))->toInt() === $expected) ? 'PASS' : 'FAIL');
}
?>
<h2>Invalid Tests</h2>
<?php
foreach($negativeTests as $numerial) {
$exception = false;
try {
(new RomanNumeral($numerial))->toInt();
} catch (\Exception $e) {
$exception = true;
}
printf('<p>%s should throw exception - Result %s</p>', $numerial, $exception ? 'PASS' : 'FAIL');
}