diff options
| author | David Moc <personal@cdatgoose.org> | 2026-03-05 23:38:49 +0100 |
|---|---|---|
| committer | David Moc <personal@cdatgoose.org> | 2026-03-05 23:38:49 +0100 |
| commit | 0385817bb1301a778bb33f8405a435293b9f8905 (patch) | |
| tree | 53f4b6f13e393bd368c37ba4363826b46940dfd3 /tests | |
| parent | 262abf9b552a168ef3ae91f91af97683f16420a7 (diff) | |
Pushing to repo for safety.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/add2.c | 7 | ||||
| -rw-r--r-- | tests/arithmetic.c | 10 | ||||
| -rw-r--r-- | tests/arrays.c | 29 | ||||
| -rw-r--r-- | tests/bitwise.c | 12 | ||||
| -rw-r--r-- | tests/comparison.c | 14 | ||||
| -rw-r--r-- | tests/edge_cases.c | 13 | ||||
| -rw-r--r-- | tests/error_syntax.c | 4 | ||||
| -rw-r--r-- | tests/error_type_mismatch.c | 9 | ||||
| -rw-r--r-- | tests/error_undefined_var.c | 4 | ||||
| -rw-r--r-- | tests/for_loop.c | 9 | ||||
| -rw-r--r-- | tests/function_call.c | 14 | ||||
| -rw-r--r-- | tests/if_else.c | 18 | ||||
| -rw-r--r-- | tests/logical.c | 14 | ||||
| -rw-r--r-- | tests/pointers.c | 13 | ||||
| -rw-r--r-- | tests/recursive.c | 11 | ||||
| -rw-r--r-- | tests/strings.c | 10 | ||||
| -rw-r--r-- | tests/test1.c | 10 | ||||
| -rw-r--r-- | tests/while_loop.c | 11 |
18 files changed, 212 insertions, 0 deletions
diff --git a/tests/add2.c b/tests/add2.c new file mode 100644 index 0000000..a9cc343 --- /dev/null +++ b/tests/add2.c @@ -0,0 +1,7 @@ +int main(int argc, char **argv) +{ + int x = 1; + int y = 2; + int z = x + y; + return z; +} diff --git a/tests/arithmetic.c b/tests/arithmetic.c new file mode 100644 index 0000000..61951d8 --- /dev/null +++ b/tests/arithmetic.c @@ -0,0 +1,10 @@ +int main() { + int a = 5; + int b = 3; + int sum = a + b; + int diff = a - b; + int prod = a * b; + int quot = a / b; + int mod = a % b; + return sum + diff + prod + quot + mod; +} diff --git a/tests/arrays.c b/tests/arrays.c new file mode 100644 index 0000000..ed46c7c --- /dev/null +++ b/tests/arrays.c @@ -0,0 +1,29 @@ +int main() { + int arr[5]; + arr[0] = 10; + arr[1] = 20; + arr[2] = 30; + arr[3] = 40; + arr[4] = 50; + + int *p = arr; + *p = 100; + *(p + 1) = 200; + *(p + 2) = 300; + *(p + 3) = 400; + *(p + 4) = 500; + int x = *p; + int y = *(p + 1); + int z = *(p + 2); + int w = *(p + 3); + int v = *(p + 4); + + int sum = 0; + for (int i = 0; i < 5; i = i + 1) { + sum = sum + arr[i]; + sum = sum + *(p + i); + sum = sum + arr[i]; + } + + return sum; +} diff --git a/tests/bitwise.c b/tests/bitwise.c new file mode 100644 index 0000000..54aec8f --- /dev/null +++ b/tests/bitwise.c @@ -0,0 +1,12 @@ +int main() { + int a = 12; + int b = 10; + + int and = a & b; + int or = a | b; + int xor = a ^ b; + int shl = a << 1; + int shr = a >> 1; + + return and + or + xor + shl + shr; +} diff --git a/tests/comparison.c b/tests/comparison.c new file mode 100644 index 0000000..44b7f46 --- /dev/null +++ b/tests/comparison.c @@ -0,0 +1,14 @@ +int main() { + int a = 10; + int b = 5; + int c = 10; + + int lt = a < b; + int le = a <= c; + int gt = a > b; + int ge = a >= c; + int eq = a == c; + int ne = a != b; + + return lt + le + gt + ge + eq + ne; +} diff --git a/tests/edge_cases.c b/tests/edge_cases.c new file mode 100644 index 0000000..218b4fc --- /dev/null +++ b/tests/edge_cases.c @@ -0,0 +1,13 @@ +int main() { + int zero = 0; + int one = 1; + int neg = 5; + + int div_result = 10 / (one + zero); + + int mod_result = neg % 3; + + int logical = (zero && one) || (one && zero); + + return div_result + mod_result + logical; +} diff --git a/tests/error_syntax.c b/tests/error_syntax.c new file mode 100644 index 0000000..241a77b --- /dev/null +++ b/tests/error_syntax.c @@ -0,0 +1,4 @@ +int main() { + int x = 5 + return x; +} diff --git a/tests/error_type_mismatch.c b/tests/error_type_mismatch.c new file mode 100644 index 0000000..ad43f97 --- /dev/null +++ b/tests/error_type_mismatch.c @@ -0,0 +1,9 @@ +char getChar() { + return 'a'; +} + + +int main() { + int x = "hello"; + return getChar(); +} diff --git a/tests/error_undefined_var.c b/tests/error_undefined_var.c new file mode 100644 index 0000000..852746f --- /dev/null +++ b/tests/error_undefined_var.c @@ -0,0 +1,4 @@ +int main() { + int x = undefined_variable; + return x; +} diff --git a/tests/for_loop.c b/tests/for_loop.c new file mode 100644 index 0000000..0fc3d0c --- /dev/null +++ b/tests/for_loop.c @@ -0,0 +1,9 @@ +int main() { + int sum = 0; + + for (int i = 0; i < 4; i = i + 1) { + sum = sum + i; + } + + return sum; +} diff --git a/tests/function_call.c b/tests/function_call.c new file mode 100644 index 0000000..1af6ef8 --- /dev/null +++ b/tests/function_call.c @@ -0,0 +1,14 @@ +int add(int a, int b) { + return a + b; +} + +int multiply(int x, int y) { + return x * y; +} + +int main() { + int result1 = add(3, 4); + int result2 = multiply(2, 5); + int result3 = add(result1, result2); + return result3; +} diff --git a/tests/if_else.c b/tests/if_else.c new file mode 100644 index 0000000..2a0609a --- /dev/null +++ b/tests/if_else.c @@ -0,0 +1,18 @@ +int main() { + int x = 5; + int y = 0; + + if (x > 3) { + y = 10; + } else { + y = 20; + } + + if (x < 3) { + y = y + 1; + } else { + y = y + 2; + } + + return y; +} diff --git a/tests/logical.c b/tests/logical.c new file mode 100644 index 0000000..6bd1018 --- /dev/null +++ b/tests/logical.c @@ -0,0 +1,14 @@ +int main() { + int a = 1; + int b = 0; + int c = 1; + + int and1 = a && b; + int and2 = a && c; + int or1 = a || b; + int or2 = b || b; + int not1 = !a; + int not2 = !b; + + return and1 + and2 + or1 + or2 + not1 + not2; +} diff --git a/tests/pointers.c b/tests/pointers.c new file mode 100644 index 0000000..669aa2e --- /dev/null +++ b/tests/pointers.c @@ -0,0 +1,13 @@ +int main() { + int x = 42; + int *p = &x; + int **pp = &p; + + int val1 = *p; + int val2 = **pp; + + *p = 100; + int val3 = x; + + return val1 + val2 + val3; +} diff --git a/tests/recursive.c b/tests/recursive.c new file mode 100644 index 0000000..91fe8cd --- /dev/null +++ b/tests/recursive.c @@ -0,0 +1,11 @@ +int factorial(int n) { + if (n <= 1) { + return 1; + } else { + return n * factorial(n - 1); + } +} + +int main() { + return factorial(4); +} diff --git a/tests/strings.c b/tests/strings.c new file mode 100644 index 0000000..04a9038 --- /dev/null +++ b/tests/strings.c @@ -0,0 +1,10 @@ +int main() { + char *str = "Hello"; + int len = 0; + + while (str[len] != 0) { + len = len + 1; + } + + return len; +} diff --git a/tests/test1.c b/tests/test1.c new file mode 100644 index 0000000..8c19bb7 --- /dev/null +++ b/tests/test1.c @@ -0,0 +1,10 @@ +int main() { + int x = 10; + int *p = &x; + *p = 20; + if (*p == 20) { + return 1; + } else { + return 0; + } +}
\ No newline at end of file diff --git a/tests/while_loop.c b/tests/while_loop.c new file mode 100644 index 0000000..0199879 --- /dev/null +++ b/tests/while_loop.c @@ -0,0 +1,11 @@ +int main() { + int i = 0; + int sum = 0; + + while (i < 5) { + sum = sum + i; + i = i + 1; + } + + return sum; +} |
