import "std.zc" fn fibonacci(n: int) -> int { if (n <= 1) { return n; } return fibonacci(n - 1) + fibonacci(n - 2); } fn test_recursion() { let fib10 = fibonacci(10); if (fib10 != 55) { println "FAIL: fibonacci(10) should be 55"; exit(1); } println " -> Recursive function works"; } fn add_three(a: int, b: int, c: int) -> int { return a + b + c; } fn test_multi_params() { let result = add_three(1, 2, 3); if (result != 6) { println "FAIL: add_three(1,2,3) should be 6"; exit(1); } println " -> Multi-parameter function works"; } fn double_val(x: int) -> int { return x * 2; } fn test_nested_calls() { let result = double_val(double_val(double_val(2))); if (result != 16) { println "FAIL: nested calls failed"; exit(1); } println " -> Nested function calls work"; } struct Counter { value: int; } impl Counter { fn new() -> Counter { return Counter { value: 0 }; } fn get(self) -> int { return self.value; } fn increment(self) { self.value = self.value + 1; } } fn test_struct_methods() { let c = Counter::new(); c.increment(); c.increment(); c.increment(); if (c.get() != 3) { println "FAIL: Counter should be 3"; exit(1); } println " -> Struct methods work"; } fn test_casting() { let f: float = 3.7; let i: int = (int)f; if (i != 3) { println "FAIL: float to int cast failed"; exit(1); } let i2: int = 42; let f2: float = (float)i2; if (f2 < 41.9 || f2 > 42.1) { println "FAIL: int to float cast failed"; exit(1); } println " -> Type casting works"; } fn test_bitwise() { let a = 0b1010; // 10 let b = 0b1100; // 12 let and_result = a & b; // 0b1000 = 8 let or_result = a | b; // 0b1110 = 14 let xor_result = a ^ b; // 0b0110 = 6 if (and_result != 8) { println "FAIL: bitwise AND failed"; exit(1); } if (or_result != 14) { println "FAIL: bitwise OR failed"; exit(1); } if (xor_result != 6) { println "FAIL: bitwise XOR failed"; exit(1); } println " -> Bitwise operations work"; } fn test_shift() { let x = 1; let left = x << 4; // 16 if (left != 16) { println "FAIL: left shift failed"; exit(1); } let y = 32; let right = y >> 2; // 8 if (right != 8) { println "FAIL: right shift failed"; exit(1); } println " -> Shift operations work"; } fn test_modulo() { let a = 17; let b = 5; let result = a % b; if (result != 2) { println "FAIL: modulo operation failed"; exit(1); } println " -> Modulo operator works"; } fn test_compound_expr() { let x = 5; let y = 10; let z = 3; let result = (x + y) * z - (y / 2); // (5 + 10) * 3 - (10 / 2) = 15 * 3 - 5 = 45 - 5 = 40 if (result != 40) { println "FAIL: compound expression failed"; exit(1); } println " -> Compound expressions work"; } fn test_increment_style() { let x = 5; x = x + 1; if (x != 6) { println "FAIL: increment style failed"; exit(1); } x = x - 1; if (x != 5) { println "FAIL: decrement style failed"; exit(1); } print " -> Increment/decrement style works"; } test "test_advanced" { println "Running function and advanced tests..."; test_recursion(); test_multi_params(); test_nested_calls(); test_struct_methods(); test_casting(); test_bitwise(); test_shift(); test_modulo(); test_compound_expr(); test_increment_style(); println "All function and advanced tests passed!"; }