Page principale | Liste des namespaces | Hiérarchie des classes | Liste des classes | Répertoires | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

libtest.cc

Aller à la documentation de ce fichier.
00001 // libtest.cc 
00002 //      Driver code to call self-test routines for standard library
00003 //      classes -- bitmaps, lists, sorted lists, and hash tables.
00004 //
00005 // Copyright (c) 1992-1996 The Regents of the University of California.
00006 // All rights reserved.  See copyright.h for copyright notice and limitation 
00007 // of liability and disclaimer of warranty provisions.
00008 
00009 #include "copyright.h"
00010 #include "libtest.h"
00011 #include "bitmap.h"
00012 #include "list.h"
00013 #include "hash.h"
00014 #include "sysdep.h"
00015 
00016 //----------------------------------------------------------------------
00017 // IntCompare
00018 //      Compare two integers together.  Serves as the comparison
00019 //      function for testing SortedLists
00020 //----------------------------------------------------------------------
00021 
00022 static int 
00023 IntCompare(int x, int y) {
00024     if (x < y) return -1;
00025     else if (x == y) return 0;
00026     else return 1;
00027 }
00028 
00029 //----------------------------------------------------------------------
00030 // HashInt, HashKey
00031 //      Compute a hash function on an integer.  Serves as the
00032 //      hashing function for testing HashTables.
00033 //----------------------------------------------------------------------
00034 
00035 static unsigned int 
00036 HashInt(int key) {
00037     return (unsigned int) key;
00038 }
00039 
00040 //----------------------------------------------------------------------
00041 // HashKey
00042 //      Convert a string into an integer.  Serves as the function
00043 //      to retrieve the key from the item in the hash table, for
00044 //      testing HashTables.  Should be able to use "atoi" directly,
00045 //      but some compilers complain about that.
00046 //----------------------------------------------------------------------
00047 
00048 static int 
00049 HashKey(char *str) {
00050     return atoi(str);
00051 }
00052 
00053 // Array of values to be inserted into a List or SortedList. 
00054 static int listTestVector[] = { 9, 5, 7 };
00055 
00056 // Array of values to be inserted into the HashTable
00057 // There are enough here to force a ReHash().
00058 static char *hashTestVector[] = { "0", "1", "2", "3", "4", "5", "6",
00059          "7", "8", "9", "10", "11", "12", "13", "14"};
00060 
00061 //----------------------------------------------------------------------
00062 // LibSelfTest
00063 //      Run self tests on bitmaps, lists, sorted lists, and 
00064 //      hash tables.
00065 //----------------------------------------------------------------------
00066 
00067 void
00068 LibSelfTest () {
00069     Bitmap *map = new Bitmap(200);
00070     List<int> *list = new List<int>;
00071     SortedList<int> *sortList = new SortedList<int>(IntCompare);
00072     HashTable<int, char *> *hashTable = 
00073         new HashTable<int, char *>(HashKey, HashInt);
00074         
00075                 
00076     map->SelfTest();
00077     list->SelfTest(listTestVector, sizeof(listTestVector)/sizeof(int));
00078     sortList->SelfTest(listTestVector, sizeof(listTestVector)/sizeof(int));
00079     hashTable->SelfTest(hashTestVector, sizeof(hashTestVector)/sizeof(char *));
00080 
00081     delete map;
00082     delete list;
00083     delete sortList;
00084     delete hashTable;
00085 }

Généré le Sun Jan 15 00:45:45 2006 pour Système NachOS : par  doxygen 1.4.4