diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 10:39:45 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 10:39:45 +0000 |
| commit | 4a34e970fb224be7640883f6b0dfa602157759f4 (patch) | |
| tree | 3f2e0a54163b179b411e604b6362c08cb1075d3d /tests/ii/overload-functions | |
| parent | b47c302bbffd668334f307d512b674f804f8f2fc (diff) | |
test(overload): add randomized differential coverage
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/ii/overload-functions')
| -rw-r--r-- | tests/ii/overload-functions/arrays.cps | 21 | ||||
| -rw-r--r-- | tests/ii/overload-functions/case.json | 3 | ||||
| -rw-r--r-- | tests/ii/overload-functions/generate.pl | 20 | ||||
| -rw-r--r-- | tests/ii/overload-functions/notes.md | 7 | ||||
| -rw-r--r-- | tests/ii/overload-functions/program.cps | 33 | ||||
| -rw-r--r-- | tests/ii/overload-functions/reference.cc | 19 | ||||
| -rw-r--r-- | tests/ii/overload-functions/scalar.cps | 15 |
7 files changed, 118 insertions, 0 deletions
diff --git a/tests/ii/overload-functions/arrays.cps b/tests/ii/overload-functions/arrays.cps new file mode 100644 index 0000000..47ff46c --- /dev/null +++ b/tests/ii/overload-functions/arrays.cps @@ -0,0 +1,21 @@ +OVERLOAD FUNCTION Score(Values : ARRAY OF INTEGER, First : INTEGER, Size : INTEGER) RETURNS INTEGER + DECLARE I : INTEGER + DECLARE Total : INTEGER + Total <- 0 + FOR I <- First TO First + Size - 1 + Total <- Total + Values[I] + NEXT I + RETURN Total +ENDFUNCTION +OVERLOAD FUNCTION Score(Values : ARRAY OF REAL, First : INTEGER, Size : INTEGER) RETURNS BOOLEAN + DECLARE I : INTEGER + DECLARE Total : REAL + Total <- 0.0 + FOR I <- First TO First + Size - 1 + Total <- Total + Values[I] + NEXT I + RETURN Total > 0.0 +ENDFUNCTION +OVERLOAD FUNCTION Score(Values : ARRAY[1:2,1:2] OF INTEGER, First : INTEGER, Size : INTEGER) RETURNS INTEGER + RETURN Values[1,1] + 2 * Values[1,2] + 3 * Values[2,1] + 4 * Values[2,2] +ENDFUNCTION diff --git a/tests/ii/overload-functions/case.json b/tests/ii/overload-functions/case.json new file mode 100644 index 0000000..073cfee --- /dev/null +++ b/tests/ii/overload-functions/case.json @@ -0,0 +1,3 @@ +{ + "sources": ["program.cps", "scalar.cps", "arrays.cps"] +} diff --git a/tests/ii/overload-functions/generate.pl b/tests/ii/overload-functions/generate.pl new file mode 100644 index 0000000..33ca9f3 --- /dev/null +++ b/tests/ii/overload-functions/generate.pl @@ -0,0 +1,20 @@ +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/.."; +use Random; +my ($seed, $count) = @ARGV; +my $rng = Random->new($seed, "overload-functions"); +my @edges = ( + '0 0 1 0 x', + '-1000 1000 8 -8 boundary', + '1000 -1000 8 8 z', + '-7 2 8 -3 cancellation', + '1 -2 2 0 pair', + '-1 2 2 -1 positive', +); +$rng->emit($count, \@edges, sub { + return join ' ', $rng->integer(-1000,1000), $rng->integer(-1000,1000), + $rng->integer(1,8), $rng->integer(-8,8), + 'x' x $rng->integer(1,24); +}); diff --git a/tests/ii/overload-functions/notes.md b/tests/ii/overload-functions/notes.md new file mode 100644 index 0000000..54b3f5d --- /dev/null +++ b/tests/ii/overload-functions/notes.md @@ -0,0 +1,7 @@ +# overload-functions + +OVERLOAD is a project extension. The scalar and array overloads of Score are defined in separate imported files. Each input record exercises INTEGER, REAL and STRING argument types; different argument counts; FUNCTION and PROCEDURE sharing a name; BYREF scalar mutation; array element types and ranks; case-insensitive calls; and nested calls whose static result type selects the outer overload. + +Inputs are A, B, Size, Lower and a nonempty ASCII string. Integer array elements form the progression A + k*B for k from 0 to Size-1. REAL elements are those exact integers divided by eight. The independent C++ oracle uses the closed-form progression sum Size*A + B*Size*(Size-1)/2, its sign, and the simplified weighted matrix sum 8*A+B. The nested scalar result is 9*A+4, and the BYREF procedure changes only its destination to A+B*Size. + +Each record emits one colon-separated line. A and B stay within [-1000,1000], Size within [1,8], and Lower within [-8,8]; all arithmetic is safely bounded. Binary fractions are exactly representable, and REAL results are observed through BOOLEAN output. Fixed records cover zero, range endpoints, changing array bounds, positive/negative totals and exact cancellation. The SHA-256 generator adds the requested random count. diff --git a/tests/ii/overload-functions/program.cps b/tests/ii/overload-functions/program.cps new file mode 100644 index 0000000..ea94a93 --- /dev/null +++ b/tests/ii/overload-functions/program.cps @@ -0,0 +1,33 @@ +INCLUDE "scalar.cps" +INCLUDE "arrays.cps" +DECLARE Count : INTEGER +DECLARE Row : INTEGER +DECLARE A : INTEGER +DECLARE B : INTEGER +DECLARE Size : INTEGER +DECLARE Lower : INTEGER +DECLARE Text : STRING +DECLARE I : INTEGER +DECLARE Changed : INTEGER +INPUT Count +FOR Row <- 1 TO Count + INPUT A + INPUT B + INPUT Size + INPUT Lower + INPUT Text + DECLARE Integers : ARRAY[Lower:Lower+Size-1] OF INTEGER + DECLARE Reals : ARRAY[Lower:Lower+Size-1] OF REAL + DECLARE Matrix : ARRAY[1:2,1:2] OF INTEGER + FOR I <- Lower TO Lower + Size - 1 + Integers[I] <- A + (I - Lower) * B + Reals[I] <- (A + (I - Lower) * B) / 8 + NEXT I + Matrix[1,1] <- A + Matrix[1,2] <- B + Matrix[2,1] <- A + B + Matrix[2,2] <- A - B + Changed <- A + CALL sCoRe(Changed, B, Size) + OUTPUT Score(A), ":", Score(A / 8), ":", Score(Text), ":", Score(A, B), ":", Score(Integers, Lower, Size), ":", Score(Reals, Lower, Size), ":", Score(Matrix, Lower, Size), ":", Score(Score(A)), ":", Changed, ":", A +NEXT Row diff --git a/tests/ii/overload-functions/reference.cc b/tests/ii/overload-functions/reference.cc new file mode 100644 index 0000000..2b4b03f --- /dev/null +++ b/tests/ii/overload-functions/reference.cc @@ -0,0 +1,19 @@ +#include <cstdint> +#include <iostream> +#include <string> + +int main() { + int count; + if (!(std::cin >> count)) return 1; + for (int row = 0; row < count; ++row) { + std::int64_t a, b, size, lower; + std::string text; + if (!(std::cin >> a >> b >> size >> lower >> text)) return 1; + // Closed forms are independent of the pseudocode's loops and dispatch. + const auto sum = size * a + b * size * (size - 1) / 2; + std::cout << 3 * a + 1 << ':' << (a < 0 ? "TRUE" : "FALSE") << ':' + << text.size() + 100 << ':' << 17 * a + b << ':' << sum << ':' + << (sum > 0 ? "TRUE" : "FALSE") << ':' << 8 * a + b << ':' + << 9 * a + 4 << ':' << a + b * size << ':' << a << '\n'; + } +} diff --git a/tests/ii/overload-functions/scalar.cps b/tests/ii/overload-functions/scalar.cps new file mode 100644 index 0000000..6953662 --- /dev/null +++ b/tests/ii/overload-functions/scalar.cps @@ -0,0 +1,15 @@ +OVERLOAD FUNCTION Score(X : INTEGER) RETURNS INTEGER + RETURN 3 * X + 1 +ENDFUNCTION +OVERLOAD FUNCTION Score(X : REAL) RETURNS BOOLEAN + RETURN X < 0.0 +ENDFUNCTION +OVERLOAD FUNCTION Score(Text : STRING) RETURNS INTEGER + RETURN LENGTH(Text) + 100 +ENDFUNCTION +OVERLOAD FUNCTION Score(X : INTEGER, Y : INTEGER) RETURNS INTEGER + RETURN 17 * X + Y +ENDFUNCTION +OVERLOAD PROCEDURE Score(BYREF Value : INTEGER, BYVAL Delta : INTEGER, Repetitions : INTEGER) + Value <- Value + Delta * Repetitions +ENDPROCEDURE |
