Skip to content

Commit e090813

Browse files
committed
add tests and documentation for max_decommission_year
1 parent b4f4a82 commit e090813

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

schemas/input/assets.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ fields:
2222
This value can be any integer >=0. If it is before the start of the simulation, it will
2323
already be commissioned in the first year and if it after the end of the simulation then it
2424
will never be commissioned.
25+
- name: max_decommission_year
26+
type: integer
27+
description: The latest year in which this asset can be decommissioned
28+
notes: |
29+
This value can be any integer that satisfies max_decommission_year >= commission_year >=0.
30+
If it is set before the simulation starting year, the asset will not be commissioned during the
31+
simulation.

src/asset.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ mod tests {
15381538
#[rstest]
15391539
#[case::early_decommission_within_lifetime(2024, 2024)]
15401540
#[case::decommission_at_maximum_year(2026, 2025)]
1541-
fn test_asset_decommission(
1541+
fn test_asset_decommission_with_process_lifetime(
15421542
#[case] requested_decommission_year: u32,
15431543
#[case] expected_decommission_year: u32,
15441544
process: Process,
@@ -1563,6 +1563,35 @@ mod tests {
15631563
assert_eq!(asset.decommission_year(), Some(expected_decommission_year));
15641564
}
15651565

1566+
#[rstest]
1567+
#[case::early_decommission_within_lifetime(2024, 2024)]
1568+
#[case::decommission_at_maximum_year(2026, 2025)]
1569+
fn test_asset_decommission_with_predefined_decommission_year(
1570+
#[case] requested_decommission_year: u32,
1571+
#[case] expected_decommission_year: u32,
1572+
process: Process,
1573+
) {
1574+
// Test successful commissioning of Future asset
1575+
let process_rc = Rc::new(process);
1576+
let mut asset = Asset::new_future_with_max_decommission(
1577+
"agent1".into(),
1578+
Rc::clone(&process_rc),
1579+
"GBR".into(),
1580+
Capacity(1.0),
1581+
2020,
1582+
Some(2025),
1583+
)
1584+
.unwrap();
1585+
asset.commission(AssetID(1), "");
1586+
assert!(asset.is_commissioned());
1587+
assert_eq!(asset.id(), Some(AssetID(1)));
1588+
1589+
// Test successful decommissioning
1590+
asset.decommission(requested_decommission_year, "");
1591+
assert!(!asset.is_commissioned());
1592+
assert_eq!(asset.decommission_year(), Some(expected_decommission_year));
1593+
}
1594+
15661595
#[rstest]
15671596
#[should_panic(expected = "Assets with state Candidate cannot be commissioned")]
15681597
fn test_commission_wrong_states(process: Process) {

src/input/asset.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ mod tests {
140140
region_id: "GBR".into(),
141141
capacity: Capacity(1.0),
142142
commission_year: 2010,
143-
..Default::default()
143+
max_decommission_year: None,
144144
})]
145145
#[case(AssetRaw { // Bad agent ID
146146
agent_id: "agent2".into(),
147147
process_id: "process1".into(),
148148
region_id: "GBR".into(),
149149
capacity: Capacity(1.0),
150150
commission_year: 2010,
151-
..Default::default()
151+
max_decommission_year: None,
152152
})]
153153
#[case(AssetRaw { // Bad region ID: not in region_ids
154154
agent_id: "agent1".into(),
@@ -158,6 +158,14 @@ mod tests {
158158
commission_year: 2010,
159159
max_decommission_year: None,
160160
})]
161+
#[case(AssetRaw { // Bad max_decommission_year: before commission_year
162+
agent_id: "agent1".into(),
163+
process_id: "process1".into(),
164+
region_id: "GBR".into(),
165+
capacity: Capacity(1.0),
166+
commission_year: 2010,
167+
max_decommission_year: Some(2005),
168+
})]
161169
fn test_read_assets_from_iter_invalid(
162170
#[case] asset: AssetRaw,
163171
agent_ids: IndexSet<AgentID>,

0 commit comments

Comments
 (0)