-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kleis-technology/e2e
e2e
- Loading branch information
Showing
12 changed files
with
353 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
process bake { | ||
products { | ||
1 kg bread | ||
} | ||
inputs { | ||
1 kg flour | ||
} | ||
} | ||
|
||
process mill { | ||
products { | ||
1 kg flour | ||
} | ||
inputs { | ||
2 kg wheat | ||
} | ||
} | ||
|
||
test bake { | ||
given { | ||
1 kg bread | ||
} | ||
assert { | ||
wheat between 2 kg and 2 kg | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
process bake { | ||
products { | ||
1 kg bread | ||
} | ||
inputs { | ||
1 kg flour | ||
} | ||
emissions { | ||
1 m3 wood_smoke (compartment="air") | ||
} | ||
} | ||
|
||
process mill { | ||
products { | ||
1 kg flour | ||
} | ||
inputs { | ||
2 kg wheat | ||
} | ||
} | ||
|
||
test bake { | ||
given { | ||
1 kg bread | ||
} | ||
assert { | ||
wheat between 2 kg and 2 kg | ||
wood_smoke between 1 m3 and 1 m3 // TODO: Reference should include compartment | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
process bake { | ||
products { | ||
1 kg bread | ||
} | ||
inputs { | ||
1 kg flour | ||
} | ||
emissions { | ||
1 m3 wood_smoke (compartment="air") | ||
} | ||
} | ||
|
||
substance wood_smoke { | ||
name = "Wood fire Smoke" | ||
type = Emission | ||
compartment = "air" | ||
// optional: sub_compartment = "low altitude" | ||
reference_unit = m3 | ||
impacts { | ||
1 kg_CO2_Eq climate_change | ||
} | ||
} | ||
|
||
process mill { | ||
products { | ||
1 kg flour | ||
} | ||
inputs { | ||
2 kg wheat | ||
} | ||
} | ||
|
||
test bake { | ||
given { | ||
1 kg bread | ||
} | ||
assert { | ||
climate_change between 1 kg_CO2_Eq and 1 kg_CO2_Eq | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
process bake { | ||
params { | ||
salt_amount = 30 g | ||
} | ||
products { | ||
1 kg bread | ||
} | ||
inputs { | ||
1 kg flour | ||
salt_amount salt | ||
} | ||
} | ||
|
||
test bake { | ||
given { | ||
1 kg bread from bake(salt_amount = 10 g) | ||
} | ||
assert { | ||
salt between 10 g and 10 g | ||
} | ||
} | ||
|
||
|
||
process produce_sandwich { | ||
products { | ||
5 p sandwich | ||
} | ||
inputs { | ||
1 kg bread from bake (salt_amount = 20 g) | ||
} | ||
} | ||
|
||
test sandwich { | ||
given { | ||
1 p sandwich from produce_sandwich // TODO: separate tests and process references | ||
} | ||
assert { | ||
flour between 0.2 kg and 0.2 kg | ||
salt between 4 g and 4 g | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
process consumption { | ||
params { | ||
budget = 200 u | ||
} | ||
products { | ||
1 u consumer | ||
} | ||
variables { | ||
a_choco = 2 u | ||
p_choco = 4 u | ||
a_candy = 1 u | ||
p_candy = 2 u | ||
q_choco = budget * a_choco / p_choco | ||
q_candy = budget * a_candy / p_candy | ||
} | ||
inputs { | ||
q_choco chocolate_bar | ||
q_candy candy | ||
} | ||
} | ||
|
||
test consumption { | ||
given { | ||
1 u consumer | ||
} | ||
assert { | ||
chocolate_bar between 100 u and 100 u | ||
candy between 100 u and 100 u | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
unit oil_barrel { | ||
symbol = "oil_barrel" | ||
alias_for = 1700 kWh | ||
} | ||
|
||
process oil_burning { | ||
products { | ||
1700 kWh electricity | ||
} | ||
impacts { | ||
1 p physical_oil_barrel | ||
} | ||
} | ||
|
||
test unit_conversion { | ||
given { | ||
1 oil_barrel electricity from oil_burning | ||
} | ||
assert { | ||
physical_oil_barrel between 1 p and 1 p | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
unit night { | ||
symbol = "night" | ||
dimension = "night" | ||
} | ||
|
||
unit guest { | ||
symbol = "guest" | ||
dimension = "guest" | ||
} | ||
|
||
unit dollar { | ||
symbol = "dollar" | ||
dimension = "dollar" | ||
} | ||
|
||
|
||
process hotel { | ||
products { | ||
1 night night | ||
} | ||
impacts { | ||
1 piece night_stay | ||
} | ||
} | ||
|
||
process customer { | ||
variables { | ||
budget = 200 dollar | ||
price_per_guest_night = 100 dollar / (guest * night) | ||
nb_guests = 2 guest | ||
|
||
/* | ||
The following formula has the wrong dimension. | ||
Assessing the process should yield a dimension error. | ||
The correct formula is | ||
nb_nights = budget / (price_per_guest_night * nb_guests) | ||
*/ | ||
nb_nights = budget / price_per_guest_night * nb_guests | ||
} | ||
|
||
products { | ||
1 piece customer | ||
} | ||
|
||
inputs { | ||
nb_nights night from hotel | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
process electric_vehicle { | ||
params { | ||
geo = "switzerland" // or "france" | ||
} | ||
products { | ||
1 person * km transport | ||
} | ||
inputs { | ||
1 kWh electricity from electricity_production match (geo = geo) | ||
} | ||
} | ||
|
||
process electricity_production { | ||
labels { | ||
geo = "switzerland" | ||
} | ||
products { | ||
1 kWh electricity | ||
} | ||
impacts { | ||
1 kg_CO2_Eq GWP | ||
} | ||
} | ||
|
||
process electricity_production { | ||
labels { | ||
geo = "france" | ||
} | ||
products { | ||
1 kWh electricity | ||
} | ||
impacts { | ||
2 kg_CO2_Eq GWP | ||
} | ||
} | ||
|
||
test electric_vehicle_ch { | ||
given { | ||
1 person * km transport from electric_vehicle(geo = "switzerland") | ||
} | ||
assert { | ||
GWP between 1 kg_CO2_Eq and 1 kg_CO2_Eq | ||
} | ||
} | ||
|
||
test electric_vehicle_fr { | ||
given { | ||
1 person * km transport from electric_vehicle(geo = "france") | ||
} | ||
assert { | ||
GWP between 2 kg_CO2_Eq and 2 kg_CO2_Eq | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Tutorials | ||
|
||
This folder contains multiple code samples covering the main LCAAC language features. | ||
Each code sample takes the form a `.lca` file. | ||
Use the [cli](../cli/README.md) to interact with the code. | ||
Moreover, each code sample contains tests. You can run the tests manually, e.g., | ||
```bash | ||
lcaac test -p 01-basics/01-getting-started | ||
``` | ||
|
||
The script `run.sh` runs all the tests. | ||
```bash | ||
./run.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo | ||
|
||
export GIT_ROOT=$(git rev-parse --show-toplevel) | ||
|
||
LCAAC_PATH=$GIT_ROOT/cli/build/install/lcaac/bin | ||
TUTORIALS_PATH=$GIT_ROOT/tutorials | ||
|
||
function setup() { | ||
$GIT_ROOT/gradlew :cli:installDist | ||
} | ||
|
||
function lcaac() { | ||
$LCAAC_PATH/lcaac $@ | ||
} | ||
|
||
if ! [ -f $LCAAC_PATH/lcaac ]; then | ||
setup | ||
fi | ||
|
||
# Check all lca tests | ||
lcaac test -p $TUTORIALS_PATH/01-basics/01-getting-started | ||
lcaac test -p $TUTORIALS_PATH/01-basics/02-biosphere | ||
lcaac test -p $TUTORIALS_PATH/01-basics/03-impacts | ||
lcaac test -p $TUTORIALS_PATH/02-advanced/01-parametrized-process | ||
lcaac test -p $TUTORIALS_PATH/02-advanced/02-variables | ||
lcaac test -p $TUTORIALS_PATH/02-advanced/03-units | ||
lcaac test -p $TUTORIALS_PATH/02-advanced/04-labels | ||
|
||
# Check custom dimensions tutorial | ||
set -euo | ||
|
||
# The following assessment is expected to fail. | ||
if lcaac assess -p $TUTORIALS_PATH/02-advanced/03-units customer; then | ||
exit 0 | ||
fi |