Skip to main content
Glama
advanced-test-qwen2.5-coder-7b-2025-10-26T11-55-07-133Z.md3.32 kB
# Advanced Zig Test Report **Model**: qwen2.5-coder:7b **Date**: 2025-10-26T11:55:07.134Z **Total Tests**: 6 **Passed**: 6 **Failed**: 0 **Average Response Time**: 29.58s ## Results ### 1. Basic Zig Syntax [EASY] **Status**: ✅ PASS **Time**: 8.78s **Response**: ```zig ```zig pub fn add(a: i32, b: i32) i32 { return a + b; } ``` ``` ### 2. Memory Allocation [EASY] **Status**: ✅ PASS **Time**: 46.46s **Response**: ```zig Sure! Below is a simple example of allocating memory for an integer using the Zig programming language's built-in `std.mem.Allocator`. The code also shows how to store an integer in that memory, and finally how to free the allocated memory. ```zig const std = @import("std"); pub fn main() !void { // Get the default allocator from the global state. var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); // Allocate enough space for an integer on th ``` ### 3. Error Handling [MEDIUM] **Status**: ✅ PASS **Time**: 45.31s **Response**: ```zig Certainly! In Zig, you can use the `Result` type to handle errors gracefully. Below is an example of a Zig function that returns a `Result` type and how it can be called with proper error handling. ```zig const std = @import("std"); // Define a custom error type pub const MyError = error{ InvalidInput, DivisionByZero, }; // Function that might return an error fn divide(a: i32, b: i32) Result(f32, MyError) { if (b == 0) { return error.DivisionByZero; } return .{ .va ``` ### 4. Structs & Methods [MEDIUM] **Status**: ✅ PASS **Time**: 22.22s **Response**: ```zig Here is an example of how you could create such a struct in Zig: ```zig const std = @import("std"); pub const Point = struct { x: f64, y: f64, pub fn new(x: f64, y: f64) Point { return .{ .x = x, .y = y }; } pub fn distanceFromOrigin(self: Point) f64 { return std.math.sqrt(self.x * self.x + self.y * self.y); } }; pub fn main() void { var point = Point.new(3.0, 4.0); print("Distance from origin is {}\n", .{point.distanceFromOrigin()}); } ``` T ``` ### 5. Generics [HARD] **Status**: ✅ PASS **Time**: 31.64s **Response**: ```zig In Zig, you can create a generic function that works with any numeric type by using type parameters. Below is an example of a generic function that takes two arguments of the same numeric type and returns the maximum of the two: ```zig pub fn max(comptime T: type, a: T, b: T) T { if (a > b) return a; return b; } ``` This function uses the `comptime` keyword to make the type parameter `T` available at compile time. It then compares two values of type `T` and returns the maximum value. ``` ### 6. Comptime Magic [HARD] **Status**: ✅ PASS **Time**: 23.05s **Response**: ```zig In Zig, `comptime` is used for computations that occur during compilation, not at runtime. This can be particularly useful for tasks like computing factorials at compile time. Here's an example of how you could define and use such a function in Zig: ```zig const std = @import("std"); // Function to compute factorial at compile time pub fn factorial(n: u64) comptime u64 { if (n == 0 or n == 1) return 1; return n * factorial(n - 1); } pub fn main() void { // Compute factorial of 5 ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fulgidus/zignet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server