-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.php
53 lines (48 loc) · 924 Bytes
/
hello.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
<?php
echo "Hello world!\n";
interface IPPOT
{
public function ippot($num);
}
// Implementations under test
$Impls = array();
class Hardcoded1 implements IPPOT
{
public function ippot($num)
{
if (!is_int($num))
{
return False;
}
$ppots = array(2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,65536);
return in_array($num, $ppots);
}
}
array_push($Impls, new Hardcoded1());
function runTests($impls)
{
$trues = array(2, 4, 8, 16, 32, 64, 65536);
$falses = array(1, -8, 0, 17, 33, 100);
$oddballs = array("hello", "", "2", "16");
foreach($impls as $impl)
{
foreach($trues as $t)
{
if (!$impl->ippot($t))
{
echo $t;
throw new Exception("should be true: {$t}");
}
}
$combined_falses = array_merge($falses, $oddballs);
foreach($combined_falses as $f)
{
if ($impl->ippot($f))
{
throw new Exception('should be false: {$f}');
}
}
}
}
runTests($Impls);
?>