-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
define P(z) z == true | ||
|
||
method foo(b: Bool) returns (z: Bool) | ||
ensures P(z) { | ||
if (b) { | ||
z := true | ||
} else { | ||
z := true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Verification successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
define P(z) z == true | ||
|
||
method foo(a: Bool, bcde: Bool, c: Bool) returns (z: Bool) | ||
requires a ==> c | ||
ensures P(z) { | ||
if (a) { | ||
if (bcde) { | ||
z := !(bcde && a) // failure | ||
} else { | ||
z := (bcde && !a) | ||
} | ||
} else { | ||
if (c) { | ||
z := !(c && a) | ||
} else { | ||
z := !(!c && !a) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/resources/branchTreeTests/firstPathFails_expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Branch fails. | ||
┌─┴─┐ | ||
│ a │ | ||
└─┬─┘ | ||
F┌┴────┐T | ||
? ┌───┴───┐ | ||
│ bcde │ | ||
└───┬───┘ | ||
F┌┴──┐T | ||
? Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
define P(z) z == true | ||
|
||
method foo(a: Bool, bcde: Bool, c: Bool) returns (z: Bool) | ||
requires a ==> c | ||
ensures P(z) { | ||
if (a) { | ||
if (bcde) { | ||
z := (bcde && a) | ||
} else { | ||
z := !(bcde && !a) | ||
} | ||
} else { | ||
if (c) { | ||
z := !(c && a) | ||
} else { | ||
z := !(!c && !a) // failure | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Branch fails. | ||
┌─┴─┐ | ||
│ a │ | ||
└─┬─┘ | ||
F┌──┴────┐T | ||
┌─┴─┐ ┌───┴───┐ | ||
│ c │ │ bcde │ | ||
└─┬─┘ └───┬───┘ | ||
F┌──┴┐T F┌┴┐T | ||
Error ✔ ✔ ✔ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
define P(z) z == true | ||
|
||
method foo(b: Bool) returns (z: Bool) | ||
ensures P(z) { | ||
z := true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Verification successful. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
define P(z) z == true | ||
|
||
method foo(a: Int, b: Int, d: Bool) returns (z: Bool) | ||
ensures P(z) { | ||
var a_ : Int := a | ||
var b_ : Int := b | ||
if (d) { | ||
a_ := 3 | ||
b_ := 3 | ||
} | ||
var c: Int | ||
c := a_ / b_ | ||
z := c > 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Branch fails. | ||
┌─┴─┐ | ||
│ d │ | ||
└─┬─┘ | ||
F┌┴──┐T | ||
? Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
define P(z) z == true | ||
|
||
method foo(a: Bool, bcde: Bool, c: Bool) returns (z: Bool) | ||
requires a ==> c | ||
ensures P(z) { | ||
while (a) { | ||
if (bcde) { | ||
z := !(bcde && a) | ||
} else { | ||
z := !(bcde && !a) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Branch fails. | ||
┌─┴─┐ | ||
│ a │ | ||
└─┬─┘ | ||
F┌──┴┐T | ||
Error ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distrcibuted with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2011-2019 ETH Zurich. | ||
|
||
import org.scalatest.funsuite.AnyFunSuite | ||
import viper.silver.ast.utility.DiskLoader | ||
|
||
import java.nio.file.{Files, Paths} | ||
|
||
class BranchTreeTests extends AnyFunSuite { | ||
val frontend = tests.instantiateFrontend() | ||
|
||
test("FirstPathFails") { | ||
executeTest("firstPathFails") | ||
} | ||
|
||
test("LastPathFails") { | ||
executeTest("lastPathFails") | ||
} | ||
|
||
test("While") { | ||
executeTest("while") | ||
} | ||
|
||
test("OnlyIf") { | ||
executeTest("onlyIf") | ||
} | ||
|
||
test("AllPathsCorrect") { | ||
executeTest("allPathsCorrect") | ||
} | ||
|
||
test("NoBranches") { | ||
executeTest("noBranches") | ||
} | ||
|
||
def executeTest(fileName: String) | ||
: Unit = { | ||
val expectedFile = getClass.getClassLoader.getResource(s"branchTreeTests/"+fileName+"_expected") | ||
val expected = DiskLoader.loadContent(Paths.get(expectedFile.toURI)).get | ||
val program = tests.loadProgram("branchTreeTests/",fileName, frontend) | ||
val actual = frontend.verifier.verify(program) | ||
assert(actual.toString.contains(expected)) | ||
} | ||
} | ||
|
||
|