Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include "dictionary.h"
- #define SIZE 1000
- void showDictionary(Dictionary* dictionary) {
- printf("Size: %d\nDictionary: ", sizeOfDictionary(dictionary));
- printDictionary(dictionary);
- printf("\n");
- }
- void doWait() {
- char c;
- do {
- printf("Enter ENTER to continue..\n");
- c = getchar();
- } while (c != '\n');
- }
- void failTests() {
- Dictionary* dictionary;
- printf("This section is fail tests, comment it out from main if you want to continue\n");
- getFromDictionary(dictionary,1);
- removeFromDictionary(dictionary,1);
- showDictionary(dictionary);
- putInDictionary(dictionary,1,1);
- destroyDictionary(dictionary);
- }
- void main() {
- // failTests();
- Dictionary* dictionary;
- int keys[SIZE];
- int values[SIZE];
- int randKey = rand() % 1000;
- printf("First test: creating dictionary from large arrays (%d)\n\n",SIZE);
- doWait();
- for (int i = 0; i < SIZE; i++) {
- keys[i] = i;
- values[i] = rand() % 1000;
- }
- dictionary = createDictionaryFromArrays(keys,values,SIZE);
- showDictionary(dictionary);
- printf("Random fetch:\nKey: %d Value: %d\n",randKey,getFromDictionary(dictionary,randKey));
- destroyDictionary;
- printf("\n\nSecond test: creating dictionary from large inputs (%d)\n\n",SIZE);
- doWait();
- randKey = rand() % 1000;
- dictionary = initDictionary();
- for (int i = 0; i < SIZE; i++)
- putInDictionary(dictionary,i,rand() % 1000);
- showDictionary(dictionary);
- printf("Random fetch:\nKey: %d Value: %d\n",randKey,getFromDictionary(dictionary,randKey));
- printf("\n\nThird test: Adding and removing large inputs (positive and negetives) (%d)\n\n",SIZE);
- doWait();
- randKey = rand() % 1000;
- dictionary = initDictionary();
- printf("Insertion\n\n\n");
- for (int i = - (SIZE / 2); i < (SIZE / 2); i++)
- putInDictionary(dictionary,i,rand() % 1000);
- showDictionary(dictionary);
- printf("\n\n\nDeletion\n\n\n");
- for (int i = - (SIZE / 2); i < (SIZE / 2); i++) {
- printf("Removing %d\n",i);
- removeFromDictionary(dictionary,i);
- }
- showDictionary(dictionary);
- printf("Random fetch:\nKey: %d Value: %d\n",randKey,getFromDictionary(dictionary,randKey));
- destroyDictionary;
- printf("\n\nForth test: invalid insertions and deletions (Some are commented out at main, check them out)\n\n");
- doWait();
- dictionary = initDictionary();
- showDictionary(dictionary);
- randKey = rand() % 1000;
- int result = getFromDictionary(dictionary,randKey);
- printf("Value for (key) %d: %d\n",randKey,result);
- (result) ? printf("Failed\n") : printf("Passed\n");
- result = removeFromDictionary(dictionary,randKey);
- printf("Removing (key) %d\nResult = %d\n",randKey,result);
- (result != 1) ? printf("Failed\n") : printf("Passed\n");
- putInDictionary(dictionary,1,1);
- showDictionary(dictionary);
- result = removeFromDictionary(dictionary,2);
- printf("Removing (key) %d\nResult = %d\n",2,result);
- (result != 1) ? printf("Failed\n") : printf("Passed\n");
- showDictionary(dictionary);
- destroyDictionary;
- printf("\n\nFifth test: Rapid massive insertion and deletion of elements (%d))\n\n",SIZE);
- doWait();
- dictionary = initDictionary();
- for (int i = 0; i < SIZE; i++) {
- printf("Inserting 1\n");
- putInDictionary(dictionary,1,1);
- printf("Deleting 1\n");
- removeFromDictionary(dictionary,1);
- showDictionary(dictionary);
- }
- destroyDictionary;
- printf("\n\nSixth test: changing the same key multiple times (%d))\n\n",SIZE);
- doWait();
- dictionary = initDictionary();
- randKey = rand() % 1000;
- for (int i = 0; i < SIZE; i++) {
- putInDictionary(dictionary,randKey,rand() % 1000);
- showDictionary(dictionary);
- }
- destroyDictionary;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement