summaryrefslogtreecommitdiff
path: root/tests/sources/0603_rate_limiter2.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sources/0603_rate_limiter2.c')
-rw-r--r--tests/sources/0603_rate_limiter2.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/sources/0603_rate_limiter2.c b/tests/sources/0603_rate_limiter2.c
new file mode 100644
index 0000000..32a7a17
--- /dev/null
+++ b/tests/sources/0603_rate_limiter2.c
@@ -0,0 +1,21 @@
+// This version is similar to the previous one, but the assertion is checked
+// inside the loop
+// No unrolling is necessary in this version!
+
+int X; // input
+int Y; // output
+int S; // last output
+int D; // maximum slope;
+
+Y = 0;
+while (rand(0,1)==1) {
+ X = rand(-128,128);
+ D = rand(0,16);
+ S = Y;
+ int R = X - S; // current slope
+ Y = X;
+ if (R <= -D) Y = S - D; // slope too small
+ else if (R >= D) Y = S + D; // slope too large
+
+ assert(Y >= -128 && Y <= 128);
+}