From 6c8a15272ace9b89cfbb331d5b5093e0f8b52a9e Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 23 Nov 2025 15:07:19 +0100 Subject: [PATCH] Implemented tests. --- Makefile | 71 ++++++++++++++++++++++++++++++- src/globals.c | 1 + src/interpreter.c | 11 ++--- src/parser.c | 35 +++++++++++++++- src/types.h | 2 + tests/array_test.rc | 63 ++++++++++++++++++++++++++++ tests/comparison_test.rc | 91 ++++++++++++++++++++++++++++++++++++++++ tests/file_seek_test.rc | 77 ++++++++++++++++++++++++++++++++++ tests/functions_test.rc | 45 ++++++++++++++++++++ tests/logical_test.rc | 84 +++++++++++++++++++++++++++++++++++++ tests/pointer_test.rc | 49 ++++++++++++++++++++++ tests/trig_test.rc | 49 ++++++++++++++++++++++ 12 files changed, 571 insertions(+), 7 deletions(-) create mode 100644 tests/array_test.rc create mode 100644 tests/comparison_test.rc create mode 100644 tests/file_seek_test.rc create mode 100644 tests/functions_test.rc create mode 100644 tests/logical_test.rc create mode 100644 tests/pointer_test.rc create mode 100644 tests/trig_test.rc diff --git a/Makefile b/Makefile index 8b196e0..911dab2 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,14 @@ TESTS = $(TEST_DIR)/feature_test.rc \ $(TEST_DIR)/file_io_test.rc \ $(TEST_DIR)/double_test.rc \ $(TEST_DIR)/break_continue_test.rc \ - $(TEST_DIR)/async_io_test.rc + $(TEST_DIR)/async_io_test.rc \ + $(TEST_DIR)/array_test.rc \ + $(TEST_DIR)/pointer_test.rc \ + $(TEST_DIR)/logical_test.rc \ + $(TEST_DIR)/comparison_test.rc \ + $(TEST_DIR)/functions_test.rc \ + $(TEST_DIR)/trig_test.rc \ + $(TEST_DIR)/file_seek_test.rc EXAMPLES = $(EXAMPLE_DIR)/http_simple.rc \ $(EXAMPLE_DIR)/http_persistent.rc \ @@ -73,6 +80,39 @@ test: $(TARGET) @echo "Running increment decrement tests..." @$(TARGET) $(TEST_DIR)/increment_decrement_test.rc 2>&1 | grep -v "Error at token" || true @echo "" + @echo "Running file I/O tests..." + @$(TARGET) $(TEST_DIR)/file_io_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running double tests..." + @$(TARGET) $(TEST_DIR)/double_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running break/continue tests..." + @$(TARGET) $(TEST_DIR)/break_continue_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running async I/O tests..." + @$(TARGET) $(TEST_DIR)/async_io_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running array tests..." + @$(TARGET) $(TEST_DIR)/array_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running pointer tests..." + @$(TARGET) $(TEST_DIR)/pointer_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running logical operators tests..." + @$(TARGET) $(TEST_DIR)/logical_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running comparison operators tests..." + @$(TARGET) $(TEST_DIR)/comparison_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running functions tests..." + @$(TARGET) $(TEST_DIR)/functions_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running trigonometry tests..." + @$(TARGET) $(TEST_DIR)/trig_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" + @echo "Running file seek tests..." + @$(TARGET) $(TEST_DIR)/file_seek_test.rc 2>&1 | grep -v "Error at token" || true + @echo "" @echo "=== All Tests Completed ===" run-feature-test: $(TARGET) @@ -105,6 +145,27 @@ run-break-continue-test: $(TARGET) run-async-io-test: $(TARGET) $(TARGET) $(TEST_DIR)/async_io_test.rc +run-array-test: $(TARGET) + $(TARGET) $(TEST_DIR)/array_test.rc + +run-pointer-test: $(TARGET) + $(TARGET) $(TEST_DIR)/pointer_test.rc + +run-logical-test: $(TARGET) + $(TARGET) $(TEST_DIR)/logical_test.rc + +run-comparison-test: $(TARGET) + $(TARGET) $(TEST_DIR)/comparison_test.rc + +run-functions-test: $(TARGET) + $(TARGET) $(TEST_DIR)/functions_test.rc + +run-trig-test: $(TARGET) + $(TARGET) $(TEST_DIR)/trig_test.rc + +run-file-seek-test: $(TARGET) + $(TARGET) $(TEST_DIR)/file_seek_test.rc + run-http-simple: $(TARGET) $(TARGET) $(EXAMPLE_DIR)/http_simple.rc @@ -131,10 +192,18 @@ help: @echo " make run-math-test - Run math_test.rc (math functions)" @echo " make run-string-test - Run string_test.rc (string concatenation)" @echo " make run-string-manip - Run string_manip_test.rc (string manipulation & slicing)" + @echo " make run-increment-decrement-test - Run increment_decrement_test.rc (++/--)" @echo " make run-file-io-test - Run file_io_test.rc (file I/O operations)" @echo " make run-double-test - Run double_test.rc (double data type)" @echo " make run-break-continue-test - Run break_continue_test.rc (break/continue)" @echo " make run-async-io-test - Run async_io_test.rc (async I/O)" + @echo " make run-array-test - Run array_test.rc (arrays)" + @echo " make run-pointer-test - Run pointer_test.rc (pointers & dereference)" + @echo " make run-logical-test - Run logical_test.rc (&&, ||)" + @echo " make run-comparison-test - Run comparison_test.rc (<, >, <=, >=)" + @echo " make run-functions-test - Run functions_test.rc (function calls & recursion)" + @echo " make run-trig-test - Run trig_test.rc (sin, cos, tan)" + @echo " make run-file-seek-test - Run file_seek_test.rc (fseek, ftell)" @echo "" @echo "Examples:" @echo " make run-http-simple - Run http_simple.rc (single connection HTTP server)" diff --git a/src/globals.c b/src/globals.c index 17abc36..7b246e9 100644 --- a/src/globals.c +++ b/src/globals.c @@ -16,3 +16,4 @@ char *src_code; char str_pool[STR_POOL_SIZE]; int str_pool_idx = 0; long ax = 0; +int return_flag = 0; diff --git a/src/interpreter.c b/src/interpreter.c index a1a11c9..64964d8 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -73,7 +73,7 @@ void statement() { pc++; while (pc < MAX_TOK && pc < tk_idx && tokens[pc].type != '}' && tokens[pc].type != 0) { statement(); - if (ax == -999 || ax == -998 || ax == -997) { + if (return_flag || ax == -998 || ax == -997) { int brace = 1; while (brace > 0 && pc < MAX_TOK && pc < tk_idx && tokens[pc].type != 0) { if (tokens[pc].type == '{') brace++; @@ -139,14 +139,14 @@ void statement() { match(')'); if (cond) { statement(); - if (ax == -999 || ax == -998 || ax == -997) return; + if (return_flag || ax == -998 || ax == -997) return; if (pc < MAX_TOK && pc < tk_idx && tokens[pc].type == Else) { pc++; skip_block(); } } else { skip_block(); if (pc < MAX_TOK && pc < tk_idx && tokens[pc].type == Else) { pc++; statement(); - if (ax == -999 || ax == -998 || ax == -997) return; + if (return_flag || ax == -998 || ax == -997) return; } } } @@ -169,7 +169,7 @@ void statement() { } body_start = pc; statement(); - if (ax == -999) return; + if (return_flag) return; if (ax == -998) { ax = 0; pc = body_start; @@ -186,7 +186,7 @@ void statement() { if (pc < MAX_TOK && pc < tk_idx && tokens[pc].type != ';') ax = expression(); else ax = 0; match(';'); - ax = -999; + return_flag = 1; } else if (tokens[pc].type == Break) { pc++; @@ -253,6 +253,7 @@ void scan_functions() { strncpy(f->name, name->text, name->val); f->name[name->val] = 0; i += 3; + f->params_start = i; int params = 0; while(i < MAX_TOK && i < tk_idx && tokens[i].type != ')') { if (tokens[i].type == Int || tokens[i].type == Char || tokens[i].type == Double) { diff --git a/src/parser.c b/src/parser.c index 0d104b2..d0a368b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -78,9 +78,9 @@ long factor() { int f_idx = find_func(t->text, t->val); if (f_idx == -1) error("Unknown function"); if (f_idx < 0 || f_idx >= func_cnt) return 0; + int call_pc = pc; pc += 2; - int old_bp = bp; long args[10]; int argc = 0; @@ -95,25 +95,58 @@ long factor() { match(')'); int ret_pc = pc; + int old_loc_cnt = loc_cnt; + int old_bp = bp; + if (sp >= MEM_SIZE) return 0; if (bp < 0 || bp >= MEM_SIZE) return 0; memory[sp] = bp; bp = sp++; if (sp >= MEM_SIZE) return 0; memory[sp++] = ret_pc; + memory[sp++] = old_loc_cnt; + + int param_base = sp; for(int i=0; i= MEM_SIZE) break; memory[sp++] = args[i]; } + int scan_pc = funcs[f_idx].params_start; + int param_idx = 0; + while (scan_pc < MAX_TOK && scan_pc < tk_idx && tokens[scan_pc].type != ')') { + if (tokens[scan_pc].type == Int || tokens[scan_pc].type == Char || tokens[scan_pc].type == Double) { + scan_pc++; + while (scan_pc < MAX_TOK && tokens[scan_pc].type == '*') scan_pc++; + if (scan_pc < MAX_TOK && tokens[scan_pc].type == Id && param_idx < argc && loc_cnt < VAR_MAX) { + Token *param_name = &tokens[scan_pc]; + Symbol *sym = &locals[loc_cnt++]; + int name_len = param_name->val; + if (name_len > 31) name_len = 31; + strncpy(sym->name, param_name->text, name_len); + sym->name[name_len] = 0; + sym->type = Int; + sym->addr = param_base + param_idx; + sym->is_array = 0; + param_idx++; + } + } + scan_pc++; + } + pc = funcs[f_idx].entry_point; + return_flag = 0; statement(); val = ax; + ax = 0; + return_flag = 0; + loc_cnt = old_loc_cnt; if (bp < 0 || bp >= MEM_SIZE) return 0; sp = bp; if (sp < 0 || sp >= MEM_SIZE) return 0; bp = memory[sp]; + if (sp + 1 < MEM_SIZE) ret_pc = memory[sp + 1]; pc = ret_pc; return val; } diff --git a/src/types.h b/src/types.h index c762678..e0a44ed 100644 --- a/src/types.h +++ b/src/types.h @@ -30,6 +30,7 @@ typedef struct { char name[32]; int entry_point; int param_count; + int params_start; } Func; typedef long (*NativeFunc)(long*, int); @@ -55,5 +56,6 @@ extern char *src_code; extern char str_pool[STR_POOL_SIZE]; extern int str_pool_idx; extern long ax; +extern int return_flag; #endif diff --git a/tests/array_test.rc b/tests/array_test.rc new file mode 100644 index 0000000..552845d --- /dev/null +++ b/tests/array_test.rc @@ -0,0 +1,63 @@ +int main() { + printf("=== Array Tests ===\n"); + + printf("Test 1: Array declaration and initialization\n"); + int arr[5]; + arr[0] = 10; + arr[1] = 20; + arr[2] = 30; + arr[3] = 40; + arr[4] = 50; + printf("arr[0] = %d\n", arr[0]); + printf("arr[1] = %d\n", arr[1]); + printf("arr[2] = %d\n", arr[2]); + printf("arr[3] = %d\n", arr[3]); + printf("arr[4] = %d\n", arr[4]); + printf("PASS: Array indexing works\n"); + + printf("Test 2: Array modification\n"); + arr[2] = 100; + printf("After arr[2] = 100: arr[2] = %d\n", arr[2]); + printf("PASS: Array element modification works\n"); + + printf("Test 3: Loop through array\n"); + int i = 0; + int sum = 0; + while (i < 5) { + sum = sum + arr[i]; + i = i + 1; + } + printf("Sum of array elements: %d\n", sum); + printf("PASS: Array iteration works\n"); + + printf("Test 4: Array with calculations\n"); + int nums[3]; + nums[0] = 5; + nums[1] = 10; + nums[2] = 15; + int total = 0; + total = total + nums[0]; + total = total + nums[1]; + total = total + nums[2]; + printf("nums[0] + nums[1] + nums[2] = %d\n", total); + printf("PASS: Array arithmetic works\n"); + + printf("Test 5: Larger array\n"); + int big[10]; + int j = 0; + while (j < 10) { + big[j] = j * j; + j = j + 1; + } + printf("Squares (0-9): "); + int k = 0; + while (k < 10) { + printf("%d ", big[k]); + k = k + 1; + } + printf("\n"); + printf("PASS: Larger arrays work\n"); + + printf("\n=== All Array Tests Completed ===\n"); + return 0; +} diff --git a/tests/comparison_test.rc b/tests/comparison_test.rc new file mode 100644 index 0000000..e2a4e75 --- /dev/null +++ b/tests/comparison_test.rc @@ -0,0 +1,91 @@ +int main() { + printf("=== Comparison Operators Tests ===\n"); + + int a = 10; + int b = 20; + int c = 10; + + printf("Test 1: Less than (<)\n"); + if (a < b) { + printf("10 < 20 = true\n"); + } + if (b < a) { + printf("20 < 10 = true (SHOULD NOT PRINT)\n"); + } else { + printf("20 < 10 = false\n"); + } + if (a < c) { + printf("10 < 10 = true (SHOULD NOT PRINT)\n"); + } else { + printf("10 < 10 = false\n"); + } + printf("PASS: Less than operator works\n"); + + printf("Test 2: Greater than (>)\n"); + if (b > a) { + printf("20 > 10 = true\n"); + } + if (a > b) { + printf("10 > 20 = true (SHOULD NOT PRINT)\n"); + } else { + printf("10 > 20 = false\n"); + } + if (a > c) { + printf("10 > 10 = true (SHOULD NOT PRINT)\n"); + } else { + printf("10 > 10 = false\n"); + } + printf("PASS: Greater than operator works\n"); + + printf("Test 3: Less than or equal (<=)\n"); + if (a <= b) { + printf("10 <= 20 = true\n"); + } + if (a <= c) { + printf("10 <= 10 = true\n"); + } + if (b <= a) { + printf("20 <= 10 = true (SHOULD NOT PRINT)\n"); + } else { + printf("20 <= 10 = false\n"); + } + printf("PASS: Less than or equal operator works\n"); + + printf("Test 4: Greater than or equal (>=)\n"); + if (b >= a) { + printf("20 >= 10 = true\n"); + } + if (a >= c) { + printf("10 >= 10 = true\n"); + } + if (a >= b) { + printf("10 >= 20 = true (SHOULD NOT PRINT)\n"); + } else { + printf("10 >= 20 = false\n"); + } + printf("PASS: Greater than or equal operator works\n"); + + printf("Test 5: Negative number comparisons\n"); + int neg1 = -5; + int neg2 = -10; + if (neg1 > neg2) { + printf("-5 > -10 = true\n"); + } + if (neg2 < neg1) { + printf("-10 < -5 = true\n"); + } + if (neg1 < 0) { + printf("-5 < 0 = true\n"); + } + printf("PASS: Negative number comparisons work\n"); + + printf("Test 6: Comparisons in expressions\n"); + int result = a < b; + printf("result of (10 < 20) = %d\n", result); + int result2 = a > b; + printf("result of (10 > 20) = %d\n", result2); + printf("PASS: Comparisons as expressions work\n"); + + printf("\n=== All Comparison Operators Tests Completed ===\n"); + return 0; +} diff --git a/tests/file_seek_test.rc b/tests/file_seek_test.rc new file mode 100644 index 0000000..c5b436f --- /dev/null +++ b/tests/file_seek_test.rc @@ -0,0 +1,77 @@ +int main() { + printf("=== File Seek Operations Tests ===\n"); + + printf("Test 1: Create test file\n"); + int f = fopen("seek_test.txt", "w"); + if (f == 0) { + printf("ERROR: Could not create file\n"); + return 1; + } + fputs(f, "0123456789ABCDEFGHIJ"); + fclose(f); + printf("PASS: File created with content\n"); + + printf("Test 2: ftell() - get current position\n"); + f = fopen("seek_test.txt", "r"); + int pos = ftell(f); + printf("Initial position: %d\n", pos); + char *line = fgets(f, 5); + printf("Read: '%s'\n", line); + pos = ftell(f); + printf("Position after reading 5 bytes: %d\n", pos); + fclose(f); + printf("PASS: ftell() works\n"); + + printf("Test 3: fseek() with SEEK_SET\n"); + f = fopen("seek_test.txt", "r"); + fseek(f, 10, SEEK_SET()); + pos = ftell(f); + printf("Position after fseek(10, SEEK_SET): %d\n", pos); + line = fgets(f, 5); + printf("Read from position 10: '%s'\n", line); + fclose(f); + printf("PASS: fseek with SEEK_SET works\n"); + + printf("Test 4: fseek() with SEEK_CUR\n"); + f = fopen("seek_test.txt", "r"); + line = fgets(f, 5); + printf("First read: '%s'\n", line); + fseek(f, 3, SEEK_CUR()); + pos = ftell(f); + printf("Position after fseek(3, SEEK_CUR): %d\n", pos); + line = fgets(f, 5); + printf("Read after seek: '%s'\n", line); + fclose(f); + printf("PASS: fseek with SEEK_CUR works\n"); + + printf("Test 5: fseek() with SEEK_END\n"); + f = fopen("seek_test.txt", "r"); + fseek(f, -5, SEEK_END()); + pos = ftell(f); + printf("Position after fseek(-5, SEEK_END): %d\n", pos); + line = fgets(f, 10); + printf("Read from near end: '%s'\n", line); + fclose(f); + printf("PASS: fseek with SEEK_END works\n"); + + printf("Test 6: Random access pattern\n"); + f = fopen("seek_test.txt", "r"); + fseek(f, 5, SEEK_SET()); + line = fgets(f, 3); + printf("Position 5: '%s'\n", line); + fseek(f, 0, SEEK_SET()); + line = fgets(f, 3); + printf("Position 0: '%s'\n", line); + fseek(f, 15, SEEK_SET()); + line = fgets(f, 3); + printf("Position 15: '%s'\n", line); + fclose(f); + printf("PASS: Random access works\n"); + + printf("Test 7: Cleanup\n"); + fremove("seek_test.txt"); + printf("PASS: File removed\n"); + + printf("\n=== All File Seek Tests Completed ===\n"); + return 0; +} diff --git a/tests/functions_test.rc b/tests/functions_test.rc new file mode 100644 index 0000000..00e5776 --- /dev/null +++ b/tests/functions_test.rc @@ -0,0 +1,45 @@ +int getValue() { + return 42; +} + +int add(int a, int b) { + return a + b; +} + +int square(int x) { + int result = x * x; + return result; +} + +int max(int a, int b) { + if (a > b) { + return a; + } + return b; +} + +int main() { + printf("=== Functions Tests ===\n"); + printf("Testing no-parameter functions...\n"); + int val = getValue(); + printf("getValue() = %d\n", val); + + printf("Testing two-parameter functions...\n"); + int sum = add(5, 3); + printf("add(5, 3) = %d\n", sum); + + printf("Testing functions with local variables...\n"); + int sq = square(7); + printf("square(7) = %d\n", sq); + + printf("Testing conditional functions...\n"); + int m1 = max(15, 20); + printf("max(15, 20) = %d\n", m1); + + printf("Testing nested function calls...\n"); + int nested = add(square(3), getValue()); + printf("add(square(3), getValue()) = %d\n", nested); + + printf("\n=== All Tests Completed ===\n"); + return 0; +} diff --git a/tests/logical_test.rc b/tests/logical_test.rc new file mode 100644 index 0000000..2fccec9 --- /dev/null +++ b/tests/logical_test.rc @@ -0,0 +1,84 @@ +int main() { + printf("=== Logical Operators Tests ===\n"); + + printf("Test 1: AND operator (&&)\n"); + int a = 1; + int b = 1; + if (a && b) { + printf("1 && 1 = true\n"); + } + int c = 1; + int d = 0; + if (c && d) { + printf("1 && 0 = true (SHOULD NOT PRINT)\n"); + } else { + printf("1 && 0 = false\n"); + } + int e = 0; + int f = 0; + if (e && f) { + printf("0 && 0 = true (SHOULD NOT PRINT)\n"); + } else { + printf("0 && 0 = false\n"); + } + printf("PASS: AND operator works\n"); + + printf("Test 2: OR operator (||)\n"); + if (a || b) { + printf("1 || 1 = true\n"); + } + if (c || d) { + printf("1 || 0 = true\n"); + } + if (e || f) { + printf("0 || 0 = true (SHOULD NOT PRINT)\n"); + } else { + printf("0 || 0 = false\n"); + } + printf("PASS: OR operator works\n"); + + printf("Test 3: Combined logical operations\n"); + int x = 5; + int y = 10; + int z = 15; + if (x < y && y < z) { + printf("5 < 10 && 10 < 15 = true\n"); + } + if (x > y || y < z) { + printf("5 > 10 || 10 < 15 = true\n"); + } + if (x > y && y > z) { + printf("5 > 10 && 10 > 15 = true (SHOULD NOT PRINT)\n"); + } else { + printf("5 > 10 && 10 > 15 = false\n"); + } + printf("PASS: Combined logical operations work\n"); + + printf("Test 4: Logical operators in while loops\n"); + int i = 0; + int j = 10; + while (i < 5 && j > 5) { + i = i + 1; + j = j - 1; + } + printf("After loop with &&: i = %d, j = %d\n", i, j); + printf("PASS: Logical operators in loops work\n"); + + printf("Test 5: Complex conditions\n"); + int age = 25; + int hasLicense = 1; + int hasInsurance = 1; + if ((age >= 18 && hasLicense) && hasInsurance) { + printf("Can drive: age >= 18, has license and insurance\n"); + } + int temp = 30; + if (temp < 0 || temp > 35) { + printf("Extreme temperature (SHOULD NOT PRINT)\n"); + } else { + printf("Normal temperature range\n"); + } + printf("PASS: Complex conditions work\n"); + + printf("\n=== All Logical Operators Tests Completed ===\n"); + return 0; +} diff --git a/tests/pointer_test.rc b/tests/pointer_test.rc new file mode 100644 index 0000000..c258514 --- /dev/null +++ b/tests/pointer_test.rc @@ -0,0 +1,49 @@ +int main() { + printf("=== Pointer Tests ===\n"); + + printf("Test 1: Address-of operator (&)\n"); + int x = 42; + int addr = &x; + printf("x = %d\n", x); + printf("&x = %d\n", addr); + printf("PASS: Address-of operator works\n"); + + printf("Test 2: Dereference operator (*)\n"); + int y = 100; + int *ptr = &y; + int val = *ptr; + printf("y = %d\n", y); + printf("*ptr = %d\n", val); + printf("PASS: Dereference operator works\n"); + + printf("Test 3: Modify through pointer\n"); + int z = 50; + int *p = &z; + *p = 75; + printf("After *p = 75, z = %d\n", z); + printf("PASS: Pointer modification works\n"); + + printf("Test 4: Multiple pointers\n"); + int a = 10; + int b = 20; + int *pa = &a; + int *pb = &b; + printf("a = %d, b = %d\n", a, b); + printf("*pa = %d, *pb = %d\n", *pa, *pb); + int sum = *pa + *pb; + printf("*pa + *pb = %d\n", sum); + printf("PASS: Multiple pointers work\n"); + + printf("Test 5: Pointer with arrays\n"); + int arr[3]; + arr[0] = 1; + arr[1] = 2; + arr[2] = 3; + printf("arr[0] = %d, arr[1] = %d, arr[2] = %d\n", arr[0], arr[1], arr[2]); + int *arrptr = &arr; + printf("Array base address: %d\n", arrptr); + printf("PASS: Pointers with arrays work\n"); + + printf("\n=== All Pointer Tests Completed ===\n"); + return 0; +} diff --git a/tests/trig_test.rc b/tests/trig_test.rc new file mode 100644 index 0000000..07834fd --- /dev/null +++ b/tests/trig_test.rc @@ -0,0 +1,49 @@ +int main() { + printf("=== Trigonometric Functions Tests ===\n"); + printf("Note: Results are scaled by 1,000,000\n"); + + printf("Test 1: sin() function\n"); + int sin0 = sin(0); + printf("sin(0) * 1000000 = %d\n", sin0); + int sin1 = sin(1); + printf("sin(1) * 1000000 = %d\n", sin1); + int sin2 = sin(2); + printf("sin(2) * 1000000 = %d\n", sin2); + printf("PASS: sin() function works\n"); + + printf("Test 2: cos() function\n"); + int cos0 = cos(0); + printf("cos(0) * 1000000 = %d\n", cos0); + int cos1 = cos(1); + printf("cos(1) * 1000000 = %d\n", cos1); + int cos2 = cos(2); + printf("cos(2) * 1000000 = %d\n", cos2); + printf("PASS: cos() function works\n"); + + printf("Test 3: tan() function\n"); + int tan0 = tan(0); + printf("tan(0) * 1000000 = %d\n", tan0); + int tan1 = tan(1); + printf("tan(1) * 1000000 = %d\n", tan1); + printf("PASS: tan() function works\n"); + + printf("Test 4: Multiple angles\n"); + int i = 0; + while (i < 4) { + int s = sin(i); + int c = cos(i); + printf("Angle %d: sin = %d, cos = %d\n", i, s, c); + i = i + 1; + } + printf("PASS: Multiple angle calculations work\n"); + + printf("Test 5: Trig with negative values\n"); + int sinNeg = sin(-1); + printf("sin(-1) * 1000000 = %d\n", sinNeg); + int cosNeg = cos(-1); + printf("cos(-1) * 1000000 = %d\n", cosNeg); + printf("PASS: Negative angle calculations work\n"); + + printf("\n=== All Trigonometric Tests Completed ===\n"); + return 0; +}