home *** CD-ROM | disk | FTP | other *** search
- -- $Source: /home/harp/1/proto/monoBANK/winnt/test_search.adb,v $
- -- $Revision: 1.2 $ $Date: 95/02/02 15:50:59 $ $Author: mg $
- -------------------------------------------------------------------------------
- --
- -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT
- -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- -- PURPOSE. The user assumes the entire risk as to the accuracy and the
- -- use of this file.
- --
- -- Copyright (c) Intermetrics, Inc. 1995
- -- Royalty-free, unlimited, worldwide, non-exclusive use, modification,
- -- reproduction and further distribution of this file is permitted.
- --
- -------------------------------------------------------------------------------
-
-
- with Text_IO;
- with Win32.Search;
-
- procedure Test_Search is
- use Text_IO;
-
- type Arr is array(Natural range <>)of aliased integer;
-
- function Rand return Integer;
- pragma Import(C, rand, "rand");
-
- A: Arr(2..11) := (others => rand);
-
- package S is new Win32.Search(Integer, Natural, Integer'Last, Arr, "<");
- junk,
- res: integer;
-
- procedure Print is
- begin
- for I in A'range loop
- put_line(integer'image(A(i)));
- end loop;
- new_line;
- end Print;
-
- begin
- new_line;
- put_line("Original array");
- print;
- s.qsort(A);
- put_line("Sorted array");
- print;
-
- put("binary search for" & integer'image(A(5)));
- s.bsearch(A(5), A, res);
- put_line(" =" & integer'image(res));
- put_line("(should be 5)");
- new_line;
-
- put("linear search with lfind for" & integer'image(A(7)));
- s.lfind(A(7), A, res);
- put_line(" =" & integer'image(res));
- put_line("(should be 7)");
- new_line;
-
- junk := rand;
- put("linear search with lfind for" & integer'image(junk));
- s.lfind(junk, A, res);
- put_line(" =" & integer'image(res));
- put_line("(should be" & integer'image(integer'last) & ")");
- new_line;
-
- put("linear search with lsearch for" & integer'image(A(9)));
- s.lsearch(A(9), A, A'Last, res);
- put_line(" =" & integer'image(res));
- put_line("(should be 9)");
- new_line;
-
- junk := rand;
- put("linear search with lsearch for" & integer'image(junk));
- s.lsearch(junk, A, A'Last-1, res);
- put_line(" =" & integer'image(res));
- put_line("(should be" & integer'image(A'last) & ")");
- put_line("A(A'last) =" & integer'image(A(A'last)));
- put_line("(should be" & integer'image(junk) & ")");
- new_line;
-
- junk := rand;
- put_line("linear search with lsearch for" & integer'image(junk));
- put("(should raise constraint_error)");
- s.lsearch(junk, A, A'Last, res);
- put_line("error - constraint_error wasn't raised!");
- end Test_Search;
-