Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

simplehash.cc

Go to the documentation of this file.
00001 /** @file simplehash.cc */
00002 /* 
00003  * Copyright (C) 2002 Laird Breyer
00004  *  
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * 
00019  * Author:   Laird Breyer <laird@lbreyer.com>
00020  */
00021 
00022 #include "simplehash.h"
00023 #include <iostream>
00024 
00025 #ifdef UNIT_TEST
00026 
00027 #define MAKE_STATEMENT(x) \
00028 do { \
00029   cout << "argv[0]: testing " #x << endl; \
00030   cout << "output: " << endl; \
00031   (x); \
00032 } while(false)
00033 
00034 #define MAKE_TEST(x,y) \
00035 do { \
00036    cout << argv[0] << ": " << (((x) == (y)) ? "PASSED" : "FAILED") << " " #x <<endl; \
00037 } while(false)
00038 
00039 #define MAKE_TEST_EX(x,y) \
00040 do { \
00041    try { \
00042      (x); \
00043      cout << argv[0] << ": FAILED" << " " #x << endl; \
00044    } catch (y) { \
00045      cout << argv[0] << ": PASSED" << " " #x << endl; \
00046    } \
00047 } while(false)
00048 
00049 int main(int argc, char** argv) {
00050   
00051   SimpleHashTable<char*> *sha = new SimpleHashTable<char*>(5);
00052   
00053   MAKE_TEST(sha->Insert(1,"banana"),true);
00054   MAKE_TEST(sha->Insert(2,"apple"),true);
00055   MAKE_TEST(sha->Insert(2,"green apple"),false); // duplicate key
00056   MAKE_TEST(sha->Insert(3,"orange"),true);
00057   MAKE_TEST(sha->Insert(4,"kiwi"),true);
00058   MAKE_TEST(sha->Insert(5,"cherry"),true);
00059   MAKE_TEST_EX(sha->Insert(5,"pineapple"),overflow_error); // table overflow
00060 
00061 }
00062 #endif

Generated on Wed May 29 11:37:15 2002 for MarkovPR by doxygen1.2.15