-
Notifications
You must be signed in to change notification settings - Fork 4
/
TestTerms.php
127 lines (114 loc) · 4.34 KB
/
TestTerms.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
include 'Terms.php';
function arrayToString($a) {
return "[" . implode(",", $a) . "]";
}
echo "Test 1: empty<br>Expected: [0]<br>Actual: ";
$termArray = new TermArray();
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 2: New<br>Expected: [1]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 3: New, York<br>Expected: [2]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("York", 1);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 4: New, New York<br>Expected: [1,1]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("New York", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 5: York, New York<br>Expected: [1,1]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("York", 1);
$termArray->addTerm("New York", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 6: New, York, New York<br>Expected: [2,1]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("York", 1);
$termArray->addTerm("New York", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 7: New, York, City<br>Expected: [3]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("York", 1);
$termArray->addTerm("City", 2);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";
echo "Test 8: New, York, City, New York, York City, New York City<br>Expected: [3,2,2,1]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("York", 1);
$termArray->addTerm("City", 2);
$termArray->addTerm("New York", 0);
$termArray->addTerm("York City", 1);
$termArray->addTerm("New York City", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br>Alternate weights:<br>";
var_dump($termArray->getAlternateWeights());
echo "<br><br>";
echo "Test 9: New, York, City, New York, York City<br>Expected: [3,2,2]<br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("New", 0);
$termArray->addTerm("York", 1);
$termArray->addTerm("City", 2);
$termArray->addTerm("New York", 0);
$termArray->addTerm("York City", 1);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
//var_dump($termArray->findGroups());
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br>Alternate weights:<br>";
var_dump($termArray->getAlternateWeights());
echo "<br><br>";
echo "Test 10: The, New, York, City, New York, York City, New York City, The New, The New York, The New York City<br>Expected: <br>Actual: ";
$termArray = new TermArray();
$termArray->addTerm("The", 0);
$termArray->addTerm("New", 1);
$termArray->addTerm("York", 2);
$termArray->addTerm("City", 3);
$termArray->addTerm("The New", 0);
$termArray->addTerm("New York", 1);
$termArray->addTerm("York City", 2);
$termArray->addTerm("New York City", 1);
$termArray->addTerm("The New York", 0);
$termArray->addTerm("The New York City", 0);
$weightHelperResult = $termArray->weightHelper($termArray->getAllTerms());
echo arrayToString($weightHelperResult);
echo "<br>Weights:<br>";
var_dump($termArray->getWeights());
echo "<br><br>";