lab6
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| lab6 [2016/02/08 22:33] – created franck | lab6 [2020/02/03 21:07] (current) – franck | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Implement | + | ====== Lab 3 ====== |
| + | |||
| + | Implement | ||
| + | |||
| + | As an example, consider the following class. | ||
| + | < | ||
| + | public class Account { | ||
| + | private double balance; | ||
| + | |||
| + | public Account() { | ||
| + | this.balance = 0.0; | ||
| + | } | ||
| + | |||
| + | public double getBalance() { | ||
| + | return this.balance; | ||
| + | } | ||
| + | |||
| + | public void deposit(double amount) { | ||
| + | this.balance += amount; | ||
| + | } | ||
| + | |||
| + | public void withdraw(double amount) { | ||
| + | this.balance -= amount; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | The above class is used in the following app. | ||
| + | < | ||
| + | import java.util.Random; | ||
| + | |||
| + | public | ||
| + | public static void main(String[] args) { | ||
| + | Account account = new Account(); | ||
| + | |||
| + | final int LOW = 2; | ||
| + | final int MEDIUM = 3; | ||
| + | final int HIGH = 4; | ||
| + | |||
| + | Random random = new Random(); | ||
| + | account.deposit(random.nextInt(HIGH)); | ||
| + | if (!random.nextBoolean()) { | ||
| + | account.deposit(random.nextInt(LOW)); | ||
| + | if (random.nextBoolean()) { | ||
| + | // do nothing | ||
| + | } else { | ||
| + | account.withdraw(random.nextInt(MEDIUM)); | ||
| + | } | ||
| + | } else { | ||
| + | account.deposit(random.nextInt(MEDIUM)); | ||
| + | if (random.nextBoolean()) { | ||
| + | // do nothing | ||
| + | } else { | ||
| + | account.deposit(random.nextInt(LOW)); | ||
| + | } | ||
| + | } | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | To apply JPF to the above app, use the following application properties file. | ||
| + | < | ||
| + | # paths | ||
| + | classpath = < | ||
| + | native_classpath = < | ||
| + | |||
| + | # application | ||
| + | target = Finances | ||
| + | cg.enumerate_random = true | ||
| + | |||
| + | # search strategy | ||
| + | search.class = lab.FieldValueSearch | ||
| + | search.value.classname = lab.Account | ||
| + | search.value.fieldname = balance | ||
| + | |||
| + | # listener | ||
| + | listener = lab.ValuedStateSpaceDot | ||
| + | </ | ||
| + | When JPF is run on the above application properties file, it produces output similar to the following. | ||
| + | < | ||
| + | JavaPathfinder core system v8.0 (rev 32+) - (C) 2005-2014 United States Government. All rights reserved. | ||
| + | |||
| + | |||
| + | ====================================================== system under test | ||
| + | Traversal.main() | ||
| + | |||
| + | ====================================================== search started: 2/3/20 12:44 PM | ||
| + | Balance: 0.0 | ||
| + | Balance: 0.0 | ||
| + | Balance: 0.0 | ||
| + | Balance: -1.0 | ||
| + | Balance: -2.0 | ||
| + | Balance: 0.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 0.0 | ||
| + | Balance: -1.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 0.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 4.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 1.0 | ||
| + | Balance: 4.0 | ||
| + | Balance: 4.0 | ||
| + | Balance: 4.0 | ||
| + | Balance: 3.0 | ||
| + | Balance: 2.0 | ||
| + | Balance: 4.0 | ||
| + | Balance: 5.0 | ||
| + | Balance: 5.0 | ||
| + | Balance: 5.0 | ||
| + | Balance: 6.0 | ||
| + | |||
| + | ====================================================== results | ||
| + | no errors detected | ||
| + | |||
| + | ====================================================== statistics | ||
| + | elapsed time: | ||
| + | states: | ||
| + | search: | ||
| + | choice generators: | ||
| + | heap: | ||
| + | instructions: | ||
| + | max memory: | ||
| + | loaded code: classes=64, | ||
| + | |||
| + | ====================================================== search finished: 2/3/20 12:44 PM | ||
| + | </ | ||
| + | It also generates a file named statespace.dot that represents the following state space. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | To receive feedback, submit your search class using the submit command //before// Tuesday February 11:\\ | ||
| + | submit 4315 lab3 ValueSearch.java | ||
| + | |||
lab6.1454970829.txt.gz · Last modified: by franck
