fn fuzzTestMinMax(rng: std.Random, queue_size: usize) !void 994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020fn fuzzTestMinMax(rng: std.Random, queue_size: usize) !void {
const gpa = std.testing.allocator;
const items = try generateRandomSlice(gpa, rng, queue_size);
var queue: MinHeap = .fromOwnedSlice(items, {});
defer queue.deinit(gpa);
var last_min: ?u32 = null;
var last_max: ?u32 = null;
var i: usize = 0;
while (i < queue_size) : (i += 1) {
if (i % 2 == 0) {
const next = queue.popMin().?;
if (last_min) |last| {
try expect(last <= next);
}
last_min = next;
} else {
const next = queue.popMax().?;
if (last_max) |last| {
try expect(last >= next);
}
last_max = next;
}
}
}