Data-Pool-Shared
view release on metacpan or search on metacpan
t/04-edge-cases.t view on Meta::CPAN
push @slots, $s;
}
ok $alloc_ok, "cap=$cap alloc 1..$cap";
is $pool->used, $cap, "cap=$cap fully used";
ok !defined $pool->try_alloc, "cap=$cap full";
# spot-check first and last
is $pool->get($slots[0]), 1, "cap=$cap first slot";
is $pool->get($slots[-1]), $cap, "cap=$cap last slot";
$pool->free($_) for @slots;
is $pool->used, 0, "cap=$cap all freed";
}
# --- I64 extreme values ---
my $i64 = Data::Pool::Shared::I64->new(undef, 4);
my $s = $i64->alloc;
# max positive IV
my $max_iv = ~0 >> 1; # 2^63-1
$i64->set($s, $max_iv);
is $i64->get($s), $max_iv, "I64 max IV";
# min negative IV
my $min_iv = -(~0 >> 1) - 1; # -2^63
$i64->set($s, $min_iv);
is $i64->get($s), $min_iv, "I64 min IV";
# -1
$i64->set($s, -1);
is $i64->get($s), -1, "I64 -1";
# 0
$i64->set($s, 0);
is $i64->get($s), 0, "I64 0";
# CAS with negative values
$i64->set($s, -100);
ok $i64->cas($s, -100, -200), "I64 cas negative";
is $i64->get($s), -200, "I64 cas result negative";
# add overflow (wraps)
$i64->set($s, $max_iv);
my $wrapped = $i64->add($s, 1);
is $wrapped, $min_iv, "I64 add overflow wraps to min";
# incr/decr at boundaries
$i64->set($s, 0);
is $i64->decr($s), -1, "I64 decr from 0";
$i64->set($s, -1);
is $i64->incr($s), 0, "I64 incr from -1";
$i64->free($s);
# --- F64 edge values ---
my $f64 = Data::Pool::Shared::F64->new(undef, 4);
$s = $f64->alloc;
# Use string->NV so literals produce real Inf/NaN under -Duselongdouble
# (where 9e999 would fit in long double and not overflow to Inf).
my $posinf = "Inf" + 0;
my $neginf = "-Inf" + 0;
my $nan = "NaN" + 0;
# Infinity
$f64->set($s, $posinf);
my $v = $f64->get($s);
ok $v == $posinf, "F64 +Inf";
# -Infinity
$f64->set($s, $neginf);
$v = $f64->get($s);
ok $v == $neginf, "F64 -Inf";
# NaN
$f64->set($s, $nan);
$v = $f64->get($s);
ok $v != $v, "F64 NaN (NaN != NaN)";
# Negative zero
$f64->set($s, -0.0);
$v = $f64->get($s);
ok $v == 0.0, "F64 -0.0 compares equal to 0.0";
# Very small
$f64->set($s, 5e-324);
$v = $f64->get($s);
ok $v > 0 && $v < 1e-300, "F64 denormalized";
$f64->free($s);
# --- I32 extremes ---
my $i32 = Data::Pool::Shared::I32->new(undef, 4);
$s = $i32->alloc;
$i32->set($s, 2147483647); # INT32_MAX
is $i32->get($s), 2147483647, "I32 max";
$i32->set($s, -2147483648); # INT32_MIN
is $i32->get($s), -2147483648, "I32 min";
# add wrap
$i32->set($s, 2147483647);
my $w = $i32->add($s, 1);
is $w, -2147483648, "I32 add overflow wraps";
$i32->free($s);
# --- Str edge cases ---
my $str = Data::Pool::Shared::Str->new(undef, 4, 32);
$s = $str->alloc;
# empty string
$str->set($s, "");
is $str->get($s), "", "Str empty string";
# null bytes (binary data)
my $bin = "a\x00b\x00c";
$str->set($s, $bin);
is $str->get($s), $bin, "Str with null bytes";
is length($str->get($s)), 5, "Str null byte length preserved";
# full max_len
my $full = "x" x 32;
$str->set($s, $full);
is $str->get($s), $full, "Str full max_len";
is length($str->get($s)), 32, "Str full length";
# exceeds max_len â truncated
my $long = "y" x 100;
$str->set($s, $long);
is length($str->get($s)), 32, "Str truncated to max_len";
is $str->get($s), "y" x 32, "Str truncated content";
$str->free($s);
( run in 2.310 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )