/[jsFind]/trunk/html/test.html
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/html/test.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21 - (show annotations)
Wed Oct 6 15:33:33 2004 UTC (19 years, 6 months ago) by dpavlin
File MIME type: text/html
File size: 4174 byte(s)
added Homer's The Odyssey as test data

1 <!DOCTYPE html PUBLIC
2 "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
7 <title>jsFind Test page</title>
8 <script src="js/search.js" type="text/javascript"></script>
9 <script src="test_data.js" type="text/javascript"></script>
10 <script type="text/javascript">
11
12 /*
13 var test_data = {
14 'by': {
15 '33': 1,
16 '28': 1,
17 '7': 2,
18 '91': 1,
19 '78': 2,
20 '8': 1,
21 '1': 2,
22 '16': 1,
23 '23': 1,
24 '100': 1,
25 '65': 1
26 },
27 'voice.': {
28 '80': 1
29 }
30 };
31 */
32
33 function get_div(name) {
34 var div = document.getElementById(name);
35 if (! div) alert("can't find div "+name);
36 return div;
37 }
38
39 var good_div = null;
40 var bad_div = null;
41 var test_div = null;
42
43
44 var results_output = '';
45 var debug_output = '';
46 var test_ok = 0;
47 var test_error = 0;
48 var test_failed = false;
49
50 var word_nr = -1; // first emement is word_nr++
51 var words = Array();
52
53
54 function debug(msg) {
55 debug_output += msg+"<br/>\n";
56 test_div.innerHTML += msg+'<br/>';
57 return;
58 }
59
60 function msg_error(msg) {
61 debug('<span style="color: red;">'+msg+'</span>');
62 bad_div.innerHTML += '<span style="color: red;">'+msg+'</span><br/>';
63 test_error++;
64 test_failed = true;
65 return true;
66 }
67
68 function msg_ok(msg) {
69 debug('<span style="color: green;">'+msg+'</span>');
70 good_div.innerHTML += '<span style="color: green;">'+msg+'</span><br/>';
71 test_ok++;
72 return true;
73 }
74
75 function got_result(result) {
76 if (result.length < 0) {
77 msg_error("no results for word "+words[word_nr]);
78 }
79
80 var word = words[word_nr];
81 var len = 0;
82 for (var i in test_data[word]) len++;
83
84 if (result.length == len) {
85 msg_ok("found "+result.lengh+" results");
86 } else if ( result.length > len )
87 msg_error("too much results "+result.length+" > "+len)
88 else msg_error("too fiew results "+result.length+" < "+len);
89
90 for(var i=result.length-1; i>=0; i--) {
91 var test_hit = i+": <em>"+
92 result[i].title+"</em> * <tt>"+
93 result[i].link+"</tt> * "+
94 result[i].frequency;
95
96 if ( test_data[ words[word_nr] ][ result[i].link ] != result[i].frequency ) {
97 msg_error("error in frequency for word: <b>"+words[word_nr]+"</b> [hit "+i+"] "+test_data[ words[word_nr] ][ result[i].link ]+" != "+result[i].frequency+"<br/>"+test_hit);
98
99 results_output += test_hit;
100 } else {
101 debug(words[word_nr]+" "+i+" "+result[i].frequency);
102 }
103
104 }
105
106 // try next search
107 if (word_nr < words.length) do_search();
108
109 return true;
110 }
111
112 function do_test() {
113
114 good_div = get_div('good');
115 bad_div = get_div('bad');
116 test_div = get_div('debug');
117
118 var test_words = 0;
119
120 for (word in test_data) {
121 words[test_words] = word;
122 debug("word "+test_words+" is <b>"+words[test_words]+"</b>");
123 test_words++;
124 }
125
126 do_search();
127 }
128
129
130 function do_search() {
131
132 word_nr++;
133
134 if (word_nr < words.length && words[word_nr] != 'undefined') {
135
136 results_output = '';
137 debug_output = '';
138 test_failed = false;
139
140 debug("search for "+words[word_nr]+" ["+word_nr+"]");
141
142 doSearch('homer', words[word_nr], got_result);
143
144
145 if (1 || test_failed) {
146 if (test_div) test_div.innerHTML += debug_output + results_output;
147 } else {
148 if (test_div) test_div.innerHTML += debug_output;
149 }
150
151 } else {
152 test_div.innerHTML += "<hr/>tested "+word_nr+" words, "+test_ok+" test passed, "+test_error+" test failed.<hr/>";
153 }
154 }
155
156 </script>
157 </head>
158
159 <body onLoad="do_test();">
160
161 <div style="color: blue;">
162 This is test html for jsFind -- it might take a long time on slower
163 computers and/or browsers, so please be patient!
164 </div>
165
166 <div id="good" style="border: 1px solid green; width: 30%; float: left;">
167 </div>
168
169 <div id="bad" style="border: 1px solid red; width: 30%; float: right;">
170 </div>
171
172 <div id="debug" style="color: gray;">
173 </div>
174
175 </body>
176 </html>

  ViewVC Help
Powered by ViewVC 1.1.26