catala/tests/test_array/good/fold.catala_en
2023-06-08 14:03:08 +02:00

62 lines
1.7 KiB
Plaintext

## Article
```catala
declaration structure S:
data id content integer
data income content money
declaration scope A:
context output x content collection S
scope A:
definition x equals [
S { -- id: 0 -- income: $0 };
S { -- id: 1 -- income: $4 + $5 };
S { -- id: 2 -- income: $8 * 0.65 }
]
declaration scope B:
a scope A
output argmax content S
output argmin content S
scope B:
definition argmax equals
(m among a.x such that m.income * 2.0 is maximum
or if collection empty then S { -- id: -1 --income: $0 })
definition argmin equals
(m among a.x such that m.income + $5 is minimum
or if collection empty then S { -- id: -1 --income: $20 })
```
```catala-test-inline
$ catala Interpret -s A
[RESULT] Computation successful! Results:
[RESULT] x =
[ { S id = 0; income = $0.00; };
{ S id = 1; income = $9.00; };
{ S id = 2; income = $5.20; } ]
```
```catala-test-inline
$ catala Interpret -s B
[RESULT] Computation successful! Results:
[RESULT] argmax = { S id = 1; income = $9.00; }
[RESULT] argmin = { S id = 0; income = $0.00; }
```
```catala-test-inline
$ catala Interpret_Lcalc -s A --avoid_exceptions --optimize
[RESULT] Computation successful! Results:
[RESULT] x =
ESome
[ ESome { S id = ESome 0; income = ESome $0.00; };
ESome { S id = ESome 1; income = ESome $9.00; };
ESome { S id = ESome 2; income = ESome $5.20; } ]
```
```catala-test-inline
$ catala Interpret_Lcalc -s B --avoid_exceptions --optimize
[RESULT] Computation successful! Results:
[RESULT] argmax = ESome { S id = ESome 1; income = ESome $9.00; }
[RESULT] argmin = ESome { S id = ESome 0; income = ESome $0.00; }
```