diff options
| author | _ov4 <ov4@ov4.one> | 2026-10-16 20:53:55 +0800 |
|---|---|---|
| committer | _ov4 <ov4@ov4.one> | 2026-10-16 20:53:55 +0800 |
| commit | d19f9ddb866ac2415cbfe66966897a8efe8ddb63 (patch) | |
| tree | 6be1a9a6e316e776a396813f7cb22c688287b21a /tests/ii/arithmetic | |
| parent | 5c00b8cd03cbfc516cce92229f3f4974d7549c24 (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/arithmetic')
| -rw-r--r-- | tests/ii/arithmetic/case.json | 1 | ||||
| -rw-r--r-- | tests/ii/arithmetic/generate.pl | 23 | ||||
| -rw-r--r-- | tests/ii/arithmetic/notes.md | 5 | ||||
| -rw-r--r-- | tests/ii/arithmetic/program.cps | 12 | ||||
| -rw-r--r-- | tests/ii/arithmetic/reference.cc | 13 |
5 files changed, 54 insertions, 0 deletions
diff --git a/tests/ii/arithmetic/case.json b/tests/ii/arithmetic/case.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/ii/arithmetic/case.json @@ -0,0 +1 @@ +{} diff --git a/tests/ii/arithmetic/generate.pl b/tests/ii/arithmetic/generate.pl new file mode 100644 index 0000000..24236a8 --- /dev/null +++ b/tests/ii/arithmetic/generate.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/.."; +use Random; +my ($seed, $count) = @ARGV; +my $rng = Random->new($seed, "arithmetic"); +my @edges = ( + '9223372036854775807 1', + '-9223372036854775808 1', + '-9223372036854775808 2', + '0 -1', + '7 -3', + '-7 3', + '-7 -3', + '1 1', +); +$rng->emit($count, \@edges, sub { +my $a = $rng->integer(-1000000, 1000000); +my $b = $rng->integer(-1000000, 1000000); +$b = 1 if $b == 0; +return "$a $b"; +}); diff --git a/tests/ii/arithmetic/notes.md b/tests/ii/arithmetic/notes.md new file mode 100644 index 0000000..947a3fa --- /dev/null +++ b/tests/ii/arithmetic/notes.md @@ -0,0 +1,5 @@ +# arithmetic + +CIE pp. 15-16, project i64 and truncation-towards-zero DIV/MOD. Full-width extremes are used only in safe division/remainder and comparisons; addition, subtraction and multiplication use A MOD 1000001. B is nonzero, and INT64_MIN / -1 is never generated. + +Each record produces exactly one output line. Random records are preceded by fixed boundary records; every arithmetic intermediate is bounded. diff --git a/tests/ii/arithmetic/program.cps b/tests/ii/arithmetic/program.cps new file mode 100644 index 0000000..7c4bf52 --- /dev/null +++ b/tests/ii/arithmetic/program.cps @@ -0,0 +1,12 @@ +DECLARE Count : INTEGER +DECLARE Index : INTEGER +DECLARE A : INTEGER +DECLARE B : INTEGER +DECLARE Small : INTEGER +INPUT Count +FOR Index <- 1 TO Count + INPUT A + INPUT B + Small <- A MOD 1000001 + OUTPUT A < B, ":", A DIV B, ":", A MOD B, ":", Small + B, ":", Small - B, ":", Small * B +NEXT Index diff --git a/tests/ii/arithmetic/reference.cc b/tests/ii/arithmetic/reference.cc new file mode 100644 index 0000000..6d3d98f --- /dev/null +++ b/tests/ii/arithmetic/reference.cc @@ -0,0 +1,13 @@ +#include <cstdint> +#include <iostream> +int main() { + int count; + if (!(std::cin >> count)) return 1; + for (int i = 0; i < count; ++i) { + std::int64_t a, b; + if (!(std::cin >> a >> b) || b == 0) return 1; + auto small = a % 1000001; + std::cout << (a < b ? "TRUE" : "FALSE") << ':' << a / b << ':' << a % b + << ':' << small + b << ':' << small - b << ':' << small * b << '\n'; + } +} |
