00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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);
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);
00060
00061 }
00062 #endif