Skip to content

Commit

Permalink
update mark test to showcase stress testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-coding committed Oct 11, 2024
1 parent 0565222 commit 76ea032
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 1,025 deletions.
73 changes: 7 additions & 66 deletions code/tests/test_arrayof.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,67 +86,13 @@ FOSSIL_TEST(test_fossil_tofu_arrayof_clear) {
// performence based on current structures
// implmentation.

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_create) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30");
fossil_tofu_arrayof_erase(&array);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
}

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_add) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0);
fossil_tofu_t tofu1 = fossil_tofu_create("int", "10");
fossil_tofu_t tofu2 = fossil_tofu_create("int", "20");
fossil_tofu_arrayof_add(&array, tofu1);
fossil_tofu_arrayof_add(&array, tofu2);
fossil_tofu_arrayof_erase(&array);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
}

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_get) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30");
fossil_tofu_t tofu = fossil_tofu_arrayof_get(&array, 1);
ASSUME_ITS_EQUAL_I32(20, tofu.value.int_val);
fossil_tofu_arrayof_erase(&array);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
}

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_size) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 2, "10", "20");
fossil_tofu_arrayof_size(&array);
fossil_tofu_arrayof_erase(&array);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
}

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_is_empty) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 0);
fossil_tofu_arrayof_is_empty(&array);
fossil_tofu_arrayof_erase(&array);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
}

FOSSIL_TEST(benchmark_fossil_tofu_arrayof_clear) {
TEST_BENCHMARK();
for (size_t i = 0; i < 1000000; i++) {
fossil_tofu_arrayof_t array = fossil_tofu_arrayof_create("int", 3, "10", "20", "30");
fossil_tofu_arrayof_clear(&array);
fossil_tofu_arrayof_erase(&array);
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);
}
TEST_DURATION_SEC(TEST_CURRENT_TIME(), 1.0);
fossil_tofu_arrayof_erase(&array);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -162,10 +108,5 @@ FOSSIL_TEST_GROUP(c_arrayof_structure_tests) {
ADD_TEST(test_fossil_tofu_arrayof_clear);

// Benchmarking
ADD_TEST(benchmark_fossil_tofu_arrayof_create);
ADD_TEST(benchmark_fossil_tofu_arrayof_add);
ADD_TEST(benchmark_fossil_tofu_arrayof_get);
ADD_TEST(benchmark_fossil_tofu_arrayof_size);
ADD_TEST(benchmark_fossil_tofu_arrayof_is_empty);
ADD_TEST(benchmark_fossil_tofu_arrayof_clear);
ADD_TEST(stress_test_array);
} // end of tests
75 changes: 2 additions & 73 deletions code/tests/test_doublylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ FOSSIL_TEST(test_dlist_reverse_backward) {
// performence based on current structures
// implmentation.

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

Expand All @@ -154,74 +154,6 @@ FOSSIL_TEST(benchmark_dlist_insert) {
fossil_tofu_erase(&element);
}

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

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

// Start the benchmark
TEST_BENCHMARK();

// Remove the element
fossil_tofu_t removedElement;
fossil_dlist_remove(mock_dlist, &removedElement);

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

fossil_tofu_erase(&element);
}

FOSSIL_TEST(benchmark_dlist_reverse_forward) {
// Insert some elements
fossil_tofu_t element1 = fossil_tofu_create("int", "42");
fossil_tofu_t element2 = fossil_tofu_create("int", "10");
fossil_tofu_t element3 = fossil_tofu_create("int", "5");

fossil_dlist_insert(mock_dlist, element1);
fossil_dlist_insert(mock_dlist, element2);
fossil_dlist_insert(mock_dlist, element3);

// Start the benchmark
TEST_BENCHMARK();

// Reverse the doubly linked list forward
fossil_dlist_reverse_forward(mock_dlist);

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

fossil_tofu_erase(&element1);
fossil_tofu_erase(&element2);
fossil_tofu_erase(&element3);
}

FOSSIL_TEST(benchmark_dlist_reverse_backward) {
// Insert some elements
fossil_tofu_t element1 = fossil_tofu_create("int", "42");
fossil_tofu_t element2 = fossil_tofu_create("int", "10");
fossil_tofu_t element3 = fossil_tofu_create("int", "5");

fossil_dlist_insert(mock_dlist, element1);
fossil_dlist_insert(mock_dlist, element2);
fossil_dlist_insert(mock_dlist, element3);

// Start the benchmark
TEST_BENCHMARK();

// Reverse the doubly linked list backward
fossil_dlist_reverse_backward(mock_dlist);

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

fossil_tofu_erase(&element1);
fossil_tofu_erase(&element2);
fossil_tofu_erase(&element3);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -233,8 +165,5 @@ FOSSIL_TEST_GROUP(c_dlist_structure_tests) {
ADD_TESTF(test_dlist_reverse_forward, struct_dlist_fixture);
ADD_TESTF(test_dlist_reverse_backward, struct_dlist_fixture);

ADD_TESTF(benchmark_dlist_insert, struct_dlist_fixture);
ADD_TESTF(benchmark_dlist_remove, struct_dlist_fixture);
ADD_TESTF(benchmark_dlist_reverse_forward, struct_dlist_fixture);
ADD_TESTF(benchmark_dlist_reverse_backward, struct_dlist_fixture);
ADD_TESTF(stress_test_dlist, struct_dlist_fixture);
} // end of tests
88 changes: 3 additions & 85 deletions code/tests/test_dqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,93 +131,15 @@ FOSSIL_TEST(test_dqueue_not_empty_and_is_empty) {
// performence based on current structures
// implmentation.

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

// Start the benchmark
TEST_BENCHMARK();

// Insert the element
fossil_dqueue_insert(mock_dqueue, element);

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

fossil_tofu_erase(&element);
}

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

// Insert the element
fossil_dqueue_insert(mock_dqueue, element);

// Start the benchmark
TEST_BENCHMARK();

// Remove the element
fossil_tofu_t removedElement;
fossil_dqueue_remove(mock_dqueue, &removedElement);

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

fossil_tofu_erase(&element);
}

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

// Insert the element
fossil_dqueue_insert(mock_dqueue, element);

// Start the benchmark
TEST_BENCHMARK();

// Get the size
fossil_dqueue_size(mock_dqueue);

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

fossil_tofu_erase(&element);
}

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

// Insert the element
fossil_dqueue_insert(mock_dqueue, element);

// Start the benchmark
TEST_BENCHMARK();

for (size_t i = 0; i < 1000000; i++) {
fossil_dqueue_not_empty(mock_dqueue);
}

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

fossil_tofu_erase(&element);
}

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

// Insert the element
fossil_dqueue_insert(mock_dqueue, element);

// Start the benchmark
TEST_BENCHMARK();

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

// Stop the benchmark
Expand All @@ -237,9 +159,5 @@ FOSSIL_TEST_GROUP(c_dqueue_structure_tests) {
ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture);

// Benchmarking cases
ADD_TESTF(benchmark_dqueue_insert, struct_dqueue_fixture);
ADD_TESTF(benchmark_dqueue_remove, struct_dqueue_fixture);
ADD_TESTF(benchmark_dqueue_size, struct_dqueue_fixture);
ADD_TESTF(benchmark_dqueue_not_empty, struct_dqueue_fixture);
ADD_TESTF(benchmark_dqueue_is_empty, struct_dqueue_fixture);
ADD_TESTF(stress_test_dqueue, struct_dqueue_fixture);
} // end of tests
81 changes: 6 additions & 75 deletions code/tests/test_forwardlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,90 +141,24 @@ FOSSIL_TEST(test_flist_reverse_backward) {
// performence based on current structures
// implmentation.

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

// Start the benchmark
TEST_BENCHMARK();

// Insert the element
fossil_flist_insert(mock_flist, element);
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_TEST(benchmark_flist_remove) {
// Create an element
fossil_tofu_t element = fossil_tofu_create("int", "42");

// Insert the element
fossil_flist_insert(mock_flist, element);

// Start the benchmark
TEST_BENCHMARK();

// Remove the element
fossil_tofu_t removedElement;
fossil_flist_remove(mock_flist, &removedElement);

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

fossil_tofu_erase(&element);
}

FOSSIL_TEST(benchmark_flist_reverse_forward) {
// Insert some elements
fossil_tofu_t element1 = fossil_tofu_create("int", "42");
fossil_tofu_t element2 = fossil_tofu_create("int", "10");
fossil_tofu_t element3 = fossil_tofu_create("int", "5");

fossil_flist_insert(mock_flist, element1);
fossil_flist_insert(mock_flist, element2);
fossil_flist_insert(mock_flist, element3);

// Start the benchmark
TEST_BENCHMARK();

// Reverse the linked list forward
fossil_flist_reverse_forward(mock_flist);

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

fossil_tofu_erase(&element1);
fossil_tofu_erase(&element2);
fossil_tofu_erase(&element3);
}

FOSSIL_TEST(benchmark_flist_reverse_backward) {
// Insert some elements
fossil_tofu_t element1 = fossil_tofu_create("int", "42");
fossil_tofu_t element2 = fossil_tofu_create("int", "10");
fossil_tofu_t element3 = fossil_tofu_create("int", "5");

fossil_flist_insert(mock_flist, element1);
fossil_flist_insert(mock_flist, element2);
fossil_flist_insert(mock_flist, element3);

// Start the benchmark
TEST_BENCHMARK();

// Reverse the linked list backward
fossil_flist_reverse_backward(mock_flist);

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

fossil_tofu_erase(&element1);
fossil_tofu_erase(&element2);
fossil_tofu_erase(&element3);
}

// * * * * * * * * * * * * * * * * * * * * * * * *
// * Fossil Logic Test Pool
// * * * * * * * * * * * * * * * * * * * * * * * *
Expand All @@ -236,8 +170,5 @@ FOSSIL_TEST_GROUP(c_flist_structure_tests) {
ADD_TESTF(test_flist_reverse_backward, struct_flist_fixture);

// Benchmarking cases
ADD_TEST(benchmark_flist_insert);
ADD_TEST(benchmark_flist_remove);
ADD_TEST(benchmark_flist_reverse_forward);
ADD_TEST(benchmark_flist_reverse_backward);
ADD_TESTF(stress_test_flist, struct_flist_fixture);
} // end of tests
Loading

0 comments on commit 76ea032

Please sign in to comment.