Last active 23 hours ago

An example of turning pseudocode into a functional model.

account-test.nv Raw Playground
1|# First, we need to import conditional statements. #|
2||'@include' https://gist.nouveau.community/june/72f7794abbf64eb3890e2715d7e7789b/raw/HEAD/conditional.nv
3
4|# Let's try something. #|
5||:: test the happy path
6 :: log in as june
7 :: transfer 100 from 1234 to 5678
8 :: log out
9
10||:: test the sad path
11 :: log in as june
12 :: transfer 100 from 1234 to 5678
13 :: log out
14
15|:: test the happy path|
16 :test modifiers:
17 . authorized user
18 . sufficient funds
19
20|:: test the sad path|
21 :test modifiers:
22 . unauthorized user
23 . insufficient funds
24
25
26
27
28|# Our abstract pseudocode. #|
29|:: transfer $amount from $source to $destination :user: $user?|
30 :: ensure the user is authorized to use $source
31 :: ensure account $source has a minimum balance of $amount
32 :: start a database transaction
33 :: withdraw $amount from $source
34 :: deposit $amount into $dest
35 :: commit changes to the database
36
37|:: ensure the user is authorized to use $account|
38 :: if :: the user is not authorized to use $source :: then
39 :: unauthorized user
40 :: end
41
42|:: ensure account $account has a minimum balance of $amount|
43 :: if :: the balance of $account is lower than $amount :: then
44 :: insufficient funds
45 :: end
46
47
48|# A set of mocks. #|
49|:: log in as $user| :user: $user
50|:: log out :user: $user|
51
52|:: the user is not authorized to use $account :test modifiers: unauthorized user |
53|:: the balance of $source is lower than $amount :test modifiers: insufficient funds|
54|:: the user is not authorized to use $account :test modifiers: authorized user | :: fail
55|:: the balance of $source is lower than $amount :test modifiers: sufficient funds | :: fail
56
57|:: start a database transaction |
58|:: withdraw $amount from $account| :withdraw succeeded:
59|:: deposit $amount into $account | :deposit succeeded:
60|:: commit changes to the database| :commit successful: