home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / test_search.adb < prev    next >
Encoding:
Text File  |  1995-12-07  |  2.8 KB  |  91 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/test_search.adb,v $ 
  2. -- $Revision: 1.2 $ $Date: 95/02/02 15:50:59 $ $Author: mg $ 
  3. -------------------------------------------------------------------------------
  4. --
  5. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  6. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  7. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  8. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  9. -- use of this file.
  10. --
  11. -- Copyright (c) Intermetrics, Inc. 1995
  12. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  13. -- reproduction and further distribution of this file is permitted.
  14. --
  15. -------------------------------------------------------------------------------
  16.  
  17.  
  18. with Text_IO;
  19. with Win32.Search;
  20.  
  21. procedure Test_Search is
  22.     use Text_IO;
  23.  
  24.     type Arr is array(Natural range <>)of aliased integer;
  25.  
  26.     function Rand return Integer;
  27.     pragma Import(C, rand, "rand");
  28.  
  29.     A: Arr(2..11) := (others => rand);
  30.  
  31.     package S is new Win32.Search(Integer, Natural, Integer'Last, Arr, "<");
  32.     junk,
  33.     res: integer;
  34.  
  35.     procedure Print is
  36.     begin
  37.         for I in A'range loop
  38.             put_line(integer'image(A(i)));
  39.         end loop;
  40.         new_line;
  41.     end Print;
  42.  
  43. begin
  44.     new_line;
  45.     put_line("Original array");
  46.     print;
  47.     s.qsort(A);
  48.     put_line("Sorted array");
  49.     print;
  50.  
  51.     put("binary search for" & integer'image(A(5)));
  52.     s.bsearch(A(5), A, res);
  53.     put_line(" =" & integer'image(res));
  54.     put_line("(should be 5)");
  55.     new_line;
  56.  
  57.     put("linear search with lfind for" & integer'image(A(7)));
  58.     s.lfind(A(7), A, res);
  59.     put_line(" =" & integer'image(res));
  60.     put_line("(should be 7)");
  61.     new_line;
  62.  
  63.     junk := rand;
  64.     put("linear search with lfind for" & integer'image(junk));
  65.     s.lfind(junk, A, res);
  66.     put_line(" =" & integer'image(res));
  67.     put_line("(should be" & integer'image(integer'last) & ")");
  68.     new_line;
  69.  
  70.     put("linear search with lsearch for" & integer'image(A(9)));
  71.     s.lsearch(A(9), A, A'Last, res);
  72.     put_line(" =" & integer'image(res));
  73.     put_line("(should be 9)");
  74.     new_line;
  75.  
  76.     junk := rand;
  77.     put("linear search with lsearch for" & integer'image(junk));
  78.     s.lsearch(junk, A, A'Last-1, res);
  79.     put_line(" =" & integer'image(res));
  80.     put_line("(should be" & integer'image(A'last) & ")");
  81.     put_line("A(A'last) =" & integer'image(A(A'last)));
  82.     put_line("(should be" & integer'image(junk) & ")");
  83.     new_line;
  84.  
  85.     junk := rand;
  86.     put_line("linear search with lsearch for" & integer'image(junk));
  87.     put("(should raise constraint_error)");
  88.     s.lsearch(junk, A, A'Last, res);
  89.     put_line("error - constraint_error wasn't raised!");
  90. end Test_Search;
  91.