lawspec 0.25.0 → 0.27.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.
- package/CHANGELOG.md +109 -1
- package/NORMALIZATION-LICENSES.txt +296 -0
- package/README.md +13 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +114 -79
- package/build.json +99 -117
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/doctor.mjs +14 -4
- package/examples/native-payments/clojure/lawspec.json +1 -1
- package/examples/native-payments/csharp/lawspec.json +1 -1
- package/examples/native-payments/elixir/lawspec.json +1 -1
- package/examples/native-payments/erlang/lawspec.json +1 -1
- package/examples/native-payments/fsharp/lawspec.json +1 -1
- package/examples/native-payments/gleam/lawspec.json +1 -1
- package/examples/native-payments/go/lawspec.json +1 -1
- package/examples/native-payments/groovy/lawspec.json +1 -1
- package/examples/native-payments/haskell/lawspec.json +1 -1
- package/examples/native-payments/java/lawspec.json +1 -1
- package/examples/native-payments/javascript/lawspec.json +1 -1
- package/examples/native-payments/kotlin/lawspec.json +1 -1
- package/examples/native-payments/prolog/lawspec.json +20 -0
- package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
- package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
- package/examples/native-payments/python/lawspec.json +1 -1
- package/examples/native-payments/rust/lawspec.json +1 -1
- package/examples/native-payments/scala/lawspec.json +1 -1
- package/examples/native-payments/swift/lawspec.json +1 -1
- package/examples/native-payments/typescript/lawspec.json +1 -1
- package/examples/packages/orders/lawspec.json +1 -1
- package/examples/packages/orders/orders.lawspec +27 -25
- package/examples/packages/shop-domain/src/domain.lawspec +15 -14
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
- package/examples/rc1/authorization-snapshots.lawspec +24 -23
- package/examples/rc1/banner-filenames.lawspec +7 -6
- package/examples/rc1/bit-codec.lawspec +12 -11
- package/examples/rc1/bounded-witness-search.lawspec +52 -45
- package/examples/rc1/conflicting-requirements.lawspec +8 -7
- package/examples/rc1/constructive-witnesses.lawspec +40 -33
- package/examples/rc1/documentary-review.lawspec +9 -8
- package/examples/rc1/empty-domains.lawspec +16 -15
- package/examples/rc1/finite-integer-domains.lawspec +24 -23
- package/examples/rc1/law-metadata.lawspec +6 -5
- package/examples/rc1/native-payments.lawspec +17 -16
- package/examples/rc1/nesting/rrr.lawspec +4 -3
- package/examples/rc1/nesting/rru.lawspec +7 -6
- package/examples/rc1/nesting/rur.lawspec +7 -6
- package/examples/rc1/nesting/ruu.lawspec +10 -9
- package/examples/rc1/nesting/urr.lawspec +7 -6
- package/examples/rc1/nesting/uru.lawspec +10 -9
- package/examples/rc1/nesting/uur.lawspec +10 -9
- package/examples/rc1/nesting/uuu.lawspec +13 -12
- package/examples/rc1/order-workflow.lawspec +18 -17
- package/examples/rc1/parcel-measurements.lawspec +14 -13
- package/examples/rc1/picture-records.lawspec +6 -5
- package/examples/rc1/picture-tuples.lawspec +6 -5
- package/examples/rc1/record-payloads.lawspec +12 -11
- package/examples/rc1/recursive-records.lawspec +11 -10
- package/examples/rc1/refund-conformance.lawspec +7 -6
- package/examples/rc1/refund-policy.lawspec +15 -14
- package/examples/rc1/requirement-composition.lawspec +26 -25
- package/examples/rc1/structural-records.lawspec +13 -12
- package/examples/rc1-authoring.lawspec +6 -5
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +19 -18
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +68 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +7 -6
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +161 -160
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +7 -7
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +10 -528
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-evidence.mjs +25 -12
- package/native-examples.mjs +3 -3
- package/package.json +2 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +88 -5
- package/test-command.mjs +40 -4
- package/migrate.mjs +0 -135
- package/migration-bindings.mjs +0 -86
- package/migration-cases.mjs +0 -45
- package/migration-collections.mjs +0 -54
- package/migration-correspondence.mjs +0 -275
- package/migration-generation.mjs +0 -99
- package/migration-laws.mjs +0 -102
- package/migration-records.mjs +0 -166
- package/migration-source.mjs +0 -247
- package/migration-write.mjs +0 -156
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"languageProfile": "1.0-rc.2",
|
|
4
|
+
"sources": ["laws"],
|
|
5
|
+
"machineBits": 64,
|
|
6
|
+
"verification": {"layers": ["proof", "exhaustive", "property", "examples", "runtime", "model"]},
|
|
7
|
+
"targets": [{
|
|
8
|
+
"language": "prolog", "root": ".",
|
|
9
|
+
"nativeBindings": {
|
|
10
|
+
"functions": [
|
|
11
|
+
{"declaration": "example.payments::addFee", "native": ["domain", "payments", "apply_fee"]},
|
|
12
|
+
{"declaration": "example.payments::roundTrip", "native": ["domain", "payments", "restore"]},
|
|
13
|
+
{"declaration": "example.payments::archive", "native": ["domain", "payments", "store"]}
|
|
14
|
+
],
|
|
15
|
+
"generators": [
|
|
16
|
+
{"type": "example.payments::type::Money", "factory": ["domain", "payment_generators", "prices"]}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}]
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** <module> Application-owned payments over canonical constructor terms.
|
|
2
|
+
|
|
3
|
+
The fee uses Prolog integer arithmetic, independently of the checked model's
|
|
4
|
+
decimal arithmetic. Aligning decimal exponents preserves every input digit.
|
|
5
|
+
*/
|
|
6
|
+
:- module('domain.payments', [apply_fee/2, restore/2, store/2]).
|
|
7
|
+
|
|
8
|
+
apply_fee(value(Tag, [decimal(Sign, Digits, Exponent), Currency]),
|
|
9
|
+
value(Tag, [decimal(ResultSign, ResultDigits, Scale), Currency])) :-
|
|
10
|
+
foldl(decimal_digit, Digits, 0, Magnitude),
|
|
11
|
+
Coefficient is (1 - 2*Sign)*Magnitude,
|
|
12
|
+
Scale is min(Exponent, -1),
|
|
13
|
+
Sum is Coefficient*10**(Exponent-Scale) + 2*10**(-1-Scale),
|
|
14
|
+
( Sum < 0 -> ResultSign=1 ; ResultSign=0 ),
|
|
15
|
+
Absolute is abs(Sum),
|
|
16
|
+
number_codes(Absolute, Codes),
|
|
17
|
+
maplist(digit_code, ResultDigits, Codes).
|
|
18
|
+
|
|
19
|
+
decimal_digit(Digit, Previous, Result) :- Result is Previous*10 + Digit.
|
|
20
|
+
digit_code(Digit, Code) :- Digit is Code - 0'0.
|
|
21
|
+
|
|
22
|
+
restore(Payment, Payment).
|
|
23
|
+
store(Payments, Payments).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** <module> Native strategy factory with Hypothesis's ordinary shrinker.
|
|
2
|
+
|
|
3
|
+
Janus retains child and result strategies as Python objects. The generated
|
|
4
|
+
schema validates every generated native value and every candidate shrink.
|
|
5
|
+
*/
|
|
6
|
+
:- module('domain.payment_generators', [prices/1]).
|
|
7
|
+
:- use_module(library(janus)).
|
|
8
|
+
|
|
9
|
+
prices(Strategy) :-
|
|
10
|
+
py_call('hypothesis.strategies':integers(100, 200), Cents, [py_object(true)]),
|
|
11
|
+
py_call('hypothesis.strategies':just(-2), Exponent, [py_object(true)]),
|
|
12
|
+
py_call(lawspec_runtime:make_decimal, Decimal, [py_object(true)]),
|
|
13
|
+
py_call('hypothesis.strategies':builds(Decimal, Cents, Exponent), Amounts, [py_object(true)]),
|
|
14
|
+
py_call(lawspec_data:'CurrencyEUR'(), Euro, [py_object(true)]),
|
|
15
|
+
py_call('hypothesis.strategies':just(Euro), Currencies, [py_object(true)]),
|
|
16
|
+
py_call(lawspec_data:'Money', Money, [py_object(true)]),
|
|
17
|
+
py_call('hypothesis.strategies':builds(Money, Amounts, Currencies), Strategy, [py_object(true)]).
|
|
@@ -21,64 +21,66 @@ classify :: Int64 -> Band
|
|
|
21
21
|
law "|dollars settle in dollars| is
|
|
22
22
|
definition :
|
|
23
23
|
settlement Usd = domain.Usd
|
|
24
|
-
end
|
|
25
|
-
end
|
|
24
|
+
end definition
|
|
25
|
+
end law
|
|
26
26
|
|
|
27
27
|
law "|pounds settle in euros| is
|
|
28
28
|
definition :
|
|
29
29
|
settlement Gbp = domain.Eur
|
|
30
|
-
end
|
|
31
|
-
end
|
|
30
|
+
end definition
|
|
31
|
+
end law
|
|
32
32
|
|
|
33
33
|
law "|a line total keeps the price currency| is
|
|
34
34
|
definition :
|
|
35
35
|
for all (l :: Line) =>
|
|
36
36
|
domain.currencyOf (lineTotal l) = (first matching case of l :
|
|
37
37
|
when Line record{ price = p , quantity = q} then domain.currencyOf p
|
|
38
|
-
end case) end
|
|
39
|
-
end
|
|
38
|
+
end case) end for all
|
|
39
|
+
end definition
|
|
40
40
|
example "|two items| :
|
|
41
41
|
l = Line record{ price = (Money record{ currency = domain.Usd , cents =
|
|
42
42
|
250}) , quantity = (domain.Quantity 2)}
|
|
43
43
|
expect domain.centsOf (lineTotal l) = 500
|
|
44
|
-
end
|
|
45
|
-
end
|
|
44
|
+
end example
|
|
45
|
+
end law
|
|
46
46
|
|
|
47
47
|
law "|the cheaper price does not depend on order| is
|
|
48
48
|
definition :
|
|
49
49
|
apply law "|commutative| cheaper
|
|
50
|
-
end
|
|
51
|
-
end
|
|
50
|
+
end definition
|
|
51
|
+
end law
|
|
52
52
|
|
|
53
53
|
law "|rounding down to whole dollars is stable| is
|
|
54
54
|
definition :
|
|
55
55
|
apply law "|idempotent| roundDown
|
|
56
|
-
end
|
|
57
|
-
end
|
|
56
|
+
end definition
|
|
57
|
+
end law
|
|
58
58
|
|
|
59
59
|
law "|rounding down never raises a price| is
|
|
60
60
|
definition :
|
|
61
|
-
for all (c :: Cents) => roundDown c <= c end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
61
|
+
for all (c :: Cents) => roundDown c <= c end for all
|
|
62
|
+
end definition
|
|
63
|
+
end law
|
|
64
64
|
|
|
65
65
|
law "|prices are classified into version 2 bands| is
|
|
66
66
|
definition :
|
|
67
|
-
for all (c :: Cents) => tax.rateOf (classify c) <= 25 end
|
|
68
|
-
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
|
|
72
|
-
end
|
|
67
|
+
for all (c :: Cents) => tax.rateOf (classify c) <= 25 end for all
|
|
68
|
+
end definition
|
|
69
|
+
example "|nothing| : c = 0 expect classify c = Zero end example
|
|
70
|
+
example "|small| : c = 9999 expect classify c = Low end example
|
|
71
|
+
example "|large| : c = 10000 expect classify c = High end example
|
|
72
|
+
end law
|
|
73
73
|
|
|
74
74
|
law "|shop.domain keeps version 1 of the bands| is
|
|
75
75
|
definition :
|
|
76
76
|
domain.dutyOf domain.High = 20
|
|
77
|
-
end
|
|
78
|
-
end
|
|
77
|
+
end definition
|
|
78
|
+
end law
|
|
79
79
|
|
|
80
80
|
law "|this project sees version 2 of the bands| is
|
|
81
81
|
definition :
|
|
82
82
|
tax.rateOf High = 25
|
|
83
|
-
end
|
|
84
|
-
end
|
|
83
|
+
end definition
|
|
84
|
+
end law
|
|
85
|
+
|
|
86
|
+
end unit
|
|
@@ -10,11 +10,11 @@ export Band
|
|
|
10
10
|
-- declare a Currency or a Usd of its own.
|
|
11
11
|
type Currency is one of | Usd | Eur end type
|
|
12
12
|
|
|
13
|
-
refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end
|
|
13
|
+
refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end refinement
|
|
14
14
|
|
|
15
15
|
type Money is a record{ currency :: Currency cents :: Cents} end type
|
|
16
16
|
|
|
17
|
-
wrapper Quantity is Int32 where value >= 1 && value <= 1000 end
|
|
17
|
+
wrapper Quantity is Int32 where value >= 1 && value <= 1000 end wrapper
|
|
18
18
|
|
|
19
19
|
function currencyOf (m :: Money) -> Currency is
|
|
20
20
|
first matching case of m : when Money record{ currency = c , cents = n} then c
|
|
@@ -32,15 +32,15 @@ function dutyOf (b :: Band) -> Int64 is tax.rateOf b end function
|
|
|
32
32
|
-- Generic laws are templates: an importer applies them to its own adapters.
|
|
33
33
|
law "|commutative| (f :: a -> a -> a) requires Eq a is
|
|
34
34
|
definition :
|
|
35
|
-
for all (x :: a) (y :: a) => f x y = f y x end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
35
|
+
for all (x :: a) (y :: a) => f x y = f y x end for all
|
|
36
|
+
end definition
|
|
37
|
+
end law
|
|
38
38
|
|
|
39
39
|
law "|idempotent| (f :: a -> a) requires Eq a is
|
|
40
40
|
definition :
|
|
41
|
-
for all (x :: a) => f (f x) = f x end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
41
|
+
for all (x :: a) => f (f x) = f x end for all
|
|
42
|
+
end definition
|
|
43
|
+
end law
|
|
44
44
|
|
|
45
45
|
-- A published contract: every project that depends on this package implements
|
|
46
46
|
-- convert and is tested against these laws.
|
|
@@ -48,12 +48,13 @@ convert :: Currency -> Money -> Money
|
|
|
48
48
|
|
|
49
49
|
law "|conversion targets the requested currency| is
|
|
50
50
|
definition :
|
|
51
|
-
for all (c :: Currency) (m :: Money) => currencyOf (convert c m) = c end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
51
|
+
for all (c :: Currency) (m :: Money) => currencyOf (convert c m) = c end for all
|
|
52
|
+
end definition
|
|
53
|
+
end law
|
|
54
54
|
|
|
55
55
|
law "|converting to the same currency changes nothing| is
|
|
56
56
|
definition :
|
|
57
|
-
for all (m :: Money) => convert (currencyOf m) m = m end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
57
|
+
for all (m :: Money) => convert (currencyOf m) m = m end for all
|
|
58
|
+
end definition
|
|
59
|
+
end law
|
|
60
|
+
end unit
|
|
@@ -39,27 +39,27 @@ law "|ready payments have authorization| is
|
|
|
39
39
|
there must exist an (authorization of type Authorization
|
|
40
40
|
where active Ready the authorization) such that
|
|
41
41
|
authorization `authorizes payment
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
42
|
+
end exists
|
|
43
|
+
end for all
|
|
44
|
+
end definition
|
|
45
45
|
|
|
46
46
|
description:
|
|
47
47
|
"The Ready snapshot contains an active approval for each payment."
|
|
48
|
-
end
|
|
49
|
-
end
|
|
48
|
+
end description
|
|
49
|
+
end law
|
|
50
50
|
|
|
51
51
|
law "|the revoked first approval is absent| is
|
|
52
52
|
definition:
|
|
53
53
|
there does not exist (authorization of type Authorization
|
|
54
54
|
where active FirstRevoked the authorization) such that
|
|
55
55
|
authorization `authorizes FirstPayment
|
|
56
|
-
end
|
|
57
|
-
end
|
|
56
|
+
end exists
|
|
57
|
+
end definition
|
|
58
58
|
|
|
59
59
|
description:
|
|
60
60
|
"The FirstRevoked snapshot has no active approval for the first payment."
|
|
61
|
-
end
|
|
62
|
-
end
|
|
61
|
+
end description
|
|
62
|
+
end law
|
|
63
63
|
|
|
64
64
|
law "|all revoked approvals are absent| is
|
|
65
65
|
definition:
|
|
@@ -67,24 +67,24 @@ law "|all revoked approvals are absent| is
|
|
|
67
67
|
there must not exist (authorization of type Authorization
|
|
68
68
|
where active AllRevoked the authorization) such that
|
|
69
69
|
authorization `authorizes payment
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
70
|
+
end exists
|
|
71
|
+
end for all
|
|
72
|
+
end definition
|
|
73
|
+
end law
|
|
74
74
|
|
|
75
75
|
law "|one approval cannot cover every payment| is
|
|
76
76
|
definition:
|
|
77
77
|
must not there exists (authorization of type Authorization) such that
|
|
78
78
|
for all (payment of type Payment) =>
|
|
79
79
|
authorization `authorizes payment
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
80
|
+
end for all
|
|
81
|
+
end exists
|
|
82
|
+
end definition
|
|
83
83
|
|
|
84
84
|
rationale:
|
|
85
85
|
"Each approval belongs to one payment. Quantifier order changes the claim."
|
|
86
|
-
end
|
|
87
|
-
end
|
|
86
|
+
end rationale
|
|
87
|
+
end law
|
|
88
88
|
|
|
89
89
|
law "|activation matches the complete snapshot| is
|
|
90
90
|
definition:
|
|
@@ -93,8 +93,8 @@ law "|activation matches the complete snapshot| is
|
|
|
93
93
|
active state authorization must be
|
|
94
94
|
(state = Ready or
|
|
95
95
|
(state = FirstRevoked and authorization = SecondApproval))
|
|
96
|
-
end
|
|
97
|
-
end
|
|
96
|
+
end for all
|
|
97
|
+
end definition
|
|
98
98
|
|
|
99
99
|
expect active state authorization = expected
|
|
100
100
|
in table (state, authorization, expected):
|
|
@@ -104,9 +104,10 @@ law "|activation matches the complete snapshot| is
|
|
|
104
104
|
row FirstRevoked, SecondApproval, true
|
|
105
105
|
row AllRevoked, FirstApproval, false
|
|
106
106
|
row AllRevoked, SecondApproval, false
|
|
107
|
-
end
|
|
107
|
+
end table
|
|
108
108
|
|
|
109
109
|
description:
|
|
110
110
|
"The search domain is exactly two approval identities in one snapshot."
|
|
111
|
-
end
|
|
112
|
-
end
|
|
111
|
+
end description
|
|
112
|
+
end law
|
|
113
|
+
end unit
|
|
@@ -17,7 +17,7 @@ end type
|
|
|
17
17
|
|
|
18
18
|
function containsProfanity (input of type Text) -> Bool is
|
|
19
19
|
let folded = prelude.caseFold input in
|
|
20
|
-
prelude.any (prelude.textContains folded) ["shit", "piss", "fuck"]
|
|
20
|
+
prelude.any (prelude.textContains folded) ["shit", "piss", "fuck"] end let
|
|
21
21
|
end function
|
|
22
22
|
|
|
23
23
|
function bannerDecision (picture of type Picture) -> BannerDecision is
|
|
@@ -36,13 +36,13 @@ end function
|
|
|
36
36
|
law "|prohibited filenames are rejected before checking dimensions| is
|
|
37
37
|
description:
|
|
38
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
|
|
39
|
+
end description
|
|
40
40
|
definition:
|
|
41
41
|
for all (picture of type Picture) =>
|
|
42
42
|
containsProfanity picture.fileName implies
|
|
43
43
|
bannerDecision picture must be Rejected picture.fileName
|
|
44
|
-
end
|
|
45
|
-
end
|
|
44
|
+
end for all
|
|
45
|
+
end definition
|
|
46
46
|
expect bannerDecision picture = expected
|
|
47
47
|
in table (picture, expected):
|
|
48
48
|
row Picture record{fileName = "banner.png", dimensions = record{width =
|
|
@@ -59,5 +59,6 @@ law "|prohibited filenames are rejected before checking dimensions| is
|
|
|
59
59
|
height = 1}}, Rejected "ſhit.png"
|
|
60
60
|
row Picture record{fileName = "fucK.png", dimensions = record{width = 1,
|
|
61
61
|
height = 1}}, Rejected "fucK.png"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
62
|
+
end table
|
|
63
|
+
end law
|
|
64
|
+
end unit
|
|
@@ -20,37 +20,38 @@ law "|each bit is recovered| is
|
|
|
20
20
|
definition:
|
|
21
21
|
for all (bit of type Bool) =>
|
|
22
22
|
decodeBit (bitText bit) must be Just bit
|
|
23
|
-
end
|
|
24
|
-
end
|
|
23
|
+
end for all
|
|
24
|
+
end definition
|
|
25
25
|
|
|
26
26
|
description:
|
|
27
27
|
"Each bit has a one-character encoding that decodes to the original bit."
|
|
28
|
-
end
|
|
28
|
+
end description
|
|
29
29
|
|
|
30
30
|
expect bitText bit = encoded
|
|
31
31
|
expect decodeBit encoded = decoded
|
|
32
32
|
in table (bit, encoded, decoded):
|
|
33
33
|
row false, "0", Just false
|
|
34
34
|
row true, "1", Just true
|
|
35
|
-
end
|
|
36
|
-
end
|
|
35
|
+
end table
|
|
36
|
+
end law
|
|
37
37
|
|
|
38
38
|
law "|decoding is a left inverse| is
|
|
39
39
|
definition:
|
|
40
40
|
apply law "|left inverse| "|decode with zero default| bitText
|
|
41
|
-
end
|
|
41
|
+
end definition
|
|
42
42
|
|
|
43
43
|
description:
|
|
44
44
|
"Decoding an encoded bit recovers it. The inverse is the first argument."
|
|
45
|
-
end
|
|
46
|
-
end
|
|
45
|
+
end description
|
|
46
|
+
end law
|
|
47
47
|
|
|
48
48
|
law "|other text has no bit| is
|
|
49
49
|
definition:
|
|
50
50
|
decodeBit "01" must be Nothing
|
|
51
|
-
end
|
|
51
|
+
end definition
|
|
52
52
|
|
|
53
53
|
description:
|
|
54
54
|
"Two characters are not one encoded bit. Invalid input has no decoded value."
|
|
55
|
-
end
|
|
56
|
-
end
|
|
55
|
+
end description
|
|
56
|
+
end law
|
|
57
|
+
end unit
|