-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.php
86 lines (65 loc) · 2.05 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require_once('genderfromname.php');
$genders = array('Josephine' => 'f',
'Michael' => 'm',
'Dondi' => 'm',
'Jonny' => 'm',
'Pascal' => 'm',
'Velvet' => 'f',
'Eamon' => 'm',
'FLKMLKSJN' => '');
$names = array('Josephine',
'Michael',
'Dondi',
'Jonny',
'Pascal',
'Velvet',
'Eamon',
'FLKMLKSJN');
$MATCH_LIST[] = 'user_sub';
$tests = $MATCH_LIST;
print '<html><head><title>GenderFromName PHP module test</title></head><body>';
// Test for Text::DoubleMetaphone. Skip those tests if not installed.
if (!is_callable('double_metaphone'))
{
print 'Skipping double_metaphone tests - module not found. See http://svn.php.net/viewvc/pecl/doublemetaphone/<br>';
foreach ($tests as $index => $function)
{
if (preg_match('/metaphone/', $function))
unset($tests[$index]);
}
}
$DEBUG = 1;
$index = 0;
foreach ($tests as $testname) {
// Test just this one rule.
$MATCH_LIST = array($testname);
$firstname = $names[$index];
$secondname = $names[$index+1];
$firstresult = gender($firstname);
$secondresult = gender($secondname);
$firstexpected = $genders[$firstname];
$secondexpected = $genders[$secondname];
print_result($testname, $firstname, $firstresult, $firstexpected);
print_result($testname, $secondname, $secondresult, $secondexpected);
$index += 1;
}
print '</body></html>';
function user_sub($name) {
if (preg_match('/^eamon/', $name)) return 'm';
}
function print_result($testname, $name, $result, $expected)
{
if (isset($result))
{
if ($result['gender']!==$expected)
print "ERROR: $testname produced '{$result['gender']}' for $name, expected '$expected'<br>";
else
print "SUCCESS: $testname produced '{$result['gender']}' for $name<br>";
}
else
{
print "UNKNOWN: $testname produced nothing for $name<br>";
}
}
?>