/*
    Appellation: plant <test>
    Contrib: @FL03
*/
extern crate eryon_actors as actors;
extern crate eryon_core as eryon;

use actors::prelude::*;
use eryon::nrt::Triad;
use eryon::rulemap;

#[test]
fn test_wolfram_plant() -> anyhow::Result<()> {
    let max_steps = 100;
    // create a headspace for the plant (a.k.a. triad)
    let headspace = Triad::major(0); // c-major triad
    // create a ruleset for the plant
    let ruleset = rulemap! {
        (0, 0) -> Right(0, 4),
        (0, 4) -> Right(1, 7),
        (0, 7) -> Left(0, 0),
        (1, 0) -> Left(1, 7),
        (1, 4) -> Left(0, 11),
        (1, 7) -> Right(1, 4),
        (0, 11) -> Left(1, 7),
        (1, 11) -> Right(0, 0)
    };

    // Create a simple program using our 4 symbols (0, 4, 7, 11)
    let program = [0, 4, 7, 11, 0, 4, 7, 0, 11, 4, 0, 7];
    // initialize a new instance of WolframPlant
    let mut plant = WolframPlant::from_headspace(headspace);
    // set the ruleset for the plant
    plant.set_ruleset(ruleset.clone());
    // execute the program for a maximum of 100 steps
    let res = plant.run_for(program.to_vec(), max_steps)?;
    assert!(!res.is_empty());
    assert!(res.len() <= max_steps + 1, "res.len() = {}", res.len());
    Ok(())
}
