You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
5 months ago
|
// hash_test.c
|
||
|
#include "../include/hash.h"
|
||
|
#include <stdio.h>
|
||
|
typedef struct test
|
||
|
{
|
||
|
char *name;
|
||
|
}test;
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
test *test1 = malloc(sizeof(test));
|
||
|
test *test2 = malloc(sizeof(test));
|
||
|
test1->name = "test1";
|
||
|
test2->name = "test2";
|
||
|
HashTable *myTable = create_table();
|
||
|
add_item(myTable, "key1", test1);
|
||
|
add_item(myTable, "key2", test2);
|
||
|
char *input = argv[1];
|
||
|
test *value = find_value(myTable, input);
|
||
|
if (value) {
|
||
|
printf("Test Passed: %s\n", value->name);
|
||
|
} else {
|
||
|
printf("Test Failed: Key not found.\n");
|
||
|
}
|
||
|
remove_item(myTable, "key1");
|
||
|
printf("remove key1.\n");
|
||
|
test *value2 = find_value(myTable, input);
|
||
|
if (value2) {
|
||
|
printf("Test Passed: %s\n", value2->name);
|
||
|
} else {
|
||
|
printf("Test Failed: Key not found.\n");
|
||
|
}
|
||
|
add_item(myTable, "key1", test1);
|
||
|
test *value4 = find_value(myTable, "key1");
|
||
|
if (value4) {
|
||
|
printf("Test Passed: %s\n", value4->name);
|
||
|
} else {
|
||
|
printf("Test Failed: Key not found.\n");
|
||
|
}
|
||
|
test *value3 = find_value(myTable, "key2");
|
||
|
if (value3) {
|
||
|
printf("Test Passed: %s\n", value3->name);
|
||
|
} else {
|
||
|
printf("Test Failed: Key not found.\n");
|
||
|
}
|
||
|
free(test1);
|
||
|
free(test2);
|
||
|
free_table(myTable);
|
||
|
return 0;
|
||
|
}
|