Skip to content

Commit

Permalink
Final changes. Renaming to conventions. Everything working perfectly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Earqee committed May 20, 2018
1 parent 8556d45 commit 2c278f9
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 84 deletions.
Binary file added a.out
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 15 additions & 21 deletions hash_test.c
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"
#include "header.h"

#define GENERIC void*
#define INTEGER long int
#include "hash.h"

HASH* build_hash_for_test ()
HASH* Build_Hash_For_Test ()
{
HASH* hash = HASH_Create ();
HASH* hash = HASH_Create ();

HASH_Insert (hash, 10, 100);
HASH_Insert (hash, 'B', 150);
HASH_Insert (hash, 9, 9);
HASH_Insert (hash, 'F', 200);
HASH_Insert (hash, 10, 100);
HASH_Insert (hash, 'B', 150);
HASH_Insert (hash, 9, 9);
HASH_Insert (hash, 'F', 200);

return hash;

}

void test_hash_size ()
void Test_Hash_Size ()
{
HASH *hash = build_hash_for_test();
HASH *hash = Build_Hash_For_Test();
CU_ASSERT_EQUAL (HASH_Get_Size (hash), MAX_HASH_SIZE);
return;
}

void test_hash_elements ()
void Test_Hash_Elements ()
{
HASH *hash = build_hash_for_test();
HASH *hash = Build_Hash_For_Test();

CU_ASSERT_EQUAL (HASH_Get_hash_element(hash, 100), 10);
CU_ASSERT_EQUAL (HASH_Get_hash_element(hash, 150), 'B');
CU_ASSERT_EQUAL (HASH_Get_hash_element(hash, 9), 9);
CU_ASSERT_EQUAL (HASH_Get_hash_element(hash, 200), 'F');
return;
}

int main ()
Expand All @@ -49,8 +43,8 @@ int main ()
// Add a suite to the registry
hash_test_size = CU_add_suite ("Testing hash size", 0, 0);
hash_test_elements = CU_add_suite ("Testing hash elements", 0, 0);
CU_add_test (hash_test_size, "Testing hash size", test_hash_size);
CU_add_test (hash_test_elements, "Testing hash elements", test_hash_elements);
CU_add_test (hash_test_size, "Testing hash size", Test_Hash_Size);
CU_add_test (hash_test_elements, "Testing hash elements", Test_Hash_Elements);

// Sets the basic run mode, CU_BRM_VERBOSE will show maximum output of run details
// Other choices are: CU_BRM_SILENT and CU_BRM_NORMAL
Expand Down
16 changes: 16 additions & 0 deletions header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"

#define GENERIC void*
#define INTEGER long int

#define MAX_HEAP_SIZE (1 << 9)


#include "basic_structures/hash.h"
#include "basic_structures/tree.h"
#include "basic_structures/list.h"
#include "basic_structures/heap.h"
35 changes: 14 additions & 21 deletions heap_test.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"
#include "header.h"

#define GENERIC void*
#define INTEGER long int
#define MAX_HEAP_SIZE 10
#include "heap.h"

HEAP* build_heap_for_test ()
HEAP* Build_Heap_For_Test ()
{
HEAP* heap = HEAP_Create ();

Expand All @@ -21,23 +12,25 @@ HEAP* build_heap_for_test ()
return heap;
}

void test_heap_size ()
void Test_Heap_Size ()
{
HEAP *heap = build_heap_for_test();
HEAP *heap = Build_Heap_For_Test();
CU_ASSERT_EQUAL (HEAP_Get_Size (heap), 5);
return;
}

void test_heap_dequeue ()
void Test_Heap_Dequeue ()
{
HEAP *heap = build_heap_for_test();
HEAP *heap = Build_Heap_For_Test();
CU_ASSERT_EQUAL (HEAP_Dequeue(heap,is_greater),'A');

return;
}

void test_heap_parent ()
void Test_Heap_Parent ()
{
HEAP* heap = build_heap_for_test ();
HEAP* heap = Build_Heap_For_Test ();
CU_ASSERT_EQUAL (HEAP_Get_Data(heap, HEAP_Get_Parent(5)), 400);
return;
}

int main ()
Expand All @@ -55,9 +48,9 @@ int main ()
heap_test_dequeue = CU_add_suite ("Testing heap dequeue", 0, 0);
heap_test_parent = CU_add_suite ("Testing heap parent", 0, 0);

CU_add_test (heap_test_size, "Testing heap size", test_heap_size);
CU_add_test (heap_test_dequeue, "Testing heap dequeue", test_heap_dequeue);
CU_add_test (heap_test_parent, "Testing heap parent ", test_heap_parent);
CU_add_test (heap_test_size, "Testing heap size", Test_Heap_Size);
CU_add_test (heap_test_dequeue, "Testing heap dequeue", Test_Heap_Dequeue);
CU_add_test (heap_test_parent, "Testing heap parent ", Test_Heap_Parent);

// Sets the basic run mode, CU_BRM_VERBOSE will show maximum output of run details
// Other choices are: CU_BRM_SILENT and CU_BRM_NORMAL
Expand Down
28 changes: 10 additions & 18 deletions list_test.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"
#include "header.h"

#define GENERIC void*
#define INTEGER long int

#include "deque.h"


LIST* build_list_for_test ()
LIST* Build_List_For_Test ()
{
LIST* list = LIST_Create ();
LIST_Insert_Tail (list, 4);
Expand All @@ -21,21 +11,23 @@ LIST* build_list_for_test ()
return list;
}

void test_list_insert ()
void Test_List_Insert ()
{
LIST* list = build_list_for_test ();
LIST* list = Build_List_For_Test ();

CU_ASSERT_EQUAL (list->size, 4);
CU_ASSERT_EQUAL (list->head->data, 4);
CU_ASSERT_EQUAL (list->tail->data, 9);
return;
}

void test_list_remove ()
void Test_List_Remove ()
{
LIST* list = build_list_for_test ();
LIST* list = Build_List_For_Test ();

LIST_Remove_Tail (list);
CU_ASSERT_EQUAL (list->tail->data, 2);
return;
}

int main ()
Expand All @@ -50,8 +42,8 @@ int main ()
list_test_insert = CU_add_suite ("Testing List Insert", 0, 0);
list_test_remove = CU_add_suite ("Testing List Remove", 0 ,0);

CU_add_test (list_test_insert, "Testing List Insert", test_list_insert);
CU_add_test (list_test_remove, "Testing List Remove", test_list_remove);
CU_add_test (list_test_insert, "Testing List Insert", Test_List_Insert);
CU_add_test (list_test_remove, "Testing List Remove", Test_List_Remove);

// Sets the basic run mode, CU_BRM_VERBOSE will show maximum output of run details
// Other choices are: CU_BRM_SILENT and CU_BRM_NORMAL
Expand Down
40 changes: 16 additions & 24 deletions tree_test.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "CUnit/Basic.h"
#include "header.h"

#define GENERIC void*
#define INTEGER long int

#include "tree.h"

void test_tree_root ()
void Test_Tree_Root ()
{
BINARY_TREE* arv = BINARY_TREE_Create ();

arv->root = TREE_NODE_Create (3);
BINARY_TREE* tree = BINARY_TREE_Create ();

tree->root = TREE_NODE_Create (3);

CU_ASSERT_EQUAL (TREE_Get_Node_Data (arv->root), 3);
CU_ASSERT_EQUAL (TREE_Get_Node_Data (tree->root), 3);
return;
}

void test_tree_children()
void Test_Tree_Children()
{
BINARY_TREE* arv = BINARY_TREE_Create ();
BINARY_TREE* tree = BINARY_TREE_Create ();

arv->root = TREE_NODE_Create_Merged (TREE_NODE_Create(2), TREE_NODE_Create(1));
tree->root = TREE_NODE_Create_Merged (TREE_NODE_Create(2), TREE_NODE_Create(1));

printf("%d\n",arv->root->left->data);
printf("%d\n",arv->root->right->data);
printf("%d\n",tree->root->left->data);
printf("%d\n",tree->root->right->data);

CU_ASSERT_EQUAL (TREE_Get_Node_Data (arv->root->left), 1);
CU_ASSERT_EQUAL (TREE_Get_Node_Data (arv->root->right), 2);
CU_ASSERT_EQUAL (TREE_Get_Node_Data (tree->root->left), 1);
CU_ASSERT_EQUAL (TREE_Get_Node_Data (tree->root->right), 2);
return;
}

int main ()
Expand All @@ -44,8 +36,8 @@ int main ()
tree_test_root = CU_add_suite ("Testing tree root", 0, 0);
tree_test_children = CU_add_suite ("Testing tree root children", 0 ,0);

CU_add_test (tree_test_root, "Testing tree root", test_tree_root);
CU_add_test (tree_test_children, "Testing tree root children", test_tree_children);
CU_add_test (tree_test_root, "Testing tree root", Test_Tree_Root);
CU_add_test (tree_test_children, "Testing tree root children", Test_Tree_Children);

// Sets the basic run mode, CU_BRM_VERBOSE will show maximum output of run details
// Other choices are: CU_BRM_SILENT and CU_BRM_NORMAL
Expand Down

0 comments on commit 2c278f9

Please sign in to comment.