Skip to content

Commit 5f6cba9

Browse files
committed
Add Downloader DFA
1 parent 96e381a commit 5f6cba9

File tree

9 files changed

+9
-7
lines changed

9 files changed

+9
-7
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Here, we specify that this object can only be in two states: `on` or `off`. Then
144144

145145
This object has two methods, `turnOn` and `turnOff`. From the state refinements, we can see that the method `turnOn` can only be called when the object is in state `off` transiting to state `on`. Similarly, the method `turnOff` can only be called when the object is in state `on`, transiting to state `off`. This means that we cannot call the same method twice in a row, since it would violate the protocol established by the state refinements. The following DFA illustrates this:
146146

147-
![Light Bulb DFA](./images/light_bulb_dfa.png)
147+
![Light Bulb DFA](./docs/images/light_bulb_dfa.png)
148148

149149
> Uncomment line 22 to observe the error and then comment it back again.
150150
@@ -154,7 +154,7 @@ This object has two methods, `turnOn` and `turnOff`. From the state refinements,
154154
155155
For example, we want to ensure that the `pause` method can only be called when the player is playing, and that the `stop` method can only be called when the player is not stopped (you can either use the `!` or the `||` operator for this). The state transitions are represented by the following DFA:
156156

157-
![Media Player DFA](./images/media_player_dfa.png)
157+
![Media Player DFA](./docs/images/media_player_dfa.png)
158158

159159
If you get stuck, here are some **hints**:
160160

@@ -173,7 +173,7 @@ To demonstrate the state refinements in a real world scenario, let's learn about
173173
174174
Here, we refine the `Socket` class through state refinements, with the possible states being `unconnected`, `bound`, `connected`, and `closed`. Then, for each method, we specify the allowed state transitions. This way, we can ensure that, for example, the `connect` method can only be called after the `bind` method, and that the `close` method can only be called once. The following DFA details the allowed state transitions:
175175

176-
![Socket DFA](./images/socket_dfa.png)
176+
![Socket DFA](./docs/images/socket_dfa.png)
177177

178178
> Open [SocketExample.java](./src/main/java/com/tutorial/part3/SocketExample.java).
179179
@@ -187,7 +187,7 @@ Let's refine another external class.
187187
188188
We want to ensure that the `lock` method can only be called in the `unlocked` state, and that the `unlock` method can only be called in the `locked` state. These transitions are represented by the following DFA:
189189

190-
![ReentrantLock DFA](./images/reentrant_lock_dfa.png)
190+
![ReentrantLock DFA](./docs/images/reentrant_lock_dfa.png)
191191

192192
With the correct implementation, LiquidJava will report an error in line 10 of [ReentrantLockExample.java](./src/main/java/com/tutorial/part3/exercise/ReentrantLockExample.java), since we are trying to unlock a lock that is not locked. Remember to fix the error before moving on.
193193

@@ -224,7 +224,9 @@ With the correct implementation, LiquidJava will report an error in line 11 of [
224224

225225
> Open [Downloader.java](./src/main/java/com/tutorial/part5/Downloader.java). Your task is to refine the `Downloader` class by replacing the `"true"` refinements with the appropriate ones to ensure the correct behavior of the `start`, `updateProgress`, `complete` and `getFile` methods, using the `progress` ghost variable to keep track of the download progress (from `0` to `100`), and not allow incorrect uses of these methods.
226226
227-
You will have to use most of the concepts learned throughout this tutorial, including refinement aliases, state refinements, and ghost variables.
227+
You will have to use most of the concepts learned throughout this tutorial, including refinement aliases, state refinements, and ghost variables. The following DFA illustrates the allowed state transitions:
228+
229+
![Downloader DFA](./docs/images/downloader_dfa.png)
228230

229231
If you get stuck, here are some **hints**:
230232

File renamed without changes.

docs/images/downloader_dfa.png

67.1 KB
Loading
File renamed without changes.

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<link rel="icon" type="image/png" href="lj.png" />
4+
<link rel="icon" type="image/png" href="images/lj.png" />
55
<title>LiquidJava Quiz</title>
66
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
77
<meta charset="utf-8">
@@ -49,7 +49,7 @@
4949
<div class="container">
5050
<br />
5151
<h1>LiquidJava Quiz</h1>
52-
<img src="banner.gif" alt="LiquidJava Banner"/>
52+
<img src="images/banner.gif" alt="LiquidJava Banner"/>
5353
<hr>
5454
<ol>
5555
<li>

0 commit comments

Comments
 (0)