#include "benchmark.h" #include "syntax_essentials.h" #include static int total_tests = 0; static int passed_tests = 0; static int any_failure = 0; /** * * @param name * @param func * @param arg * @param expected * @param iterations */ static void run_test(const char* name, const function_to_benchmark func, const char* arg, const int expected, const size_t iterations) { total_tests++; const double avg_ms = benchmark_func(func, arg, iterations); const int result = func(arg); const int logic_ok = (result == expected); const int perf_ok = (avg_ms <= MAX_ALLOWED_MS); const int ok = logic_ok && perf_ok; if (ok) passed_tests++; else any_failure = 1; report_result(name, ok, avg_ms, MAX_ALLOWED_MS); } /** * */ static void test_names(void) { run_test("validate_first_name: valid", validate_first_name, "Jan", 1, ITERATIONS_FAST); run_test("validate_first_name: too short", validate_first_name, "J", 0, ITERATIONS_FAST); run_test("validate_last_name: valid", validate_last_name, "Kowalski", 1, ITERATIONS_FAST); run_test("validate_last_name: invalid char", validate_last_name, "Kowalski3", 0, ITERATIONS_FAST); } /** * */ static void test_full_name(void) { run_test("validate_full_name: valid", validate_full_name, "Jan Kowalski", 1, ITERATIONS_SLOW); run_test("validate_full_name: invalid first", validate_full_name, "J Kowalski", 0, ITERATIONS_SLOW); } /** * */ static void test_index(void) { run_test("validate_index: valid", validate_index, "123456", 1, ITERATIONS_FAST); run_test("validate_index: too short", validate_index, "12345", 0, ITERATIONS_FAST); } /** * * @return */ int main(void) { printf("=== Embedded Syntax Essentials Test Suite ===\n"); test_names(); test_full_name(); test_index(); printf("\n====================================\n"); printf("Tests passed: %d / %d\n", passed_tests, total_tests); if (!any_failure) { printf( "%sALL CRITERIA MET — PASS%s\n", COLOR_GREEN, COLOR_RESET); return 0; } printf("%sSUITE FAILED — performance or logic violation%s\n", COLOR_RED, COLOR_RESET); return 1; }