Skip to content

Commit

Permalink
Merge pull request #3 from dreamer-coding/main
Browse files Browse the repository at this point in the history
Classes and O of N
  • Loading branch information
dreamer-coding authored Oct 13, 2024
2 parents 66d5526 + 76ea032 commit e57195c
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if get_option('with_test').enabled()
dependencies: [
dependency('fossil-test'),
dependency('fossil-mock'),
dependency('fossil-mark'),
fossil_tofu_dep])

test('Pizza Test Run', pizza)
Expand Down
17 changes: 17 additions & 0 deletions code/tests/test_arrayof.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -81,6 +82,19 @@ FOSSIL_TEST(test_fossil_tofu_arrayof_clear) {
fossil_tofu_arrayof_erase(&array);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_array) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0);
for (int i = 0; i < 1000000; i++) {
fossil_tofu_t tofu = fossil_tofu_create("int", "10");
fossil_tofu_arrayof_add(&array, tofu);
}
fossil_tofu_arrayof_erase(&array);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -92,4 +106,7 @@ FOSSIL_TEST_GROUP(c_arrayof_structure_tests) {
ADD_TEST(test_fossil_tofu_arrayof_size);
ADD_TEST(test_fossil_tofu_arrayof_is_empty);
ADD_TEST(test_fossil_tofu_arrayof_clear);

// Benchmarking
ADD_TEST(stress_test_array);
} // end of tests
23 changes: 23 additions & 0 deletions code/tests/test_doublylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>
#include "fossil/tofu/framework.h"

Expand Down Expand Up @@ -133,6 +134,26 @@ FOSSIL_TEST(test_dlist_reverse_backward) {
ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_dlist) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

// Insert the element
fossil_dlist_insert(mock_dlist, element);

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -143,4 +164,6 @@ FOSSIL_TEST_GROUP(c_dlist_structure_tests) {
ADD_TESTF(test_dlist_remove, struct_dlist_fixture);
ADD_TESTF(test_dlist_reverse_forward, struct_dlist_fixture);
ADD_TESTF(test_dlist_reverse_backward, struct_dlist_fixture);

ADD_TESTF(stress_test_dlist, struct_dlist_fixture);
} // end of tests
26 changes: 26 additions & 0 deletions code/tests/test_dqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include <fossil/tofu/framework.h>

// * * * * * * * * * * * * * * * * * * * * * * * *
Expand Down Expand Up @@ -125,6 +127,27 @@ FOSSIL_TEST(test_dqueue_not_empty_and_is_empty) {
ASSUME_ITS_TRUE(fossil_dqueue_is_empty(mock_dqueue));
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_dqueue) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_dqueue_insert(mock_dqueue, element);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -134,4 +157,7 @@ FOSSIL_TEST_GROUP(c_dqueue_structure_tests) {
ADD_TESTF(test_dqueue_remove, struct_dqueue_fixture);
//ADD_TESTF(test_dqueue_getter_and_setter, struct_dqueue_fixture);
ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture);

// Benchmarking cases
ADD_TESTF(stress_test_dqueue, struct_dqueue_fixture);
} // end of tests
26 changes: 26 additions & 0 deletions code/tests/test_forwardlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -136,6 +137,28 @@ FOSSIL_TEST(test_flist_reverse_backward) {
ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_flist) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_flist_insert(mock_flist, element);
fossil_flist_remove(mock_flist, &element);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -145,4 +168,7 @@ FOSSIL_TEST_GROUP(c_flist_structure_tests) {
ADD_TESTF(test_flist_remove, struct_flist_fixture);
ADD_TESTF(test_flist_reverse_forward, struct_flist_fixture);
ADD_TESTF(test_flist_reverse_backward, struct_flist_fixture);

// Benchmarking cases
ADD_TESTF(stress_test_flist, struct_flist_fixture);
} // end of tests
30 changes: 30 additions & 0 deletions code/tests/test_mapof.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -101,6 +102,32 @@ FOSSIL_TEST(test_fossil_tofu_mapof_clear) {
fossil_tofu_mapof_erase(&map);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_map) {
// Create a map object
fossil_tofu_mapof_t map = fossil_tofu_mapof_create("int");

// Start the benchmark
TEST_BENCHMARK();

// Perform some operations
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_t key = fossil_tofu_create("int", "1");
fossil_tofu_t value = fossil_tofu_create("int", "100");
fossil_tofu_mapof_add(&map, key, value);
fossil_tofu_mapof_remove(&map, key);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

// Erase the map object
fossil_tofu_mapof_erase(&map);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -113,4 +140,7 @@ FOSSIL_TEST_GROUP(c_mapof_structure_tests) {
ADD_TEST(test_fossil_tofu_mapof_size);
ADD_TEST(test_fossil_tofu_mapof_is_empty);
ADD_TEST(test_fossil_tofu_mapof_clear);

// Benchmarking
ADD_TEST(stress_test_map);
} // end of tests
26 changes: 26 additions & 0 deletions code/tests/test_pqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -96,6 +97,28 @@ FOSSIL_TEST(test_pqueue_not_empty_and_is_empty) {
ASSUME_ITS_TRUE(fossil_pqueue_remove(mock_pqueue, &removedElement, removedPriority));
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_pqueue) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_pqueue_insert(mock_pqueue, element, 2);
fossil_pqueue_remove(mock_pqueue, &element, 2);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -105,4 +128,7 @@ FOSSIL_TEST_GROUP(c_pqueue_structure_tests) {
ADD_TESTF(test_pqueue_insert_and_size, struct_pqueue_fixture);
ADD_TESTF(test_pqueue_remove, struct_pqueue_fixture);
ADD_TESTF(test_pqueue_not_empty_and_is_empty, struct_pqueue_fixture);

// Benchmarking
ADD_TESTF(stress_test_pqueue, struct_pqueue_fixture);
} // end of tests
26 changes: 26 additions & 0 deletions code/tests/test_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -104,6 +105,28 @@ FOSSIL_TEST(test_queue_not_empty_and_is_empty) {
fossil_tofu_erase(&element);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_queue) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_queue_insert(mock_queue, element);
fossil_queue_remove(mock_queue, &element);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -113,4 +136,7 @@ FOSSIL_TEST_GROUP(c_structure_tests) {
ADD_TESTF(test_queue_insert_and_size, struct_queue_fixture);
ADD_TESTF(test_queue_remove, struct_queue_fixture);
ADD_TESTF(test_queue_not_empty_and_is_empty, struct_queue_fixture);

// Benchmarking
ADD_TESTF(stress_test_queue, struct_queue_fixture);
} // end of tests
26 changes: 26 additions & 0 deletions code/tests/test_setof.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* -----------------------------------------------------------------------------
*/
#include <fossil/unittest/framework.h>
#include <fossil/benchmark/framework.h>
#include <fossil/unittest/assume.h>

#include "fossil/tofu/framework.h"
Expand Down Expand Up @@ -107,6 +108,28 @@ FOSSIL_TEST(test_set_contains) {
fossil_tofu_erase(&element3);
}

// benchmarking cases to capture the true
// performence based on current structures
// implmentation.

FOSSIL_TEST(stress_test_set) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_set_insert(mock_set, element);
fossil_set_remove(mock_set, element);
}

// Stop the benchmark
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);

fossil_tofu_erase(&element);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -116,4 +139,7 @@ FOSSIL_TEST_GROUP(c_setof_structure_tests) {
ADD_TESTF(test_set_insert_and_size, struct_set_fixture);
ADD_TESTF(test_set_remove, struct_set_fixture);
ADD_TESTF(test_set_contains, struct_set_fixture);

// Benchmarking
ADD_TESTF(stress_test_set, struct_set_fixture);
} // end of tests
Loading

0 comments on commit e57195c

Please sign in to comment.