1
Fork 0

split bdz int and str tests

This commit is contained in:
Motiejus Jakštys 2022-03-16 07:08:57 +02:00 committed by Motiejus Jakštys
parent e142621753
commit c721fa6d5d
1 changed files with 26 additions and 25 deletions

View File

@ -693,29 +693,30 @@ test "users compare function" {
try testing.expect(!cmpUser({}, bb, b)); try testing.expect(!cmpUser({}, bb, b));
} }
test "bdzIdx" { fn expectUsedHashes(allocator: Allocator, arr: []const u32) !void {
const allocator = testing.allocator; var used = try allocator.alloc(bool, arr.len);
const k_u32 = [_]u32{ 42, 1, 2, 3 }; defer allocator.free(used);
const k_str = [_][]const u8{ "42", "1", "2", "3" }; mem.set(bool, used, false);
assert(k_u32.len == k_str.len); for (arr) |elem|
const mphf_str = try cmph.packStr(allocator, k_str[0..]); used[arr[elem]] = true;
const mphf_u32 = try cmph.packU32(allocator, k_u32[0..]); for (used) |item|
defer allocator.free(mphf_str); try testing.expect(item);
defer allocator.free(mphf_u32); }
{ test "bdzIdx on u32" {
var result = try bdzIdx(u32, allocator, mphf_u32, k_u32[0..]); const keys = [_]u32{ 42, 1, 2, 3 };
defer allocator.free(result); const mphf = try cmph.packU32(testing.allocator, keys[0..]);
var used = [_]bool{false} ** k_u32.len; defer testing.allocator.free(mphf);
for (result) |elem| used[result[elem]] = true; var result = try bdzIdx(u32, testing.allocator, mphf, keys[0..]);
for (used) |item| try testing.expect(item); defer testing.allocator.free(result);
} try expectUsedHashes(testing.allocator, result);
}
{
var result = try bdzIdx([]const u8, allocator, mphf_str, k_str[0..]); test "bdzIdx on str" {
defer allocator.free(result); const keys = [_][]const u8{ "42", "1", "2", "3" };
var used = [_]bool{false} ** k_u32.len; const mphf = try cmph.packStr(testing.allocator, keys[0..]);
for (result) |elem| used[result[elem]] = true; defer testing.allocator.free(mphf);
for (used) |item| try testing.expect(item); var result = try bdzIdx([]const u8, testing.allocator, mphf, keys[0..]);
} defer testing.allocator.free(result);
try expectUsedHashes(testing.allocator, result);
} }