From d5ff22d026aa00171322dc5ed0abbc05bed3d8a1 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:23:33 +0100 Subject: [PATCH 1/4] Build(Tests) - Cleanup of the test harness --- Cargo.toml | 8 +++++--- Makefile.toml | 2 +- coverage/html/badges/flat.svg | 8 ++++---- coverage/html/badges/flat_square.svg | 6 +++--- coverage/html/badges/for_the_badge.svg | 6 +++--- coverage/html/badges/plastic.svg | 8 ++++---- coverage/html/badges/social.svg | 8 ++++---- pyproject.toml | 5 ++++- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3e6c0e..f0d1f67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ toml = "0.5.9" clap = {version = "4.1.6", features = ["derive"]} threadpool = "1.8.1" # For python bindings TODO: make it optionnal -pyo3 = { version = "0.18.0", features = ["extension-module"] } +pyo3 = { version = "0.18.1", features= ["extension-module"]} # [target.'cfg(not(no_python))'.dependencies] # pyo3 = { version = "0.18.0", features = ["extension-module"] } @@ -36,7 +36,8 @@ opt-level = 3 lto = true [features] -default = [] +extension-module = ["pyo3/extension-module"] +default = ["extension-module"] verbose = [] no_python = [] # Removes the python bindings fast = [] # Remove some under optimisations that try to find other routes @@ -48,4 +49,5 @@ crate-type = ["cdylib","rlib"] [[bin]] name = "xiv_csolver_cli" -path = "src/bin/xiv_csolver.rs" \ No newline at end of file +path = "src/bin/xiv_csolver.rs" + diff --git a/Makefile.toml b/Makefile.toml index cf4c53b..b9d99a1 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -29,7 +29,7 @@ ignore_errors = true script = [ "mkdir -p coverage", "mkdir -p coverage/html", -"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test", +"CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off' LLVM_PROFILE_FILE='llvm/cargo-test-%p-%m.profraw' cargo test", "grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' -o coverage/html/" ] diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index 6febf64..4c9dba0 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%"> + coverage: 56% @@ -16,8 +16,8 @@ coverage - - 48% + + 56% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index 9907885..efc26f9 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 56%"> + coverage: 56% coverage - 48% + 56% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 7d6b58d..0956090 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 56%"> + COVERAGE: 56% COVERAGE - 48% + 56% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 209f476..16fde0e 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 56%"> + coverage: 56% @@ -18,8 +18,8 @@ coverage - - 48% + + 56% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index ccb1035..f5e0951 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 48% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 56%"> + Coverage: 56% @@ -20,8 +20,8 @@ Coverage - - 48% + + 56% \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5c2868e..19a619f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,4 +10,7 @@ classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", -] \ No newline at end of file +] + +[tool.maturin] +features = ["pyo3/extension-module"] \ No newline at end of file -- 2.45.1 From ee24bdd0af3f4f149223345504bb4cf25214e562 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:24:22 +0100 Subject: [PATCH 2/4] Tests(Multiple) - Updates multiple test units --- README.md | 2 +- rustfmt.toml | 1 + src/action.rs | 10 ++++++---- src/bin/xiv_csolver.rs | 2 +- src/craft.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- src/io.rs | 22 +++++++++++++++++++++- src/solver.rs | 4 ++++ 7 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 rustfmt.toml diff --git a/README.md b/README.md index fb2e1c4..0a64ce8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Originaly written by [RikaKagurasaka](https://github.com/RikaKagurasaka/xiv_craf it now is widely improved and provides python bindings for a GUI (or anything else really) -![coverage/html/badges/flat.svg](coverage/html/badges/flat.svg) +![coverage/html/badges/plastic.svg](coverage/html/badges/flat.svg) ### Basic RUST CLI Usage Everything is done through the regular cargo interface diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..4e727a0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +reorder_imports = true \ No newline at end of file diff --git a/src/action.rs b/src/action.rs index 9ff889f..fe4d716 100644 --- a/src/action.rs +++ b/src/action.rs @@ -145,9 +145,10 @@ impl Action { } /// Get the durability cost this action would have if used at this stage of the craft /// This method accounts for the effects of **master mend** and **waste not**. - pub fn get_durability_cost(&self, _craft: &Craft) -> u32 { + /// Note that not using i32 for durability from scratch is a desing choice + pub fn get_durability_cost(&self, _craft: &Craft) -> i32 { if self == &ACTIONS.masters_mend { - return 30; + return -30; } if self.dur == 0 || self.progress == 0 && self.quality == 0 { return 0; @@ -159,7 +160,7 @@ impl Action { if dur < 5 { dur = 5; } - dur + dur as i32 } /// Get the progress effect this action would have if used at this stage of the craft /// This method accounts for the effects of **groundwork** under 20 durability, @@ -419,6 +420,7 @@ impl Default for ActionList { .build(), masters_mend: ActionBuilder::new("Master's Mend").cp(88).build(), + //masters_mend: ActionBuilder::new("Master's Mend").dur(-30).cp(88).build(), waste_not: ActionBuilder::new("Waste Not") .cp(56) .buff(Some((Buff::WasteNot, 4))) @@ -514,7 +516,7 @@ mod test { assert_eq!(&ACTIONS.standard_touch.get_cp_cost(&craft), &18); assert_eq!(&ACTIONS.advanced_touch.get_cp_cost(&craft), &18); - assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &30); + assert_eq!(&ACTIONS.masters_mend.get_durability_cost(&craft), &-30); assert_eq!(&ACTIONS.byregot_blessing.get_quality(&craft), &420); assert_eq!(&ACTIONS.byregot_blessing.can_use(&craft), &true); diff --git a/src/bin/xiv_csolver.rs b/src/bin/xiv_csolver.rs index c94c690..9549faf 100644 --- a/src/bin/xiv_csolver.rs +++ b/src/bin/xiv_csolver.rs @@ -30,7 +30,7 @@ //! //! It is really recommended to set up a venv to handle the python development //! -//! All bindings and the explanation of how to use them can be found in the [`io`](crate::io) module. +//! All bindings and the explanation of how to use them can be found in the [`io`](xiv_csolver_lib::io) module. //! //! ### Features //! diff --git a/src/craft.rs b/src/craft.rs index 2a43a4d..777e696 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -215,10 +215,48 @@ impl<'a> Craft<'a> { #[cfg(test)] mod test { - // use pretty_assertions::assert_eq; + use pretty_assertions::assert_eq; // Struct Test #[test] pub fn struct_tests() { - let _craft = crate::craft::Craft::default(); + let craft = crate::craft::Craft::default().clone(); + assert_eq!(craft.get_base_progression(), 22); + assert_eq!(craft.get_base_quality(), 55); + + format!("{}", craft); + format!("{:?}", craft); + } + + #[test] + pub fn test_craft() { + let mut craft = crate::craft::Craft::default(); + craft.cp = 1000; + format!("{:?}", craft); + let mut craft2 = craft.run_action(&crate::action::ACTIONS.veneration).clone(); + + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.manipulation); + craft.run_action(&crate::action::ACTIONS.basic_touch); + craft.run_action(&crate::action::ACTIONS.basic_synthesis); + assert_eq!(craft.durability, 190); + craft.run_action(&crate::action::ACTIONS.masters_mend); + assert_eq!(craft.durability, 200); + craft.run_action(&crate::action::ACTIONS.masters_mend); + for _ in 0..10 { + craft.run_action(&crate::action::ACTIONS.basic_touch); + } + + for _ in 0..3 { + craft.run_action(&crate::action::ACTIONS.masters_mend); + craft.run_action(&crate::action::ACTIONS.groundwork); + } + assert_eq!(craft.success, crate::craft::Success::Success); + + for _ in 0..20 { + craft2.run_action(&crate::action::ACTIONS.preparatory_touch); + } + assert_eq!(craft2.durability, 0); + assert_eq!(craft2.success, crate::craft::Success::Failure); } } diff --git a/src/io.rs b/src/io.rs index 4c6e038..c9bd331 100644 --- a/src/io.rs +++ b/src/io.rs @@ -235,7 +235,26 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { Ok(()) } -/// +/// A test result, useful for debugging, all values are set to zero as per the +/// [`default`](crate::io::SolverResult::default) +/// ``` +/// # use xiv_csolver_lib::io::SolverResult; +/// SolverResult{ +/// steps: 0, +/// progression: 0, +/// quality: 0, +/// durability: 0, +/// total_progression: 0, +/// total_quality: 0, +/// total_durability: 0, +/// actions: vec!["Act1".to_string(), "Act2".to_string()], +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// cp: 0, +/// total_cp: 0, +/// }; +/// ``` #[cfg(not(feature = "no_python"))] #[pyfunction] pub fn test_result() -> SolverResult { @@ -273,6 +292,7 @@ use crate::{solve_craft, Recipe, Stats}; /// crafting_feeder = FeedingClass() /// rich.inspect(xiv_csolver_lib.solve_from_python(crafting_feeder)) /// ``` + #[cfg(not(feature = "no_python"))] #[pyfunction] pub fn solve_from_python(py: Python<'_>, values: &PyAny) -> PyResult>> { diff --git a/src/solver.rs b/src/solver.rs index 6a2e35f..d16af34 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -61,6 +61,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { // ACTIONS.groundwork for the --pls if craft.args.desperate { available_actions.append(&mut action_vec![ACTIONS.groundwork]); + available_actions.append(&mut action_vec![ACTIONS.masters_mend]); } // For long first run @@ -191,6 +192,9 @@ pub fn next_action_phase_2<'a>(craft: &Craft<'a>) -> Vec> { available_actions.push(&ACTIONS.byregot_blessing); } } + // if craft.durability + 30 < craft.recipe.durability as i32{ + // available_actions.push(&ACTIONS.masters_mend); + // } let mut final_actions: Vec> = Vec::new(); for action in available_actions { -- 2.45.1 From fc5cce934acd196267de3cc16285c34799a79cc6 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 06:48:35 +0100 Subject: [PATCH 3/4] Reformat(All) - Reformats the code --- Makefile.toml | 9 +++++---- rustfmt.toml | 2 +- src/action.rs | 9 ++++----- src/craft.rs | 1 - src/io.rs | 22 +++++++++++----------- src/solver.rs | 4 ++-- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index b9d99a1..92956fa 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -18,10 +18,11 @@ script = [ "twine upload releases/xiv_csolver_lib*.whl --repository gitea", ] -[tasks.format] -install_crate = "rustfmt" -command = "cargo" -args = ["fmt", "--", "--emit=files"] +[tasks.fmt] +script_runner = "@shell" +script = [ +"cargo +nightly fmt -- --config format_code_in_doc_comments=true" +] [tasks.testcov] script_runner = "@shell" diff --git a/rustfmt.toml b/rustfmt.toml index 4e727a0..44148a2 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -reorder_imports = true \ No newline at end of file +reorder_imports = true diff --git a/src/action.rs b/src/action.rs index fe4d716..0ae718d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -2,7 +2,6 @@ //! //! All actions are defined as Action, containing all methods to actively use it in a craft //! while ActionBuilder is used only initally as a lazy_static setup -//! use crate::craft::Craft; use crate::specs::{Buff, Success}; @@ -45,10 +44,10 @@ impl ActionBuilder { /// use xiv_csolver_lib::action::ActionBuilder; /// use xiv_csolver_lib::specs::Buff; /// ActionBuilder::new("Muscle Memory") - /// .cp(6) - /// .progress(300) - /// .buff(Some((Buff::MuscleMemory, 5))) - /// .build(); + /// .cp(6) + /// .progress(300) + /// .buff(Some((Buff::MuscleMemory, 5))) + /// .build(); /// ``` pub fn new(name: &str) -> Self { let mut short_name = name.to_string(); diff --git a/src/craft.rs b/src/craft.rs index 777e696..cbffb01 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -3,7 +3,6 @@ //! A craft represent the state of the recipe with a vector of actions applied to it. //! Applying actions to it will make the craft progress, while branching and trying other actions //! will be done by cloning -//! use crate::action::Action; use crate::specs::{Buff, BuffState, Recipe, Stats, Success}; diff --git a/src/io.rs b/src/io.rs index c9bd331..e4214b7 100644 --- a/src/io.rs +++ b/src/io.rs @@ -239,21 +239,21 @@ fn xiv_csolver_lib(_py: Python, m: &PyModule) -> PyResult<()> { /// [`default`](crate::io::SolverResult::default) /// ``` /// # use xiv_csolver_lib::io::SolverResult; -/// SolverResult{ +/// SolverResult { /// steps: 0, /// progression: 0, /// quality: 0, /// durability: 0, -/// total_progression: 0, -/// total_quality: 0, -/// total_durability: 0, -/// actions: vec!["Act1".to_string(), "Act2".to_string()], -/// step1_solutions: 0, -/// step2_solutions: 0, -/// found_100_percent: false, -/// cp: 0, -/// total_cp: 0, -/// }; +/// total_progression: 0, +/// total_quality: 0, +/// total_durability: 0, +/// actions: vec!["Act1".to_string(), "Act2".to_string()], +/// step1_solutions: 0, +/// step2_solutions: 0, +/// found_100_percent: false, +/// cp: 0, +/// total_cp: 0, +/// }; /// ``` #[cfg(not(feature = "no_python"))] #[pyfunction] diff --git a/src/solver.rs b/src/solver.rs index d16af34..3ed2fe6 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -26,11 +26,11 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { // Prune some actions if not requested by --long if craft.step_count == 2 { - return action_vec![/*ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration]; + return action_vec![/* ACTIONS.waste_not, ACTIONS.waste_not_ii, */ ACTIONS.veneration]; } if craft.step_count == 3 { available_actions.append(&mut action_vec![ - ACTIONS.waste_not_ii /*,ACTIONS.waste_not*/ + ACTIONS.waste_not_ii /* ,ACTIONS.waste_not */ ]) } -- 2.45.1 From 539a14a4fc795f90e3f7e93217b86872d4bf238c Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 7 Mar 2023 07:58:12 +0100 Subject: [PATCH 4/4] Coverage(Solver) - Puts solver at 76% coverage --- Makefile.toml | 2 +- coverage/html/badges/flat.svg | 8 +- coverage/html/badges/flat_square.svg | 6 +- coverage/html/badges/for_the_badge.svg | 6 +- coverage/html/badges/plastic.svg | 8 +- coverage/html/badges/social.svg | 8 +- src/craft.rs | 27 +++ src/lib.rs | 9 +- src/solver.rs | 255 ++++++++++++++++++++++++- 9 files changed, 302 insertions(+), 27 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 92956fa..72dcc22 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -21,7 +21,7 @@ script = [ [tasks.fmt] script_runner = "@shell" script = [ -"cargo +nightly fmt -- --config format_code_in_doc_comments=true" +"cargo +nightly fmt -- --config format_code_in_doc_comments=true --config imports_granularity=Module" ] [tasks.testcov] diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg index 4c9dba0..cbcfb5c 100644 --- a/coverage/html/badges/flat.svg +++ b/coverage/html/badges/flat.svg @@ -1,6 +1,6 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%"> + coverage: 69% @@ -16,8 +16,8 @@ coverage - - 56% + + 69% \ No newline at end of file diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg index efc26f9..36d4829 100644 --- a/coverage/html/badges/flat_square.svg +++ b/coverage/html/badges/flat_square.svg @@ -1,13 +1,13 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 69%"> + coverage: 69% coverage - 56% + 69% \ No newline at end of file diff --git a/coverage/html/badges/for_the_badge.svg b/coverage/html/badges/for_the_badge.svg index 0956090..0cfc978 100644 --- a/coverage/html/badges/for_the_badge.svg +++ b/coverage/html/badges/for_the_badge.svg @@ -1,13 +1,13 @@ - COVERAGE: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 69%"> + COVERAGE: 69% COVERAGE - 56% + 69% \ No newline at end of file diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg index 16fde0e..68d3549 100644 --- a/coverage/html/badges/plastic.svg +++ b/coverage/html/badges/plastic.svg @@ -1,6 +1,6 @@ - coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 69%"> + coverage: 69% @@ -18,8 +18,8 @@ coverage - - 56% + + 69% \ No newline at end of file diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg index f5e0951..45c8c46 100644 --- a/coverage/html/badges/social.svg +++ b/coverage/html/badges/social.svg @@ -1,6 +1,6 @@ - Coverage: 56% + xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 69%"> + Coverage: 69% @@ -20,8 +20,8 @@ Coverage - - 56% + + 69% \ No newline at end of file diff --git a/src/craft.rs b/src/craft.rs index cbffb01..9f4cd95 100644 --- a/src/craft.rs +++ b/src/craft.rs @@ -210,6 +210,33 @@ impl<'a> Craft<'a> { }, ) } + + /// Create a "Three start" craft, testing only + pub fn three_star() -> Craft<'a> { + Self::new( + crate::specs::Recipe { + durability: 70, + progress: 3900, + quality: 10920, + progress_divider: 130, + quality_divider: 115, + progress_modifier: 80, + quality_modifier: 70, + }, + crate::specs::Stats { + craftsmanship: 4041, + control: 3971, + max_cp: 595, + }, + crate::io::Parameters { + threads: 8, + verbose: 2, + depth: 8, + desperate: false, + byregot_step: 10, + }, + ) + } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 96c4de4..b83a71f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,12 +96,9 @@ #![warn(missing_docs)] -use crate::io::SolverResult; -use crate::{ - craft::Craft, - io::Parameters, - specs::{Recipe, Stats}, -}; +use crate::craft::Craft; +use crate::io::{Parameters, SolverResult}; +use crate::specs::{Recipe, Stats}; use std::sync::{Arc, Mutex}; use threadpool::ThreadPool; diff --git a/src/solver.rs b/src/solver.rs index 3ed2fe6..bbce062 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -16,7 +16,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { let mut available_actions = Vec::>::new(); let mut forbidden_actions = Vec::>::new(); - // Optimize the first three steps for massive time save + // Optimize the first four steps for massive time save if craft.step_count == 0 { return action_vec![ACTIONS.muscle_memory]; } @@ -65,7 +65,7 @@ pub fn next_action_picker_1<'a>(craft: &Craft<'a>) -> Vec> { } // For long first run - if craft.step_count > 8 { + if craft.step_count > 8 && craft.buffs.waste_not == 0 { available_actions.append(&mut action_vec![ACTIONS.waste_not_ii, ACTIONS.waste_not]) }; @@ -246,3 +246,254 @@ pub fn generate_routes_phase2<'a>(craft: Craft<'a>) -> Option>> { top_routes.push(top_route); Some(top_routes) } + +#[cfg(test)] +mod test { + use crate::solver::{generate_routes_phase1, next_action_picker_1, ACTIONS}; + + #[test] + pub fn test_first_step() { + let mut craft = crate::craft::Craft::three_star(); + // Try a failed craft + craft.success = crate::specs::Success::Failure; + let vact = next_action_picker_1(&craft); + assert_eq!(vact, vec![None]); + craft.success = crate::specs::Success::Pending; + + // Try the first 4 steps + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.muscle_memory]); + craft.run_action(&ACTIONS.muscle_memory); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.manipulation]); + craft.run_action(&ACTIONS.manipulation); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.veneration]); + craft.run_action(&ACTIONS.veneration); + + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.waste_not_ii, ACTIONS.groundwork]); + craft.run_action(&ACTIONS.waste_not_ii); + + // Try the steps 5-8, deterministically + let vact = next_action_picker_1(&craft); + assert_eq!(vact, action_vec![ACTIONS.groundwork]); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.groundwork, + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.careful_synthesis); + + // Check odd parameters + craft.buffs.waste_not = 0; + craft.progression = 0; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis + ] + ); + craft.run_action(&ACTIONS.delicate_synthesis); + + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + + craft.args.desperate = true; + let vact = next_action_picker_1(&craft); + assert_eq!( + vact, + action_vec![ + ACTIONS.basic_synthesis, + ACTIONS.careful_synthesis, + ACTIONS.prudent_synthesis, + ACTIONS.delicate_synthesis, + ACTIONS.groundwork, + ACTIONS.masters_mend, + ACTIONS.waste_not_ii, + ACTIONS.waste_not + ] + ); + } + + #[test] + pub fn test_routes_p1() { + let craft = crate::craft::Craft::three_star(); + let mut routes1 = generate_routes_phase1(craft); + + for route in routes1.iter() { + println!("{:?}", route.actions); + } + // Literrally any change will break it + // An eq should be implmented to just check a vector of vector versus a route + assert_eq!(routes1.len(), 9); + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis, + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.waste_not_ii, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.delicate_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.delicate_synthesis, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.prudent_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.careful_synthesis + ] + ); + + let route = routes1.pop().unwrap(); + assert_eq!( + route.actions, + vec![ + &ACTIONS.muscle_memory, + &ACTIONS.manipulation, + &ACTIONS.veneration, + &ACTIONS.groundwork, + &ACTIONS.basic_synthesis + ] + ); + + let route = routes1.pop(); + match route { + None => (), + Some(..) => panic!(), + } + } +} -- 2.45.1