- (10 min) - Presentation
- (5 min.) - Problem statement
- (40 min.) - Playing with the code
- (2 min.) - New feature statement
- (20 min.) - Playing with the code
- (13 min.) - Retrospective
Combining clojure.spec with design recipes
Presentation PDF with closed-captioned
- The ``main
branch may suffer changes after publication day, until just before the beginning of the workshop. In that case, you will havo to perform a
git pull -r`. We let you know about this at the beginning of the workshop.
- An github account.
- Git installed.
- Clojure 1.10.2 + the Clojure CLI tools installed.
- Your favourite IDE already set up. Editor as IDE.
git clone [email protected]:diegosanchez/bob-2021--combining-clojure-spec-with-design-recipes.git bob-2021
cd bob-2021
clojure -M:test:runner
Expected output:
Running tests in #{"test"}
Testing ws.prepaid-test
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
clojure -X:use-case
Expected output:
Entry point for testing the use case from CLI...
Args: {:key-simple 1, :key-map-value {:v1 "a", :v2 "b"}}
Calling use case...
1 {:v1 "a", :v2 "b"}
It's common to see the usage of a prepaid card to pay for a public transport ride. This prepaid card allows users to pay for a public transport ride.
When a user first buys a prepaid card she/he pays an initial amount of money named initial-balance. Every time a user pays for a ride, her/him consumes money from the prepaid card. A user can increase the card balance by depositing money.
The card can be used in two different modes:
- Standard: If the card balance is
B
and the user has to payR
, the payment successes whetherR <= B
.
Finally, every transaction has to be record into the contactless card.
For the sake of simplicity:
- Money amounts are represented as integers.
- the Transaction record can only have one amount per transaction.
- we have published a plausible solution (definitely, not the only possible one!) on branch
solution/aPossibleOne
.
Possible use cases include:
-
If the user has to pay 10, and his/her card balance is 100, then the payment is accomplished. Then, the card has a new record with -10 and the balance is 90.
-
If the user has to pay 20, and his/her card balance is 10, then the payment is not accomplished. There is neither a new record nor a balance change.
Some common tasks below.
Task | Command |
---|---|
Run all tests | clojure -M:test:runner |
Run unstable tests | clojure -M:test:runner -i, --include unstable |
Run stable tests | clojure -M:test:runner -e, --exclude unstable |
Run the use case | clojure -X:use-case |
Copyright © 2021, Diego Sánchez and Leandro Doctors.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Additional permission under GNU AGPL version 3 section 7:
If you modify this Program, or any covered work, by linking or combining it with Clojure (or a modified version of that library), containing parts covered under the same terms as Clojure (currently, the Eclipse Public License version 1.0), the licensors of this Program grant you additional permission to convey the resulting work. Corresponding Source for a non-source form of such a combination shall include the source code for the parts of Clojure used as well as that of the covered work.