Skip to content

Commit

Permalink
fix usort integration test (keep-starknet-strange#497)
Browse files Browse the repository at this point in the history
fix usort integration test
  • Loading branch information
StringNick authored Mar 23, 2024
1 parent 02a8bbd commit 0066cf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 14 additions & 4 deletions src/hint_processor/usort.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ pub fn usortBody(
} else |_| {}

var positions_dict = std.AutoHashMap(Felt252, std.ArrayList(u64)).init(allocator);
defer positions_dict.deinit();
defer {
errdefer {
var it = positions_dict.valueIterator();
while (it.next()) |v| {
v.deinit();
}

positions_dict.deinit();
}

var output = std.ArrayList(Felt252).init(allocator);
Expand All @@ -104,8 +105,17 @@ pub fn usortBody(
else => {},
}

var entry = positions_dict.getPtr(val) orelse
@constCast(&std.ArrayList(u64).init(allocator));
var entry = positions_dict.getPtr(val) orelse blk: {
var nval = std.ArrayList(u64).init(allocator);
errdefer nval.deinit();

const res = try positions_dict.getOrPutValue(
val,
nval,
);

break :blk res.value_ptr;
};

try entry.append(i);
}
Expand Down
10 changes: 4 additions & 6 deletions src/integration_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub fn main() void {
// .{ .pathname = "cairo_programs/example_blake2s.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/example_program.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/factorial.json", .layout = "plain" },
// TODO: FailedToComputeOp0 error
// TODO: HintNotImplemented error
// .{ .pathname = "cairo_programs/fast_ec_add_v2.json", .layout = "all_cairo" },
// TODO: FailedToComputeOp0 error
// TODO: HintNotImplemented error
// .{ .pathname = "cairo_programs/fast_ec_add_v3.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/fibonacci.json", .layout = "plain" },
// TODO: HintNotImplemented error uint384 hint
Expand Down Expand Up @@ -147,8 +147,7 @@ pub fn main() void {
.{ .pathname = "cairo_programs/normalize_address.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/not_main.json", .layout = "all_cairo" },

// TODO: panic attempt to use null value
// .{ .pathname = "cairo_programs/operations_with_data_structures.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/operations_with_data_structures.json", .layout = "all_cairo" },

// TODO: hint not implemented sha256
// .{ .pathname = "cairo_programs/packed_sha256_test.json", .layout = "all_cairo" },
Expand Down Expand Up @@ -223,8 +222,7 @@ pub fn main() void {
.{ .pathname = "cairo_programs/unsafe_keccak.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/unsigned_div_rem.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/use_imported_module.json", .layout = "all_cairo" },
// TODO: panic attempt to use null value
// .{ .pathname = "cairo_programs/usort.json", .layout = "all_cairo" },
.{ .pathname = "cairo_programs/usort.json", .layout = "all_cairo" },
};

var ok_count: usize = 0;
Expand Down

0 comments on commit 0066cf9

Please sign in to comment.