diff --git a/Makefile.toml b/Makefile.toml
index 72dcc22..0c25cfa 100644
--- a/Makefile.toml
+++ b/Makefile.toml
@@ -30,8 +30,9 @@ ignore_errors = true
script = [
"mkdir -p coverage",
"mkdir -p coverage/html",
+"mkdir -p coverage/",
"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/"
+"grcov . --binary-path ./target/debug/deps/ -s . -t html --branch --ignore-not-existing --ignore '../*' --ignore '/*' --ignore '*xiv_csolver.rs' --ignore '*python*.rs' -o coverage/html/",
]
[tasks.clean]
diff --git a/coverage/html/badges/flat.svg b/coverage/html/badges/flat.svg
index b482db6..b7c0854 100644
--- a/coverage/html/badges/flat.svg
+++ b/coverage/html/badges/flat.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/coverage/html/badges/flat_square.svg b/coverage/html/badges/flat_square.svg
index cc89b0d..a18f634 100644
--- a/coverage/html/badges/flat_square.svg
+++ b/coverage/html/badges/flat_square.svg
@@ -1,13 +1,13 @@
\ 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 427f757..12a1eb8 100644
--- a/coverage/html/badges/for_the_badge.svg
+++ b/coverage/html/badges/for_the_badge.svg
@@ -1,13 +1,13 @@
\ No newline at end of file
diff --git a/coverage/html/badges/plastic.svg b/coverage/html/badges/plastic.svg
index 5900c59..2245a14 100644
--- a/coverage/html/badges/plastic.svg
+++ b/coverage/html/badges/plastic.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/coverage/html/badges/social.svg b/coverage/html/badges/social.svg
index 8aeabdb..f26a8cf 100644
--- a/coverage/html/badges/social.svg
+++ b/coverage/html/badges/social.svg
@@ -1,6 +1,6 @@
\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index b83a71f..ec165d2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -148,7 +148,7 @@ pub fn solve_craft<'a>(
}
}
- // Core algorithm, fill all found routes with the best route (doesn't branch, just replace)
+ // Core algorithm, fill all found routes with the best route
let arc_phase2_routes = Arc::new(Mutex::new(Vec::::new()));
for route in phase1_routes {
@@ -371,3 +371,183 @@ pub fn find_safe_route(routes: &Option>) -> Option<&SolverResu
None => None,
}
}
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ pub fn test_lib_find_route() {
+ // Supposed to find a route for the base craft
+ let mut craft = crate::craft::Craft::two_star();
+ let res = solve_craft(craft.recipe, craft.stats, craft.args);
+ assert!(res.unwrap().len() > 2000);
+
+ craft.recipe.progress = 0;
+ let res = solve_craft(craft.recipe, craft.stats, craft.args);
+ println!("{:?}", res);
+ assert!(res.is_none());
+
+ craft.recipe.progress = 100;
+ craft.stats.max_cp = 0;
+ craft.cp = 0;
+
+ let mut res = solve_craft(craft.recipe, craft.stats, craft.args).unwrap();
+ println!("{:?}", res);
+ assert_eq!(res.len(), 1);
+ assert_eq!(res.pop().unwrap().actions, vec!("basicSynth2"));
+ }
+
+ #[test]
+ pub fn test_lib_print_route() {
+ let craft = crate::craft::Craft::two_star();
+ print_routes(&solve_craft(craft.recipe, craft.stats, craft.args));
+ print_routes(&None);
+ }
+
+ #[test]
+ pub fn test_lib_best_solutions() {
+ let craft = crate::craft::Craft::two_star();
+ let res = solve_craft(craft.recipe, craft.stats, craft.args);
+
+ assert!(find_fast_route(&None).is_none());
+ assert!(find_quality_route(&None).is_none());
+ assert!(find_safe_route(&None).is_none());
+
+ assert!(find_fast_route(&Some(vec![])).is_none());
+ assert!(find_quality_route(&Some(vec![])).is_none());
+ assert!(find_safe_route(&&Some(vec![])).is_none());
+
+ let sol = find_fast_route(&res).unwrap();
+ assert_eq!(sol.steps, 17);
+ assert_eq!(sol.quality, 11129);
+ assert_eq!(sol.progression, 3750);
+ assert_eq!(sol.durability, 0);
+ assert_eq!(sol.cp, 7);
+ assert_eq!(sol.step1_solutions, 9);
+ assert_eq!(sol.step2_solutions, 21193);
+ assert_eq!(sol.found_100_percent, true);
+ assert_eq!(
+ sol.actions,
+ vec!(
+ "muscleMemory",
+ "manipulation",
+ "veneration",
+ "wasteNot2",
+ "groundwork",
+ "delicateSynthesis",
+ "delicateSynthesis",
+ "innovation",
+ "preparatoryTouch",
+ "preparatoryTouch",
+ "preparatoryTouch",
+ "preparatoryTouch",
+ "innovation",
+ "basicTouch",
+ "standardTouch",
+ "greatStrides",
+ "byregotsBlessing",
+ "basicSynth2"
+ )
+ );
+
+ let sol = find_quality_route(&res).unwrap();
+ assert_eq!(sol.steps, 23);
+ assert_eq!(sol.quality, 12032);
+ assert_eq!(sol.progression, 3675);
+ assert_eq!(sol.durability, -5);
+ assert_eq!(sol.cp, 3);
+ assert_eq!(sol.step1_solutions, 9);
+ assert_eq!(sol.step2_solutions, 21193);
+ assert_eq!(sol.found_100_percent, true);
+ assert_eq!(
+ sol.actions,
+ vec!(
+ "muscleMemory",
+ "manipulation",
+ "veneration",
+ "groundwork",
+ "prudentSynthesis",
+ "innovation",
+ "prudentTouch",
+ "basicTouch",
+ "standardTouch",
+ "advancedTouch",
+ "manipulation",
+ "innovation",
+ "prudentTouch",
+ "basicTouch",
+ "standardTouch",
+ "advancedTouch",
+ "innovation",
+ "basicTouch",
+ "standardTouch",
+ "advancedTouch",
+ "greatStrides",
+ "innovation",
+ "byregotsBlessing",
+ "basicSynth2"
+ )
+ );
+
+ let sol = find_safe_route(&res).unwrap();
+ assert_eq!(sol.steps, 22);
+ assert_eq!(sol.quality, 11161);
+ assert_eq!(sol.progression, 3675);
+ assert_eq!(sol.durability, 10);
+ assert_eq!(sol.cp, 4);
+ assert_eq!(sol.step1_solutions, 9);
+ assert_eq!(sol.step2_solutions, 21193);
+ assert_eq!(sol.found_100_percent, true);
+ assert_eq!(
+ sol.actions,
+ vec!(
+ "muscleMemory",
+ "manipulation",
+ "veneration",
+ "groundwork",
+ "carefulSynthesis",
+ "prudentTouch",
+ "innovation",
+ "prudentTouch",
+ "prudentTouch",
+ "prudentTouch",
+ "prudentTouch",
+ "manipulation",
+ "innovation",
+ "prudentTouch",
+ "basicTouch",
+ "standardTouch",
+ "advancedTouch",
+ "innovation",
+ "basicTouch",
+ "standardTouch",
+ "greatStrides",
+ "byregotsBlessing",
+ "basicSynth2"
+ )
+ );
+ }
+
+ #[test]
+ pub fn test_load_from_config() {
+ load_from_config("default_recipe", "craft.toml", "default_character");
+ }
+
+ #[should_panic]
+ #[test]
+ pub fn test_bad_config_filename() {
+ load_from_config("default_recipe", "nocrafto.toml", "default_character");
+ }
+
+ #[should_panic]
+ #[test]
+ pub fn test_bad_config_recipename() {
+ load_from_config("bad_recipe", "craft.toml", "default_character");
+ }
+ #[should_panic]
+ #[test]
+ pub fn test_bad_config_charname() {
+ load_from_config("default_recipe", "craft.toml", "bad_character");
+ }
+}