aboutsummaryrefslogtreecommitdiff
path: root/tests/ii/Random.pm
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.one>2026-10-16 20:53:55 +0800
committer_ov4 <ov4@ov4.one>2026-10-16 20:53:55 +0800
commitd19f9ddb866ac2415cbfe66966897a8efe8ddb63 (patch)
tree6be1a9a6e316e776a396813f7cb22c688287b21a /tests/ii/Random.pm
parent5c00b8cd03cbfc516cce92229f3f4974d7549c24 (diff)
test(compiler): add seeded C++ differential tests across seven groups
Generate 10000 random records per group plus boundary inputs using a portable SHA-256 stream. Compare native and runner output independently. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'tests/ii/Random.pm')
-rw-r--r--tests/ii/Random.pm25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ii/Random.pm b/tests/ii/Random.pm
new file mode 100644
index 0000000..a7a95e5
--- /dev/null
+++ b/tests/ii/Random.pm
@@ -0,0 +1,25 @@
+package Random;
+use strict;
+use warnings;
+use Digest::SHA qw(sha256);
+
+# Fixed byte order and decimal counter: independent of Perl's rand and hash seed.
+sub new {
+ my ($class, $seed, $group) = @_;
+ return bless { seed => $seed, group => $group, counter => 0 }, $class;
+}
+sub integer {
+ my ($self, $low, $high) = @_;
+ die "invalid random range\n" if $high < $low || $high - $low >= 4294967296;
+ my $bytes = sha256($self->{seed} . "\0" . $self->{group} . "\0" . $self->{counter}++);
+ return $low + unpack('N', substr($bytes, 0, 4)) % ($high - $low + 1);
+}
+sub emit {
+ my ($self, $count, $edges, $make) = @_;
+ die "positive count required\n" unless defined($count) && $count =~ /^[1-9][0-9]*$/;
+ binmode STDOUT; # Identical input bytes on every platform.
+ print scalar(@$edges) + $count, "\n";
+ print "$_\n" for @$edges;
+ print $make->(), "\n" for 1 .. $count;
+}
+1;