lawspec 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/README.md +29 -22
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/api.mjs +14 -23
  5. package/bin/lawspec.mjs +186 -65
  6. package/build.json +255 -159
  7. package/builtin-data-names.mjs +73 -0
  8. package/core.wasm +2 -2
  9. package/examples/native-payments/clojure/lawspec.json +13 -2
  10. package/examples/native-payments/csharp/lawspec.json +13 -2
  11. package/examples/native-payments/elixir/lawspec.json +14 -3
  12. package/examples/native-payments/erlang/lawspec.json +14 -3
  13. package/examples/native-payments/fsharp/lawspec.json +14 -3
  14. package/examples/native-payments/gleam/lawspec.json +14 -3
  15. package/examples/native-payments/go/lawspec.json +14 -3
  16. package/examples/native-payments/groovy/lawspec.json +14 -3
  17. package/examples/native-payments/haskell/lawspec.json +14 -3
  18. package/examples/native-payments/java/lawspec.json +14 -3
  19. package/examples/native-payments/javascript/lawspec.json +14 -3
  20. package/examples/native-payments/kotlin/lawspec.json +14 -3
  21. package/examples/native-payments/python/lawspec.json +14 -3
  22. package/examples/native-payments/rust/lawspec.json +14 -3
  23. package/examples/native-payments/scala/lawspec.json +14 -3
  24. package/examples/native-payments/swift/lawspec.json +14 -3
  25. package/examples/native-payments/typescript/lawspec.json +14 -3
  26. package/examples/packages/orders/lawspec.json +25 -5
  27. package/examples/packages/orders/orders.lawspec +36 -34
  28. package/examples/packages/shop-domain/src/domain.lawspec +23 -21
  29. package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
  30. package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
  31. package/examples/rc1/authorization-snapshots.lawspec +112 -0
  32. package/examples/rc1/banner-filenames.lawspec +63 -0
  33. package/examples/rc1/bit-codec.lawspec +56 -0
  34. package/examples/rc1/bounded-witness-search.lawspec +144 -0
  35. package/examples/rc1/conflicting-requirements.lawspec +30 -0
  36. package/examples/rc1/constructive-witnesses.lawspec +113 -0
  37. package/examples/rc1/documentary-review.lawspec +42 -0
  38. package/examples/rc1/empty-domains.lawspec +46 -0
  39. package/examples/rc1/finite-integer-domains.lawspec +75 -0
  40. package/examples/rc1/law-metadata.lawspec +29 -0
  41. package/examples/rc1/native-payments.lawspec +107 -0
  42. package/examples/rc1/nesting/rrr.lawspec +33 -0
  43. package/examples/rc1/nesting/rru.lawspec +56 -0
  44. package/examples/rc1/nesting/rur.lawspec +57 -0
  45. package/examples/rc1/nesting/ruu.lawspec +77 -0
  46. package/examples/rc1/nesting/urr.lawspec +52 -0
  47. package/examples/rc1/nesting/uru.lawspec +72 -0
  48. package/examples/rc1/nesting/uur.lawspec +73 -0
  49. package/examples/rc1/nesting/uuu.lawspec +95 -0
  50. package/examples/rc1/order-workflow.lawspec +126 -0
  51. package/examples/rc1/parcel-measurements.lawspec +92 -0
  52. package/examples/rc1/picture-records.lawspec +51 -0
  53. package/examples/rc1/picture-tuples.lawspec +47 -0
  54. package/examples/rc1/record-payloads.lawspec +56 -0
  55. package/examples/rc1/recursive-records.lawspec +64 -0
  56. package/examples/rc1/refund-conformance.lawspec +44 -0
  57. package/examples/rc1/refund-policy.lawspec +88 -0
  58. package/examples/rc1/requirement-composition.lawspec +89 -0
  59. package/examples/rc1/structural-records.lawspec +53 -0
  60. package/examples/rc1-authoring.lawspec +56 -0
  61. package/examples-command.mjs +11 -5
  62. package/explain.mjs +112 -0
  63. package/expression-presentation.mjs +333 -0
  64. package/files.mjs +16 -0
  65. package/index.d.ts +929 -11
  66. package/lsp.mjs +231 -0
  67. package/migrate.mjs +135 -0
  68. package/migration-bindings.mjs +86 -0
  69. package/migration-cases.mjs +45 -0
  70. package/migration-collections.mjs +54 -0
  71. package/migration-correspondence.mjs +275 -0
  72. package/migration-generation.mjs +99 -0
  73. package/migration-laws.mjs +102 -0
  74. package/migration-records.mjs +166 -0
  75. package/migration-source.mjs +247 -0
  76. package/migration-write.mjs +156 -0
  77. package/native-evidence.mjs +187 -0
  78. package/native-examples.mjs +8 -1
  79. package/node-events-reporter.mjs +23 -0
  80. package/package.json +8 -1
  81. package/positional-fields.mjs +13 -0
  82. package/proof.d.ts +35 -0
  83. package/proof.mjs +174 -0
  84. package/starter-rc1.lawspec +25 -0
  85. package/templates.mjs +2 -2
  86. package/test-command.mjs +107 -35
  87. package/typed-presentation.mjs +165 -0
@@ -1,13 +1,14 @@
1
1
  unit shop.orders
2
- import shop.domain as domain (Money, Cents, `commutative`, `idempotent`)
2
+ import shop.domain as domain (Money, Cents, law "|commutative|, law
3
+ "|idempotent|)
3
4
  -- shop.domain uses version 1 of shop.tax; this project's range selects
4
5
  -- version 2. Both are in the build, and their Bands are different types.
5
6
  import shop.tax.api as tax (Band)
6
7
 
7
8
  -- Constructor names are scoped to their unit: this Usd is not domain.Usd.
8
- type Currency is | Usd | Gbp end
9
+ type Currency is one of | Usd | Gbp end type
9
10
 
10
- type Line is Line price :: Money quantity :: domain.Quantity end
11
+ type Line is a record{ price :: Money quantity :: domain.Quantity} end type
11
12
 
12
13
  settlement :: Currency -> domain.Currency
13
14
  lineTotal :: Line -> Money
@@ -17,66 +18,67 @@ cheaper :: Int64 -> Int64 -> Int64
17
18
  roundDown :: Int64 -> Int64
18
19
  classify :: Int64 -> Band
19
20
 
20
- law `dollars settle in dollars` is
21
- definition is
21
+ law "|dollars settle in dollars| is
22
+ definition :
22
23
  settlement Usd = domain.Usd
23
24
  end
24
25
  end
25
26
 
26
- law `pounds settle in euros` is
27
- definition is
27
+ law "|pounds settle in euros| is
28
+ definition :
28
29
  settlement Gbp = domain.Eur
29
30
  end
30
31
  end
31
32
 
32
- law `a line total keeps the price currency` is
33
- definition is
34
- `for all` (l :: Line) .
35
- domain.currencyOf (lineTotal l) = (match l with
36
- | Line p q -> domain.currencyOf p
37
- end)
33
+ law "|a line total keeps the price currency| is
34
+ definition :
35
+ for all (l :: Line) =>
36
+ domain.currencyOf (lineTotal l) = (first matching case of l :
37
+ when Line record{ price = p , quantity = q} then domain.currencyOf p
38
+ end case) end
38
39
  end
39
- example `two items` is
40
- l = Line (Money domain.Usd 250) (domain.Quantity 2)
40
+ example "|two items| :
41
+ l = Line record{ price = (Money record{ currency = domain.Usd , cents =
42
+ 250}) , quantity = (domain.Quantity 2)}
41
43
  expect domain.centsOf (lineTotal l) = 500
42
44
  end
43
45
  end
44
46
 
45
- law `the cheaper price does not depend on order` is
46
- definition is
47
- `commutative` cheaper
47
+ law "|the cheaper price does not depend on order| is
48
+ definition :
49
+ apply law "|commutative| cheaper
48
50
  end
49
51
  end
50
52
 
51
- law `rounding down to whole dollars is stable` is
52
- definition is
53
- `idempotent` roundDown
53
+ law "|rounding down to whole dollars is stable| is
54
+ definition :
55
+ apply law "|idempotent| roundDown
54
56
  end
55
57
  end
56
58
 
57
- law `rounding down never raises a price` is
58
- definition is
59
- `for all` (c :: Cents) . roundDown c <= c
59
+ law "|rounding down never raises a price| is
60
+ definition :
61
+ for all (c :: Cents) => roundDown c <= c end
60
62
  end
61
63
  end
62
64
 
63
- law `prices are classified into version 2 bands` is
64
- definition is
65
- `for all` (c :: Cents) . tax.rateOf (classify c) <= 25
65
+ law "|prices are classified into version 2 bands| is
66
+ definition :
67
+ for all (c :: Cents) => tax.rateOf (classify c) <= 25 end
66
68
  end
67
- example `nothing` is c = 0 expect classify c = Zero end
68
- example `small` is c = 9999 expect classify c = Low end
69
- example `large` is c = 10000 expect classify c = High end
69
+ example "|nothing| : c = 0 expect classify c = Zero end
70
+ example "|small| : c = 9999 expect classify c = Low end
71
+ example "|large| : c = 10000 expect classify c = High end
70
72
  end
71
73
 
72
- law `shop.domain keeps version 1 of the bands` is
73
- definition is
74
+ law "|shop.domain keeps version 1 of the bands| is
75
+ definition :
74
76
  domain.dutyOf domain.High = 20
75
77
  end
76
78
  end
77
79
 
78
- law `this project sees version 2 of the bands` is
79
- definition is
80
+ law "|this project sees version 2 of the bands| is
81
+ definition :
80
82
  tax.rateOf High = 25
81
83
  end
82
84
  end
@@ -8,35 +8,37 @@ export Band
8
8
  -- A package of reusable types, refinements, definitions and laws. Other units
9
9
  -- import it by name; its declarations keep their own names, so an importer may
10
10
  -- declare a Currency or a Usd of its own.
11
- type Currency is | Usd | Eur end
11
+ type Currency is one of | Usd | Eur end type
12
12
 
13
13
  refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end
14
14
 
15
- type Money is Money currency :: Currency cents :: Cents end
15
+ type Money is a record{ currency :: Currency cents :: Cents} end type
16
16
 
17
17
  wrapper Quantity is Int32 where value >= 1 && value <= 1000 end
18
18
 
19
- definition currencyOf (m :: Money) :: Currency is
20
- match m with | Money c n -> c end
21
- end
19
+ function currencyOf (m :: Money) -> Currency is
20
+ first matching case of m : when Money record{ currency = c , cents = n} then c
21
+ end case
22
+ end function
22
23
 
23
- definition centsOf (m :: Money) :: Int64 is
24
- match m with | Money c n -> n end
25
- end
24
+ function centsOf (m :: Money) -> Int64 is
25
+ first matching case of m : when Money record{ currency = c , cents = n} then n
26
+ end case
27
+ end function
26
28
 
27
29
  -- The duty on a band, at version 1's rates.
28
- definition dutyOf (b :: Band) :: Int64 is tax.rateOf b end
30
+ function dutyOf (b :: Band) -> Int64 is tax.rateOf b end function
29
31
 
30
32
  -- Generic laws are templates: an importer applies them to its own adapters.
31
- law `commutative` (f :: a -> a -> a) requires Eq a is
32
- definition is
33
- `for all` (x :: a) (y :: a) . f x y = f y x
33
+ law "|commutative| (f :: a -> a -> a) requires Eq a is
34
+ definition :
35
+ for all (x :: a) (y :: a) => f x y = f y x end
34
36
  end
35
37
  end
36
38
 
37
- law `idempotent` (f :: a -> a) requires Eq a is
38
- definition is
39
- `for all` (x :: a) . f (f x) = f x
39
+ law "|idempotent| (f :: a -> a) requires Eq a is
40
+ definition :
41
+ for all (x :: a) => f (f x) = f x end
40
42
  end
41
43
  end
42
44
 
@@ -44,14 +46,14 @@ end
44
46
  -- convert and is tested against these laws.
45
47
  convert :: Currency -> Money -> Money
46
48
 
47
- law `conversion targets the requested currency` is
48
- definition is
49
- `for all` (c :: Currency) (m :: Money) . currencyOf (convert c m) = c
49
+ law "|conversion targets the requested currency| is
50
+ definition :
51
+ for all (c :: Currency) (m :: Money) => currencyOf (convert c m) = c end
50
52
  end
51
53
  end
52
54
 
53
- law `converting to the same currency changes nothing` is
54
- definition is
55
- `for all` (m :: Money) . convert (currencyOf m) m = m
55
+ law "|converting to the same currency changes nothing| is
56
+ definition :
57
+ for all (m :: Money) => convert (currencyOf m) m = m end
56
58
  end
57
59
  end
@@ -1,8 +1,8 @@
1
1
  unit shop.tax.rates
2
2
 
3
3
  -- Version 1 of the tax bands.
4
- type Band is | Low | High end
4
+ type Band is one of | Low | High end type
5
5
 
6
- definition rateOf (b :: Band) :: Int64 is
7
- match b with | Low -> 5 | High -> 20 end
8
- end
6
+ function rateOf (b :: Band) -> Int64 is
7
+ first matching case of b : when Low then 5 when High then 20 end case
8
+ end function
@@ -2,8 +2,9 @@ unit shop.tax.rates
2
2
 
3
3
  -- Version 2 adds a zero band and changes the rates. A build may hold both
4
4
  -- versions: each dependent sees the one its version range selects.
5
- type Band is | Zero | Low | High end
5
+ type Band is one of | Zero | Low | High end type
6
6
 
7
- definition rateOf (b :: Band) :: Int64 is
8
- match b with | Zero -> 0 | Low -> 10 | High -> 25 end
9
- end
7
+ function rateOf (b :: Band) -> Int64 is
8
+ first matching case of b : when Zero then 0 when Low then 10 when High then 25
9
+ end case
10
+ end function
@@ -0,0 +1,112 @@
1
+ unit example.rc1.authorizationSnapshots
2
+
3
+ type Payment is one of
4
+ | FirstPayment
5
+ | SecondPayment
6
+ end type
7
+
8
+ type Authorization is one of
9
+ | FirstApproval
10
+ | SecondApproval
11
+ end type
12
+
13
+ type AuthorizationState is one of
14
+ | Ready
15
+ | FirstRevoked
16
+ | AllRevoked
17
+ end type
18
+
19
+ function active (state of type AuthorizationState)
20
+ (authorization of type Authorization) -> Bool is
21
+ first matching case of state:
22
+ when Ready then true
23
+ when FirstRevoked then authorization = SecondApproval
24
+ when AllRevoked then false
25
+ end case
26
+ end function
27
+
28
+ function authorizes (authorization of type Authorization)
29
+ (payment of type Payment) -> Bool is
30
+ first matching case of authorization:
31
+ when FirstApproval then payment = FirstPayment
32
+ when SecondApproval then payment = SecondPayment
33
+ end case
34
+ end function
35
+
36
+ law "|ready payments have authorization| is
37
+ definition:
38
+ for all (payment of type Payment) =>
39
+ there must exist an (authorization of type Authorization
40
+ where active Ready the authorization) such that
41
+ authorization `authorizes payment
42
+ end
43
+ end
44
+ end
45
+
46
+ description:
47
+ "The Ready snapshot contains an active approval for each payment."
48
+ end
49
+ end
50
+
51
+ law "|the revoked first approval is absent| is
52
+ definition:
53
+ there does not exist (authorization of type Authorization
54
+ where active FirstRevoked the authorization) such that
55
+ authorization `authorizes FirstPayment
56
+ end
57
+ end
58
+
59
+ description:
60
+ "The FirstRevoked snapshot has no active approval for the first payment."
61
+ end
62
+ end
63
+
64
+ law "|all revoked approvals are absent| is
65
+ definition:
66
+ for all (payment of type Payment) =>
67
+ there must not exist (authorization of type Authorization
68
+ where active AllRevoked the authorization) such that
69
+ authorization `authorizes payment
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ law "|one approval cannot cover every payment| is
76
+ definition:
77
+ must not there exists (authorization of type Authorization) such that
78
+ for all (payment of type Payment) =>
79
+ authorization `authorizes payment
80
+ end
81
+ end
82
+ end
83
+
84
+ rationale:
85
+ "Each approval belongs to one payment. Quantifier order changes the claim."
86
+ end
87
+ end
88
+
89
+ law "|activation matches the complete snapshot| is
90
+ definition:
91
+ for all (state of type AuthorizationState)
92
+ (authorization of type Authorization) =>
93
+ active state authorization must be
94
+ (state = Ready or
95
+ (state = FirstRevoked and authorization = SecondApproval))
96
+ end
97
+ end
98
+
99
+ expect active state authorization = expected
100
+ in table (state, authorization, expected):
101
+ row Ready, FirstApproval, true
102
+ row Ready, SecondApproval, true
103
+ row FirstRevoked, FirstApproval, false
104
+ row FirstRevoked, SecondApproval, true
105
+ row AllRevoked, FirstApproval, false
106
+ row AllRevoked, SecondApproval, false
107
+ end
108
+
109
+ description:
110
+ "The search domain is exactly two approval identities in one snapshot."
111
+ end
112
+ end
@@ -0,0 +1,63 @@
1
+ unit pictures.banners
2
+
3
+ type Picture is a record{
4
+ fileName of type Text
5
+ dimensions of type record{
6
+ width of type Nat
7
+ height of type Nat
8
+ }
9
+ }
10
+ end type
11
+
12
+ type BannerDecision is one of
13
+ | Rejected of type Text
14
+ | Eligible
15
+ | TooSmall
16
+ end type
17
+
18
+ function containsProfanity (input of type Text) -> Bool is
19
+ let folded = prelude.caseFold input in
20
+ prelude.any (prelude.textContains folded) ["shit", "piss", "fuck"]
21
+ end function
22
+
23
+ function bannerDecision (picture of type Picture) -> BannerDecision is
24
+ first matching case of picture.fileName:
25
+ when containsProfanity it then Rejected it
26
+ otherwise
27
+ if picture.dimensions.width >= 1200 and picture.dimensions.height >= 300
28
+ then
29
+ Eligible
30
+ else
31
+ TooSmall
32
+ end if
33
+ end case
34
+ end function
35
+
36
+ law "|prohibited filenames are rejected before checking dimensions| is
37
+ description:
38
+ "A prohibited fragment rejects the filename at every size. Clean banners need at least 1200 pixels of width and 300 pixels of height."
39
+ end
40
+ definition:
41
+ for all (picture of type Picture) =>
42
+ containsProfanity picture.fileName implies
43
+ bannerDecision picture must be Rejected picture.fileName
44
+ end
45
+ end
46
+ expect bannerDecision picture = expected
47
+ in table (picture, expected):
48
+ row Picture record{fileName = "banner.png", dimensions = record{width =
49
+ 1200, height = 300}}, Eligible
50
+ row Picture record{fileName = "portrait.png", dimensions = record{width =
51
+ 100, height = 100}}, TooSmall
52
+ row Picture record{fileName = "SHIT.png", dimensions = record{width = 1200,
53
+ height = 300}}, Rejected "SHIT.png"
54
+ row Picture record{fileName = "xxpIssxx.jpg", dimensions = record{width = 1,
55
+ height = 1}}, Rejected "xxpIssxx.jpg"
56
+ row Picture record{fileName = "PIẞ.png", dimensions = record{width = 1,
57
+ height = 1}}, Rejected "PIẞ.png"
58
+ row Picture record{fileName = "ſhit.png", dimensions = record{width = 1,
59
+ height = 1}}, Rejected "ſhit.png"
60
+ row Picture record{fileName = "fucK.png", dimensions = record{width = 1,
61
+ height = 1}}, Rejected "fucK.png"
62
+ end
63
+ end
@@ -0,0 +1,56 @@
1
+ unit example.rc1.bitCodec
2
+
3
+ mapping bitText of type Bool -> Text is
4
+ row false, "0"
5
+ row true, "1"
6
+ end mapping
7
+
8
+ function decodeBit (text of type Text) -> Maybe Bool is
9
+ bitTextInverse text
10
+ end function
11
+
12
+ function "|decode with zero default| (text of type Text) -> Bool is
13
+ first matching case of decodeBit text:
14
+ when Just bit then bit
15
+ when Nothing then false
16
+ end case
17
+ end function
18
+
19
+ law "|each bit is recovered| is
20
+ definition:
21
+ for all (bit of type Bool) =>
22
+ decodeBit (bitText bit) must be Just bit
23
+ end
24
+ end
25
+
26
+ description:
27
+ "Each bit has a one-character encoding that decodes to the original bit."
28
+ end
29
+
30
+ expect bitText bit = encoded
31
+ expect decodeBit encoded = decoded
32
+ in table (bit, encoded, decoded):
33
+ row false, "0", Just false
34
+ row true, "1", Just true
35
+ end
36
+ end
37
+
38
+ law "|decoding is a left inverse| is
39
+ definition:
40
+ apply law "|left inverse| "|decode with zero default| bitText
41
+ end
42
+
43
+ description:
44
+ "Decoding an encoded bit recovers it. The inverse is the first argument."
45
+ end
46
+ end
47
+
48
+ law "|other text has no bit| is
49
+ definition:
50
+ decodeBit "01" must be Nothing
51
+ end
52
+
53
+ description:
54
+ "Two characters are not one encoded bit. Invalid input has no decoded value."
55
+ end
56
+ end
@@ -0,0 +1,144 @@
1
+ unit example.rc1.boundedWitnessSearch
2
+
3
+ type RequestLabel is a record{
4
+ text of type Text
5
+ }
6
+ end type
7
+
8
+ function keepValue (value of type a) -> a is
9
+ value
10
+ end function
11
+
12
+ function reply (allowed of type Bool) -> Integer is
13
+ if allowed then 1 else 2 end if
14
+ end function
15
+
16
+ function labelFor (allowed of type Bool) -> RequestLabel is
17
+ RequestLabel record{
18
+ text = if allowed then "approved" else "declined" end if
19
+ }
20
+ end function
21
+
22
+ law "|each request can receive its matching reply| is
23
+ description:
24
+ "Allowed requests receive reply one; other requests receive reply two."
25
+ end
26
+ definition:
27
+ for all (allowed of type Bool) =>
28
+ there exists (answer of type Integer) such that
29
+ answer must be reply allowed
30
+ end
31
+ end
32
+ end
33
+ expect reply allowed = expected
34
+ in table (allowed, expected):
35
+ row true, 1
36
+ row false, 2
37
+ end
38
+ end
39
+
40
+ law "|each request can receive its matching label| is
41
+ definition:
42
+ for all (allowed of type Bool) =>
43
+ there exists (label of type RequestLabel) such that
44
+ label.text must be (if allowed then "approved" else "declined" end if)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ law "|an adjusted amount can exceed any exact amount| is
51
+ definition:
52
+ for all (amount of type Integer) =>
53
+ there exists (adjusted of type Integer where adjusted > amount) such that
54
+ adjusted > amount
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ law "|a small amount cannot be both positive and nonpositive| is
61
+ definition:
62
+ there must not exist (amount of type Integer where
63
+ amount >= 0 and amount <= 3) such that
64
+ amount > 0 and amount <= 0
65
+ end
66
+ end
67
+ end
68
+
69
+ law "|independent requirements can choose distinct amounts| is
70
+ definition:
71
+ (there exists (amount of type Integer) such that amount = 1 end)
72
+ and
73
+ (there exists (amount of type Integer) such that amount = 2 end)
74
+ end
75
+ end
76
+
77
+ law "|a dependent strategy can propose the adjusted count| is
78
+ definition:
79
+ there exists (count of type Integer) such that
80
+ count must be 4
81
+ end
82
+ end
83
+ end
84
+
85
+ law "|an exceptional request can receive a manual category| is
86
+ definition:
87
+ there exists (category of type Text) such that
88
+ category must be "manual"
89
+ end
90
+ end
91
+ end
92
+
93
+ law "|consecutive exact cents have no intermediate amount| is
94
+ definition:
95
+ for all (amount of type Integer)
96
+ (between of type Integer where between > amount and between < amount + 1)
97
+ =>
98
+ false
99
+ end
100
+ end
101
+ end
102
+
103
+ law "|exact amounts are not all zero| is
104
+ definition:
105
+ must not for all (amount of type Integer) =>
106
+ amount = 0
107
+ end
108
+ end
109
+ end
110
+
111
+ harness example.rc1.boundedWitnessSearch.testing for example.rc1.boundedWitnessSearch is
112
+ strategy replies of type Integer is one of 1, 2 end
113
+ strategy labels of type RequestLabel is
114
+ one of keepValue (labelFor true), keepValue (labelFor false)
115
+ end
116
+ strategy firstAmount of type Integer is one of 1 end
117
+ strategy secondAmount of type Integer is one of 2 end
118
+ strategy bases of type Integer is one of 0, 3 end
119
+ strategy counts of type Integer is
120
+ (bind base of type Integer from bases in one of base + 1)
121
+ such that it > 0
122
+ end
123
+ strategy ordinaryCategory of type Text is one of "automatic" end
124
+ strategy manualCategory of type Text is one of "manual" end
125
+ strategy categories of type Text is
126
+ frequency 3 ordinaryCategory, 1 manualCategory
127
+ end
128
+ strategy nonzeroAmount of type Integer is one of 1 end
129
+
130
+ for law "|each request can receive its matching reply|
131
+ witness 0 for allowed.answer
132
+ use replies for definition.allowed.answer
133
+ for law "|each request can receive its matching label|
134
+ use labels for allowed.label
135
+ for law "|independent requirements can choose distinct amounts|
136
+ use firstAmount for branch1.amount
137
+ use secondAmount for definition.branch2.amount
138
+ for law "|a dependent strategy can propose the adjusted count|
139
+ use counts for count
140
+ for law "|an exceptional request can receive a manual category|
141
+ use categories for category
142
+ for law "|exact amounts are not all zero|
143
+ use nonzeroAmount for amount
144
+ end
@@ -0,0 +1,30 @@
1
+ unit example.conflictingRefunds
2
+
3
+ type RefundDecision is one of
4
+ | Approved
5
+ | ReviewRequired
6
+ end type
7
+
8
+ function proposedDecision (flagged of type Bool) -> RefundDecision is
9
+ if flagged then ReviewRequired else Approved end if
10
+ end function
11
+
12
+ law "|every request is approved| is
13
+ description:
14
+ "The first requirement demands approval even when a request is flagged."
15
+ end
16
+ definition:
17
+ for all (flagged of type Bool) =>
18
+ proposedDecision flagged must be Approved
19
+ end
20
+ end
21
+ end
22
+
23
+ law "|a flagged request requires review| is
24
+ description:
25
+ "The second requirement demands a different result for the same request."
26
+ end
27
+ definition:
28
+ proposedDecision true must be ReviewRequired
29
+ end
30
+ end