summaryrefslogtreecommitdiff
path: root/tests/sources/0603_rate_limiter2.c
blob: 32a7a17a7cfe88c3593d98a412082fa50af8c3d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
}