summaryrefslogtreecommitdiff
path: root/tests/limiter.scade
blob: a611d98155a5ff7988abcf0554c290d32263b7de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const bound: int = 128;

node limiter(x: int; d: int) returns (probe y: int)
    var s, r: int;
    let
        assume in_bounded: x >= -bound and x <= bound;
        guarantee out_bounded: y >= -bound and y <= bound;
        s = 0 -> pre y;
        r = x - s;
        y = if r <= -d then s - d
            else if r >= d then s + d
            else x;
    tel

node test(i: int) returns(a, b, c: int; exit: bool)
    let
        exit = i >= 30;
        a = (i * 21 + 122) mod (2 * bound) - bound;  -- not really random
        b = 16;
        c = limiter(a, b);
    tel