Esempio n. 1
0
def while2() -> None:
    """While with high guard."""
    Requires(LowEvent())
    x = input_low()
    while x != 0:
        x = x - 1
    sif_print(1)
Esempio n. 2
0
def while3() -> None:
    """Termination leak."""
    x = input_high()
    while x != 0:
        x = x - 1
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(1)
Esempio n. 3
0
def fig1a() -> None:
    x = input_high()
    if x < 1234:
        x = 0
    y = x
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(y)
Esempio n. 4
0
def fig2b() -> None:
    h = input_high()
    l = input_low()
    x = f(h)
    y = f(l)
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(x)
Esempio n. 5
0
def fig2b_low() -> None:
    Requires(LowEvent())
    h = input_high()
    l = input_low()
    x = f(h)
    y = f(l)
    sif_print(y)
Esempio n. 6
0
def fig1a_low() -> None:
    Requires(LowEvent())
    x = input_low()
    if x < 1234:
        sif_print(0)
    y = x
    sif_print(y)
Esempio n. 7
0
def test_high_ref() -> None:
    Requires(LowEvent())
    h = high_ref()
    l = low_ref()
    l.append(1)
    sif_print(1)
    h.append(2)
    sif_print(2)
Esempio n. 8
0
def test_high_data() -> None:
    Requires(LowEvent())
    x = input_high()
    y = input_low()
    l = [1, y]
    l.append(x)
    sif_print(l[1])
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(l[2])
Esempio n. 9
0
def fig2a() -> None:
    x = input_high()
    if x == 1:
        l = 42
    else:
        l = 17
    l = 0
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(l)
Esempio n. 10
0
def test_high_index(low_idx: int, high_idx:int) -> None:
    Requires(LowEvent())
    Requires(low_idx >=0 and low_idx < 3)
    Requires(Low(low_idx))
    Requires(high_idx >=0 and high_idx < 3)
    Requires(Low(high_idx >= 0 and high_idx < 3))
    l = [1, 2, 3]
    sif_print(l[low_idx])
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(l[high_idx])
Esempio n. 11
0
def test_contains() -> None:
    Requires(LowEvent())
    x = input_high()
    y = input_low()
    l = [1, 2, 3]
    if y in l:
        sif_print(0)
    if x in l:
        #:: ExpectedOutput(call.precondition:assertion.false)
        sif_print(1)
Esempio n. 12
0
def while5() -> None:
    """Nested while."""
    h = input_high()
    l = input_low()
    i = 0
    while l != 0:
        while h != 0:
            i = i + 1
            h = h - 1
        l = l - 1
    #:: ExpectedOutput(call.precondition:assertion.false)
    sif_print(i)
Esempio n. 13
0
def while1() -> int:
    """While with low guard."""
    Requires(LowEvent())
    i = input_low()
    sum = 0
    while i != 0:
        Invariant(Low(i))
        Invariant(Low(sum))
        sum = sum + 1
        i = i - 1
    sif_print(sum)
    return sum
Esempio n. 14
0
def while4() -> int:
    """While with pure guard."""
    Requires(LowEvent())
    Ensures(Result() == 10)
    i = 15
    sum = 0
    while m1(i):
        Invariant(sum == 15 - i)
        Invariant(Low(i))
        Invariant(Low(m1(i)))
        Invariant(Low(sum))
        sum = sum + 1
        i = i - 1
    sif_print(sum)
    return sum
Esempio n. 15
0
def test_contains_2() -> None:
    Requires(LowEvent())
    x = input_high()
    l = [1, 2, 3]
    b = x in l
    sif_print(l[0])