Skip to content

Commit 2af01bf

Browse files
Merge pull request #71 from dreamer-coding/add_npl_summary
Add NLP and dynamic summary
2 parents 1ba1801 + 6b9b0bc commit 2af01bf

File tree

2 files changed

+118
-32
lines changed

2 files changed

+118
-32
lines changed

code/logic/fossil/test/testing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define FOSSIL_TEST_ATTR_BOLD "\033[1m" // Bold
3333
#define FOSSIL_TEST_ATTR_DIM "\033[2m" // Dim
3434
#define FOSSIL_TEST_ATTR_UNDERLINE "\033[4m" // Underline
35-
#define FOSSIL_TEST_ATTR_ITATIC "\033[3m" // Italic
35+
#define FOSSIL_TEST_ATTR_ITALIC "\033[3m" // Italic
3636

3737

3838
#include <setjmp.h>

code/logic/testing.c

Lines changed: 117 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,36 @@ const char *timeout_messages[] = {
226226
"Tests are taking too long. Time to find the bottleneck!"
227227
};
228228

229+
// Suggestions arrays based on different outcomes
230+
const char *empty_suite_suggestions[] = {
231+
"Check if your test suite has defined tests.",
232+
"Make sure your test cases are properly configured.",
233+
"Review the test configuration to ensure it’s correct."
234+
};
235+
236+
const char *failure_suggestions[] = {
237+
"Look into the test failures and their root causes.",
238+
"Check for bugs, missing dependencies, or misconfigured tests.",
239+
"Examine the test environment for potential issues.",
240+
"Review the test case logic and expected behavior.",
241+
"Consider adding more edge cases to capture hidden bugs."
242+
};
243+
244+
const char *success_suggestions[] = {
245+
"Great job! Keep adding tests to cover edge cases.",
246+
"Fantastic! Consider adding performance and stress tests.",
247+
"Success! Now, look at adding additional tests for edge cases.",
248+
"Well done! You’re on the right track, keep it up.",
249+
"Good job! Now, consider reviewing code for possible optimizations."
250+
};
251+
252+
const char *timeout_suggestions[] = {
253+
"Check resource usage and adjust timeout values.",
254+
"Investigate slow-running tests and optimize them.",
255+
"Consider breaking large tests into smaller ones to avoid timeouts.",
256+
"Check for any environmental factors affecting test performance."
257+
};
258+
229259
enum {
230260
_FOSSIL_TEST_RESPONSE_LENGTH = 50
231261
};
@@ -284,25 +314,25 @@ fossil_test_options_t fossil_test_init_options(void) {
284314
}
285315

286316
void usage_info(void) {
287-
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Usage: fossil [options] [command]" FOSSIL_TEST_COLOR_RESET);
317+
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "Usage: fossil [options] [command]" FOSSIL_TEST_COLOR_RESET);
288318
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
289319
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tOptions:" FOSSIL_TEST_COLOR_RESET);
290320
for (size_t i = 0; i < sizeof(FOSSIL_TEST_OPTIONS) / sizeof(FOSSIL_TEST_OPTIONS[0]); i++) {
291-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_OPTIONS[i]);
321+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_OPTIONS[i]);
292322
}
293323

294324
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tCommands:" FOSSIL_TEST_COLOR_RESET);
295325
for (size_t i = 0; i < sizeof(FOSSIL_TEST_COMMANDS) / sizeof(FOSSIL_TEST_COMMANDS[0]); i++) {
296-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_COMMANDS[i]);
326+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_COMMANDS[i]);
297327
}
298328
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
299329
}
300330

301331
void version_info(void) {
302332
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "Fossil Logic Test Framework");
303-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tVersion: %s\n", FOSSIL_TEST_VERSION);
304-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tAuthor: %s\n", FOSSIL_TEST_AUTHOR);
305-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tLicense: %s\n", FOSSIL_TEST_LICENSE);
333+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tVersion: %s\n", FOSSIL_TEST_VERSION);
334+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tAuthor: %s\n", FOSSIL_TEST_AUTHOR);
335+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tLicense: %s\n", FOSSIL_TEST_LICENSE);
306336
}
307337

308338
// Parse command-line arguments
@@ -701,30 +731,78 @@ void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) {
701731
}
702732
}
703733

704-
// Function to generate a dynamic message based on the test results
705-
void fossil_test_message(fossil_test_env_t *env) {
706-
// Seed random number generator
707-
srand(time(NULL));
734+
void fossil_test_sanity(fossil_test_env_t *env) {
735+
if (!env) {
736+
return;
737+
}
708738

739+
// Sanity analysis based on results
709740
if (env->pass_count == 0 && env->fail_count == 0 && env->skip_count == 0 && env->timeout_count == 0 && env->empty_count > 0) {
710-
printf(FOSSIL_TEST_COLOR_YELLOW FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, sarcastic_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
741+
// Empty test suite: sarcastic tone
742+
const char *message = sarcastic_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
743+
printf(FOSSIL_TEST_COLOR_YELLOW FOSSIL_TEST_ATTR_ITALIC "Hmm, seems like we ran an empty test suite: %s\n" FOSSIL_TEST_COLOR_RESET, message);
744+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, empty_suite_suggestions[rand() % 3]);
711745
} else if (env->fail_count > 0) {
712-
printf(FOSSIL_TEST_COLOR_RED FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, humorous_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
746+
// Failures occurred: humorous or frustrated tone
747+
const char *message = humorous_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
748+
printf(FOSSIL_TEST_COLOR_RED FOSSIL_TEST_ATTR_ITALIC "Whoops! Looks like some tests didn't pass: %s\n" FOSSIL_TEST_COLOR_RESET, message);
749+
750+
// Analysis of failures
751+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests failed. Possible causes include code issues, missing dependencies, or misconfigured tests.\n" FOSSIL_TEST_COLOR_RESET, env->fail_count);
752+
753+
// Suggestion for improvement
754+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, failure_suggestions[rand() % 5]);
713755
} else if (env->pass_count > 0) {
714-
printf(FOSSIL_TEST_COLOR_GREEN FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, great_news_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
756+
// Success: positive, motivational tone
757+
const char *message = great_news_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
758+
printf(FOSSIL_TEST_COLOR_GREEN FOSSIL_TEST_ATTR_ITALIC "Success! All systems go! Tests passed: %s\n" FOSSIL_TEST_COLOR_RESET, message);
759+
760+
// Analysis of success
761+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests passed successfully. Great work!\n", env->pass_count);
762+
763+
// Suggestion for improvement
764+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n", success_suggestions[rand() % 5]);
715765
} else if (env->timeout_count > 0) {
716-
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, timeout_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
766+
// Timeout occurred: calm, motivating tone
767+
const char *message = timeout_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
768+
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITALIC "Some tests timed out, but we’ll catch them next time: %s\n" FOSSIL_TEST_COLOR_RESET, message);
769+
770+
// Analysis of timeouts
771+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests timed out. This might be due to long execution times or heavy resource usage.\n" FOSSIL_TEST_COLOR_RESET, env->timeout_count);
772+
773+
// Suggestion for improvement
774+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, timeout_suggestions[rand() % 4]);
775+
} else {
776+
// Unexpected case: neutral tone
777+
printf(FOSSIL_TEST_COLOR_RESET "We’ve encountered an unexpected result state. Something's off—let’s look into it.\n");
778+
}
779+
780+
// Final remarks based on overall results
781+
printf(FOSSIL_TEST_COLOR_BLUE "\nFinal Analysis:\n" FOSSIL_TEST_COLOR_RESET);
782+
if (env->pass_count > 0) {
783+
printf("Success rate: %.2f%%\n", (double)env->pass_count / (env->pass_count + env->fail_count + env->skip_count + env->timeout_count) * 100);
784+
}
785+
if (env->fail_count > 0) {
786+
printf("Failure rate: %.2f%%\n", (double)env->fail_count / (env->pass_count + env->fail_count + env->skip_count + env->timeout_count) * 100);
717787
}
788+
if (env->skip_count > 0) {
789+
printf("Skipped tests: %d\n", env->skip_count);
790+
}
791+
if (env->timeout_count > 0) {
792+
printf("Timeout tests: %d\n", env->timeout_count);
793+
}
794+
795+
// Provide overall improvement suggestion
796+
printf(FOSSIL_TEST_COLOR_CYAN "Overall Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, success_suggestions[rand() % 5]);
718797
}
719798

720-
// Summary function for test results
721799
void fossil_test_summary(fossil_test_env_t *env) {
722800
if (!env) {
723801
return;
724802
}
725803

726804
if (env->options.dry_run) {
727-
puts(FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests were executed or evaluated." FOSSIL_TEST_COLOR_RESET);
805+
printf(FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests were executed or evaluated.\n" FOSSIL_TEST_COLOR_RESET);
728806
return;
729807
}
730808

@@ -737,7 +815,7 @@ void fossil_test_summary(fossil_test_env_t *env) {
737815
} else if (test->status == TEST_STATUS_FAIL) {
738816
env->fail_count++;
739817
if (test->failure_message) {
740-
printf("Test '%s' failed: %s\n", test->name, test->failure_message);
818+
printf(FOSSIL_TEST_COLOR_RED "Test '%s' failed: %s\n" FOSSIL_TEST_COLOR_RESET, test->name, test->failure_message);
741819
}
742820
} else if (test->status == TEST_STATUS_SKIP) {
743821
env->skip_count++;
@@ -753,25 +831,33 @@ void fossil_test_summary(fossil_test_env_t *env) {
753831
}
754832
env->end_execution_time = clock();
755833

756-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
757-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD FOSSIL_TEST_ATTR_ITATIC "\nFossil Test Summary:\n" FOSSIL_TEST_COLOR_RESET);
758-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
834+
// TUI-like header with borders and bold title
835+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
836+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD FOSSIL_TEST_ATTR_ITALIC "\tFossil Test Summary\n" FOSSIL_TEST_COLOR_RESET);
837+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
759838

760-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Passed: " FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->pass_count);
761-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Failed: " FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->fail_count);
762-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Skipped:" FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->skip_count);
763-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Timeout:" FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->timeout_count);
764-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Total: %d tests\n" FOSSIL_TEST_COLOR_RESET, env->pass_count + env->fail_count + env->skip_count);
839+
fossil_test_sanity(env); // Add suggestions
765840

766-
// Optionally, you could add the total execution time summary here
841+
// Execution time summary with a clean format
767842
double total_execution_time = (double)(env->end_execution_time - env->start_execution_time) / CLOCKS_PER_SEC;
768843
int seconds = (int)total_execution_time;
769844
int milliseconds = (int)((total_execution_time - seconds) * 1000);
770845
int microseconds = (int)((total_execution_time - seconds - milliseconds / 1000.0) * 1000000);
771846

772-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
773-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Execution time: (%.2d) seconds, (%.2d) milliseconds, (%.3d) microseconds\n" FOSSIL_TEST_COLOR_RESET, seconds, milliseconds, microseconds);
774-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
775-
776-
fossil_test_message(env);
847+
// Displaying execution time in a TUI-like format
848+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
849+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "Execution time: (%.2d) sec, (%.2d) ms, (%.3d) µs\n" FOSSIL_TEST_COLOR_RESET, seconds, milliseconds, microseconds);
850+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
851+
852+
// Detailed summary with counts and additional info
853+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "Test Results:\n" FOSSIL_TEST_COLOR_RESET);
854+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
855+
printf(FOSSIL_TEST_COLOR_CYAN "| Passed: %d\n" FOSSIL_TEST_COLOR_RESET, env->pass_count);
856+
printf(FOSSIL_TEST_COLOR_CYAN "| Failed: %d\n" FOSSIL_TEST_COLOR_RESET, env->fail_count);
857+
printf(FOSSIL_TEST_COLOR_CYAN "| Skipped: %d\n" FOSSIL_TEST_COLOR_RESET, env->skip_count);
858+
printf(FOSSIL_TEST_COLOR_CYAN "| Timed Out: %d\n" FOSSIL_TEST_COLOR_RESET, env->timeout_count);
859+
printf(FOSSIL_TEST_COLOR_CYAN "| Unexpected: %d\n" FOSSIL_TEST_COLOR_RESET, env->unexpected_count);
860+
861+
// Footer with TUI-style border
862+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "==============================================================\n" FOSSIL_TEST_COLOR_RESET);
777863
}

0 commit comments

Comments
 (0)