muse2/example/
patches.rs

1//! File patches to be used in integration tests.
2//!
3//! This is used to test small variations on existing example models.
4use crate::patch::FilePatch;
5use anyhow::{Context, Result};
6use std::{collections::BTreeMap, sync::LazyLock};
7
8/// A map of file patches, keyed by name
9type PatchMap = BTreeMap<&'static str, Vec<FilePatch>>;
10
11/// The file patches, keyed by name
12static PATCHES: LazyLock<PatchMap> = LazyLock::new(get_all_patches);
13
14/// Get all patches
15fn get_all_patches() -> PatchMap {
16    [
17        (
18            // The simple example with gas boiler process made divisible
19            "simple_divisible",
20            vec![
21                FilePatch::new("processes.csv")
22                    .with_deletion("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,")
23                    .with_addition("RGASBR,Gas boiler,all,RSHEAT,2020,2040,1.0,1000"),
24            ],
25        ),
26        // The simple example with objective type set to NPV for one agent
27        (
28            "simple_npv",
29            vec![
30                FilePatch::new("agent_objectives.csv")
31                    .with_deletion("A0_RES,all,lcox,,")
32                    .with_addition("A0_RES,all,npv,,"),
33            ],
34        ),
35    ]
36    .into_iter()
37    .collect()
38}
39
40/// Get the names for all the patches
41pub fn get_patch_names() -> impl Iterator<Item = &'static str> {
42    PATCHES.keys().copied()
43}
44
45/// Get patches for the named patched example
46pub fn get_patches(name: &str) -> Result<&[FilePatch]> {
47    Ok(PATCHES
48        .get(name)
49        .with_context(|| format!("Patched example '{name}' not found"))?)
50}