aboutsummaryrefslogtreecommitdiff
path: root/tests/ii/arithmetic
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ii/arithmetic')
-rw-r--r--tests/ii/arithmetic/notes.md2
-rw-r--r--tests/ii/arithmetic/program.cps18
-rw-r--r--tests/ii/arithmetic/reference.cc5
3 files changed, 23 insertions, 2 deletions
diff --git a/tests/ii/arithmetic/notes.md b/tests/ii/arithmetic/notes.md
index 947a3fa..d152e29 100644
--- a/tests/ii/arithmetic/notes.md
+++ b/tests/ii/arithmetic/notes.md
@@ -3,3 +3,5 @@
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.
+
+Nested IF classifies the sign; CASE tests an inclusive -10..10 range before an overlapping zero label, so zero must select the first range. The oracle computes these results without reproducing the pseudocode control flow.
diff --git a/tests/ii/arithmetic/program.cps b/tests/ii/arithmetic/program.cps
index 7c4bf52..e13381b 100644
--- a/tests/ii/arithmetic/program.cps
+++ b/tests/ii/arithmetic/program.cps
@@ -3,10 +3,26 @@ DECLARE Index : INTEGER
DECLARE A : INTEGER
DECLARE B : INTEGER
DECLARE Small : INTEGER
+DECLARE Sign : INTEGER
+DECLARE Band : 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
+ IF A < 0 THEN
+ Sign <- -1
+ ELSE
+ IF A = 0 THEN
+ Sign <- 0
+ ELSE
+ Sign <- 1
+ ENDIF
+ ENDIF
+ CASE OF Small
+ -10 TO 10 : Band <- 2
+ 0 : Band <- 99
+ OTHERWISE : Band <- 3
+ ENDCASE
+ OUTPUT A < B, ":", A DIV B, ":", A MOD B, ":", Small + B, ":", Small - B, ":", Small * B, ":", Sign, ":", Band
NEXT Index
diff --git a/tests/ii/arithmetic/reference.cc b/tests/ii/arithmetic/reference.cc
index 6d3d98f..3e0b27f 100644
--- a/tests/ii/arithmetic/reference.cc
+++ b/tests/ii/arithmetic/reference.cc
@@ -7,7 +7,10 @@ int main() {
std::int64_t a, b;
if (!(std::cin >> a >> b) || b == 0) return 1;
auto small = a % 1000001;
+ int sign = (a > 0) - (a < 0);
+ int band = small >= -10 && small <= 10 ? 2 : 3;
std::cout << (a < b ? "TRUE" : "FALSE") << ':' << a / b << ':' << a % b
- << ':' << small + b << ':' << small - b << ':' << small * b << '\n';
+ << ':' << small + b << ':' << small - b << ':' << small * b
+ << ':' << sign << ':' << band << '\n';
}
}