add test for arena dupe
This commit is contained in:
parent
0f09c6d31a
commit
fd5af31114
1 changed files with 20 additions and 0 deletions
|
|
@ -1622,3 +1622,23 @@ test "PortfolioData.revalue: returns false when the recompute yields no allocati
|
|||
defer overlay.deinit();
|
||||
try testing.expect(!pd.revalue(Date.fromYmd(2026, 5, 8), &overlay));
|
||||
}
|
||||
|
||||
test "dupePricesArena: copies entries with arena-owned keys" {
|
||||
var arena = std.heap.ArenaAllocator.init(testing.allocator);
|
||||
defer arena.deinit();
|
||||
const a = arena.allocator();
|
||||
|
||||
var src = std.StringHashMap(f64).init(testing.allocator);
|
||||
defer src.deinit();
|
||||
try src.put("AAPL", 1.5);
|
||||
try src.put("SPY", 2.5);
|
||||
|
||||
// Copy lives in the arena (keys duped there), so it survives `src`
|
||||
// being freed; reaped wholesale by arena.deinit (no out.deinit).
|
||||
var out = dupePricesArena(a, &src);
|
||||
src.clearAndFree(); // drop the source + its keys
|
||||
|
||||
try testing.expectEqual(@as(usize, 2), out.count());
|
||||
try testing.expectApproxEqAbs(@as(f64, 1.5), out.get("AAPL").?, 0.0001);
|
||||
try testing.expectApproxEqAbs(@as(f64, 2.5), out.get("SPY").?, 0.0001);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue