/[eiffelstudio]/branches/eth/eve/Src/compatible/library/i18n/tests/test_files/Dictionary/i18n_test_dictionary.e
ViewVC logotype

Contents of /branches/eth/eve/Src/compatible/library/i18n/tests/test_files/Dictionary/i18n_test_dictionary.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92964 - (show annotations)
Fri Sep 20 05:41:23 2013 UTC (6 years ago) by jasonw
File size: 14198 byte(s)
<<Merged from trunk#92963.>>
1 note
2 description : "System's root class"
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 I18N_TEST_DICTIONARY
10
11 inherit
12 I18N_PLURAL_TOOLS
13 undefine
14 default_create
15 end
16
17 EQA_SYSTEM_TEST_SET
18
19 I18N_TEST_UTILITIES
20 undefine
21 default_create
22 end
23
24 feature -- Tests
25
26 test_dictionary
27 local
28 l_dic: I18N_DICTIONARY
29 do
30 create {I18N_CHARACTER_BASED_DICTIONARY} l_dic.make (two_plural_forms_singular_one)
31 make (l_dic, two_plural_forms_singular_one, 1, 100)
32
33 create {I18N_CHARACTER_BASED_DICTIONARY} l_dic.make (two_plural_forms_singular_one)
34 make (l_dic, two_plural_forms_singular_one, 50, 100)
35
36 create {I18N_HASH_TABLE_DICTIONARY} l_dic.make (two_plural_forms_singular_one)
37 make (l_dic, two_plural_forms_singular_one, 50, 100)
38
39 create {I18N_HASH_TABLE_DICTIONARY} l_dic.make (two_plural_forms_singular_one_zero)
40 make (l_dic, two_plural_forms_singular_one_zero, 50, 100)
41
42 create {I18N_BINARY_SEARCH_ARRAY_DICTIONARY} l_dic.make (two_plural_forms_singular_one)
43 make (l_dic, two_plural_forms_singular_one, 50, 100)
44
45 create {I18N_BINARY_SEARCH_ARRAY_DICTIONARY} l_dic.make (two_plural_forms_singular_one_zero)
46 make (l_dic, two_plural_forms_singular_one_zero, 50, 100)
47 end
48
49 feature {NONE} -- Initialization
50
51 make(t:I18N_DICTIONARY; plural_form,datalength,seed:INTEGER)
52 -- Creation procedure.
53 do
54 set_current_folder(t,plural_form,datalength,seed)
55 data_generation(t,datalength,seed)
56 data_query(t,datalength,seed)
57 data_get(t,datalength,seed)
58 if not current_folder.is_closed then
59 current_folder.close
60 end
61 end
62
63 result_file_name (t:I18N_DICTIONARY;plural_form,datalength,seed:INTEGER; a_name: STRING): STRING
64 -- This is a hack, since no such facility found in the testing framework, for a file name located in the source class directory.
65 do
66 Result := environment.get ("ISE_LIBRARY").twin
67 Result.append_character (Operating_environment.directory_separator)
68 Result.append ("library")
69 Result.append_character (Operating_environment.directory_separator)
70 Result.append ("i18n")
71 Result.append_character (Operating_environment.directory_separator)
72 Result.append ("tests")
73 Result.append_character (Operating_environment.directory_separator)
74 Result.append ("test_files")
75 Result.append_character (Operating_environment.directory_separator)
76 Result.append ("Dictionary")
77 Result.append_character (Operating_environment.directory_separator)
78 Result.append (directory_name (t, plural_form, datalength, seed))
79 Result.append_character (Operating_environment.directory_separator)
80 Result.append (a_name)
81 end
82
83 feature {NONE} -- set current_folder
84
85 directory_name (t:I18N_DICTIONARY;plural_form,datalength,seed:INTEGER): STRING
86 do
87 Result := t.generating_type + "_PF"+plural_form.out+"_LEN"+datalength.out+"_S"+seed.out
88 end
89
90 set_current_folder (t:I18N_DICTIONARY;plural_form,datalength,seed:INTEGER)
91 -- check the type of t and create new folder in the relevant folder
92 -- this class could be extended when a new dictionary structure is added
93 -- need plural_form, datalength and seed to make directory uniq
94 do
95 attr_plural_form := plural_form
96 create current_folder.make(current_folder_string
97 +directory_name (t, plural_form, datalength, seed))
98 if not current_folder.exists then
99 current_folder.create_dir
100 end
101 end
102
103 feature {NONE} -- Data generation
104
105 data_generation(t:I18N_DICTIONARY; datalength,seed:INTEGER)
106 -- generate array of `I18N_DICTIONARY_ENTRY' and fill it in `t'
107 -- fill 't' with datalength of `I18N_DICTIONARY_ENTRY'
108 local
109 entry:I18N_DICTIONARY_ENTRY
110 random:RANDOM
111 i:INTEGER
112 singular:STRING_GENERAL
113 translated_singular, original_plural: STRING_GENERAL
114 file: PLAIN_TEXT_FILE
115 l_name, l_generated_name: STRING
116 l_fn: STRING
117 do
118 l_fn := "data_file"
119 create random.set_seed (seed)
120 l_generated_name := current_folder.name+Operating_environment.Directory_separator.out+l_fn
121 create file.make_create_read_write (l_generated_name)
122 from
123 i:=1
124 random.start
125 until
126 i>datalength
127 loop
128 --generate a `entry' for its first three items
129 singular:=random.item.out
130 random.forth
131 translated_singular:=random.item.out
132 random.forth
133 original_plural:=random.item.out
134 create entry.make_with_plural (singular, translated_singular, original_plural)
135
136 --fill a `entry' with plural translations
137 -- are added by hand!
138
139 random.forth
140 entry.plural_translations.enter (random.item.out, 0) -- plural translation 0
141 random.forth
142 entry.plural_translations.enter (random.item.out, 1) -- plural translation 1
143 random.forth
144 entry.plural_translations.enter (random.item.out, 2) -- plural translation 2
145 random.forth
146 entry.plural_translations.enter (random.item.out, 3) -- plural translation 3
147
148
149 --put `entry' in datastructure
150 t.extend (entry)
151
152 -- fill the `file' with the entry
153 file.put_string ("entry "+i.out+": %N%
154 %original_singular: "+entry.original_singular.out+"%N%
155 %original_plural: "+entry.original_plural.out+"%N%
156 %singular_translation: "+entry.singular_translation.out+"%N%
157 %plural_translations: (0) "+entry.plural_translations.item (0)+
158 " (1) "+entry.plural_translations.item (1)+
159 " (2) "+entry.plural_translations.item (2)+
160 " (3) "+entry.plural_translations.item (3)+"%N")
161
162 -- to continue the loop
163 i:=i+1
164 random.forth
165 end
166 io.put_string ("data generation is finished")
167 io.put_new_line
168 file.close
169
170 l_name := result_file_name (t, attr_plural_form, datalength, seed, l_fn)
171 assert ("Output does not match!", has_same_content_as_path (l_name, l_generated_name))
172 end
173
174
175 data_query(t:I18N_DICTIONARY; datalength,seed:INTEGER)
176 -- check all query functions in `I18N_DICTIONARY': `has, has_plural'
177 -- check all data for every function
178 -- use `random' with same `seed' to check whether they are in `t', one could also use a `linked_list'
179 -- to store the data in `data_generation' then use it here to check
180 -- use `random' with another `seed' to check whether they are not in `t'
181 -- the data_file could also be used, not try it yet
182 local
183 i,j: INTEGER
184 singular: STRING_GENERAL
185 translated_singular, original_plural: STRING_GENERAL
186 random: RANDOM
187 output_file: PLAIN_TEXT_FILE
188
189 l_name, l_generated_name: STRING
190 l_fn: STRING
191 do
192 l_fn := "query_yes_file"
193 create random.set_seed (seed)
194 l_generated_name := current_folder.name+Operating_environment.Directory_separator.out+l_fn
195 create output_file.make_create_read_write (l_generated_name)
196 from
197 i:=1
198 random.start
199 until
200 i > datalength
201 loop
202 singular:=random.item.out
203 random.forth
204 translated_singular:=random.item.out
205 random.forth
206 original_plural:=random.item.out
207 output_file.put_string ("query "+i.out+": %N")
208 if t.has (singular) then
209 output_file.put_string ("data structure has("+singular.out+")%N")
210 else
211 output_file.put_string ("data structure do not has("+singular.out+")%N")
212 end
213
214 -- `plural_number'>=0
215
216 from
217 j:=0
218 until
219 j>10
220 loop
221 if t.has_plural (singular,original_plural, j.as_integer_32) then
222 output_file.put_string ("data structure has_plural with plural_number: "+j.out+"%N")
223 else
224 output_file.put_string ("data structure do not has_plural with plural_number: "+j.out+"%N")
225 end
226 j:=j+1
227 end
228
229 -- to skip the four elements in plural translations
230 random.forth
231 random.forth
232 random.forth
233 random.forth
234
235 -- to continue the loop
236 random.forth
237 i:=i+1
238 end
239 output_file.close
240 l_name := result_file_name (t, attr_plural_form, datalength, seed, l_fn)
241 assert ("Output does not match!", has_same_content_as_path (l_name, l_generated_name))
242
243 -- query with its non-existent elems
244
245 l_fn := "query_non_file"
246 create random.set_seed (seed+1)
247 l_generated_name := current_folder.name+Operating_environment.Directory_separator.out+l_fn
248 create output_file.make_create_read_write (l_generated_name)
249 from
250 i:=1
251 random.start
252 until
253 i > datalength
254 loop
255 singular:=random.item.out
256 random.forth
257 translated_singular:=random.item.out
258 random.forth
259 original_plural:=random.item.out
260 output_file.put_string ("query "+i.out+": %N")
261 if t.has (singular) then
262 output_file.put_string ("data structure has("+singular.out+")%N")
263 else
264 output_file.put_string ("data structure do not has("+singular.out+")%N")
265 end
266
267
268 -- `plural_number'>=0
269
270 from
271 j:=0
272 until
273 j>10
274 loop
275 if t.has_plural (singular,original_plural, j.as_integer_32) then
276 output_file.put_string ("data structure has_plural with plural_number: "+j.out+"%N")
277 else
278 output_file.put_string ("data structure do not has_plural with plural_number: "+j.out+"%N")
279 end
280 j:=j+1
281 end
282
283 -- to continue the loop
284 random.forth
285 i:=i+1
286 end
287 output_file.close
288 l_name := result_file_name (t, attr_plural_form, datalength, seed, l_fn)
289 assert ("Output does not match!", has_same_content_as_path (l_name, l_generated_name))
290 io.put_string ("data query is finished%N")
291 end
292
293 feature {NONE} -- Data access
294
295 data_get(t:I18N_DICTIONARY; datalength,seed:INTEGER)
296 -- check data access functions in `I18N_DICTIONARY': `get_plural, get_sigular'
297 -- use 'random' with same `seed' to get them out
298 -- use 'random' with another `seed' get nothing out
299 -- again `linked_list' to store the data in `data_generation' could be comfortable
300 -- the data_file could also be used, not try it yet
301 local
302 i,j: INTEGER
303 singular: STRING_GENERAL
304 translated_singular, original_plural: STRING_GENERAL
305 random: RANDOM
306 output_file: PLAIN_TEXT_FILE
307
308 l_name, l_generated_name: STRING
309 l_fn: STRING
310 do
311 -- get data with its existent elems
312 l_fn := "get_data_file"
313 create random.set_seed (seed)
314 l_generated_name := current_folder.name+Operating_environment.Directory_separator.out+l_fn
315 create output_file.make_create_read_write (l_generated_name)
316 from
317 i:=1
318 random.start
319 until
320 i > datalength
321 loop
322 singular:=random.item.out
323 random.forth
324 translated_singular:=random.item.out
325 random.forth
326 original_plural:=random.item.out
327 output_file.put_string ("get data iteration " + i.out + ": " + "%N")
328
329 if t.has (singular) then
330 output_file.put_string ("get_singular(" + singular.as_string_8 + "): "+ t.singular (singular)+"%N")
331 else
332 output_file.put_string ("not has(" + singular.as_string_8 + "): "+ "%N")
333 end
334
335
336 -- i think `plural_number' could be 0,1,2,3
337 -- or 1 2 3 4, i do not know, try them all
338 -- actually plural_number >=0
339 from
340 j:=0
341 until
342 j>10
343 loop
344 if t.has_plural (singular,original_plural, j.as_integer_32) then
345 output_file.put_string ("get_plural (" + singular.as_string_8 + ","
346 + original_plural.as_string_8 + "," + j.out +"): "
347 + t.plural (singular, original_plural, j.as_integer_32)+"%N")
348
349 else
350
351 output_file.put_string (" not has_plural (" + singular.as_string_8 + ","
352 + original_plural.as_string_8 + "," + j.out +") %N ")
353 end
354 j:=j+1
355 end
356
357 -- to skip the four elements in plural translations
358 random.forth
359 random.forth
360 random.forth
361 random.forth
362
363 -- to continue the loop
364 random.forth
365 i:=i+1
366 end
367 output_file.close
368
369 l_name := result_file_name (t, attr_plural_form, datalength, seed, l_fn)
370 assert ("Output does not match!", has_same_content_as_path (l_name, l_generated_name))
371
372 -- get data with its non-existent elems
373 -- actually we could only get data with its existence
374
375 l_fn := "get_data_non_file"
376 create random.set_seed (seed+1)
377 l_generated_name := current_folder.name+Operating_environment.Directory_separator.out+l_fn
378 create output_file.make_create_read_write (l_generated_name)
379 from
380 i:=1
381 random.start
382 until
383 i > datalength
384 loop
385 singular:=random.item.out
386 random.forth
387 translated_singular:=random.item.out
388 random.forth
389 original_plural:=random.item.out
390 output_file.put_string ("get_data_iteration " + i.out + ": " + "%N")
391
392
393 if t.has (singular) then
394 output_file.put_string ("get_singular(" + singular.as_string_8 + "): "+ t.singular (singular)+"%N")
395 else
396 output_file.put_string (" not has_singular(" + singular.as_string_8 + ") %N ")
397 end
398
399 -- i think `plural_number' could be 0,1,2,3
400 -- or 1 2 3 4, i do not know, try them all
401 -- actually plural_number >=0
402 from
403 j:=0
404 until
405 j>10
406 loop
407 if t.has_plural (singular,original_plural, j.as_integer_32) then
408 output_file.put_string ("get_plural (" + singular.as_string_8 + "," + original_plural.as_string_8 + "," + j.out +"): "
409 + t.plural (singular, original_plural, j.as_integer_32)+"%N")
410
411 else
412
413 output_file.put_string (" not has_plural (" + singular.as_string_8 + "," + original_plural.as_string_8 + "," + j.out +")%N")
414
415 end
416 j:=j+1
417 end
418
419 -- to continue the loop
420 random.forth
421 i:=i+1
422 end
423 output_file.close
424
425 l_name := result_file_name (t, attr_plural_form, datalength, seed, l_fn)
426 assert ("Output does not match!", has_same_content_as_path (l_name, l_generated_name))
427
428 io.put_string ("data_get is finished")
429 end
430 feature {NONE} -- access
431 attr_plural_form: INTEGER
432 current_folder: DIRECTORY
433 current_folder_string: STRING_8
434 do
435 result :=Operating_environment.Current_directory_name_representation+
436 Operating_environment.Directory_separator.out
437 end
438
439
440 note
441 library: "Internationalization library"
442 copyright: "Copyright (c) 1984-2010, Eiffel Software and others"
443 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
444 source: "[
445 Eiffel Software
446 5949 Hollister Ave., Goleta, CA 93117 USA
447 Telephone 805-685-1006, Fax 805-685-6869
448 Website http://www.eiffel.com
449 Customer support http://support.eiffel.com
450 ]"
451
452
453
454
455 end -- class DICTIONARY_TEST

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23