summaryrefslogtreecommitdiffstats
path: root/tests/test_syntax_essentials.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_syntax_essentials.c')
-rw-r--r--tests/test_syntax_essentials.c125
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/test_syntax_essentials.c b/tests/test_syntax_essentials.c
new file mode 100644
index 0000000..e0f0744
--- /dev/null
+++ b/tests/test_syntax_essentials.c
@@ -0,0 +1,125 @@
1#include "benchmark.h"
2#include "syntax_essentials.h"
3#include <stdio.h>
4
5static int total_tests = 0;
6static int passed_tests = 0;
7static int any_failure = 0;
8
9/**
10 *
11 * @param name
12 * @param func
13 * @param arg
14 * @param expected
15 * @param iterations
16 */
17static void run_test(const char* name,
18 const function_to_benchmark func,
19 const char* arg,
20 const int expected,
21 const size_t iterations)
22{
23 total_tests++;
24
25 const double avg_ms = benchmark_func(func, arg, iterations);
26 const int result = func(arg);
27
28 const int logic_ok = (result == expected);
29 const int perf_ok = (avg_ms <= MAX_ALLOWED_MS);
30 const int ok = logic_ok && perf_ok;
31
32 if (ok)
33 passed_tests++;
34 else
35 any_failure = 1;
36
37 report_result(name, ok, avg_ms, MAX_ALLOWED_MS);
38}
39
40/**
41 *
42 */
43static void test_names(void)
44{
45 run_test("validate_first_name: valid",
46 validate_first_name,
47 "Jan",
48 1,
49 ITERATIONS_FAST);
50 run_test("validate_first_name: too short",
51 validate_first_name,
52 "J",
53 0,
54 ITERATIONS_FAST);
55 run_test("validate_last_name: valid",
56 validate_last_name,
57 "Kowalski",
58 1,
59 ITERATIONS_FAST);
60 run_test("validate_last_name: invalid char",
61 validate_last_name,
62 "Kowalski3",
63 0,
64 ITERATIONS_FAST);
65}
66
67/**
68 *
69 */
70static void test_full_name(void)
71{
72 run_test("validate_full_name: valid",
73 validate_full_name,
74 "Jan Kowalski",
75 1,
76 ITERATIONS_SLOW);
77 run_test("validate_full_name: invalid first",
78 validate_full_name,
79 "J Kowalski",
80 0,
81 ITERATIONS_SLOW);
82}
83
84/**
85 *
86 */
87static void test_index(void)
88{
89 run_test("validate_index: valid",
90 validate_index,
91 "123456",
92 1,
93 ITERATIONS_FAST);
94 run_test("validate_index: too short",
95 validate_index,
96 "12345",
97 0,
98 ITERATIONS_FAST);
99}
100
101/**
102 *
103 * @return
104 */
105int main(void)
106{
107 printf("=== Embedded Syntax Essentials Test Suite ===\n");
108
109 test_names();
110 test_full_name();
111 test_index();
112
113 printf("\n====================================\n");
114 printf("Tests passed: %d / %d\n", passed_tests, total_tests);
115
116 if (!any_failure) {
117 printf(
118 "%sALL CRITERIA MET — PASS%s\n", COLOR_GREEN, COLOR_RESET);
119 return 0;
120 }
121 printf("%sSUITE FAILED — performance or logic violation%s\n",
122 COLOR_RED,
123 COLOR_RESET);
124 return 1;
125}