def while2() -> None: """While with high guard.""" Requires(LowEvent()) x = input_low() while x != 0: x = x - 1 sif_print(1)
def while3() -> None: """Termination leak.""" x = input_high() while x != 0: x = x - 1 #:: ExpectedOutput(call.precondition:assertion.false) sif_print(1)
def fig1a() -> None: x = input_high() if x < 1234: x = 0 y = x #:: ExpectedOutput(call.precondition:assertion.false) sif_print(y)
def fig2b() -> None: h = input_high() l = input_low() x = f(h) y = f(l) #:: ExpectedOutput(call.precondition:assertion.false) sif_print(x)
def fig2b_low() -> None: Requires(LowEvent()) h = input_high() l = input_low() x = f(h) y = f(l) sif_print(y)
def fig1a_low() -> None: Requires(LowEvent()) x = input_low() if x < 1234: sif_print(0) y = x sif_print(y)
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)
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])
def fig2a() -> None: x = input_high() if x == 1: l = 42 else: l = 17 l = 0 #:: ExpectedOutput(call.precondition:assertion.false) sif_print(l)
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])
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)
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)
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
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
def test_contains_2() -> None: Requires(LowEvent()) x = input_high() l = [1, 2, 3] b = x in l sif_print(l[0])