Test(Coverage) - Adds the coverage of lib.rs and purges useless data from the report (python and main)

This commit is contained in:
Dandaedre 2023-03-09 01:32:12 +01:00
parent 406bc0e515
commit b0cf27f624
7 changed files with 205 additions and 24 deletions

View File

@ -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]

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 77%">
<title>coverage: 77%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 96%">
<title>coverage: 96%</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
@ -10,14 +10,14 @@
</clipPath>
<g clip-path="url(#r)">
<rect width="61" height="20" fill="#555"/>
<rect x="61" width="35" height="20" fill="#dfb317"/>
<rect x="61" width="35" height="20" fill="#97ca00"/>
<rect width="96" height="20" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="315" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">77%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">77%</text>
<text aria-hidden="true" x="775" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">96%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">96%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,13 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 77%">
<title>coverage: 77%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="coverage: 96%">
<title>coverage: 96%</title>
<g shape-rendering="crispEdges">
<rect width="61" height="20" fill="#555"/>
<rect x="61" width="35" height="20" fill="#dfb317"/>
<rect x="61" width="35" height="20" fill="#97ca00"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text x="315" y="140" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">77%</text>
<text x="775" y="140" transform="scale(.1)" fill="#fff" textLength="250">96%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 712 B

View File

@ -1,13 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 77%">
<title>COVERAGE: 77%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="142.5" height="28" role="img" aria-label="COVERAGE: 96%">
<title>COVERAGE: 96%</title>
<g shape-rendering="crispEdges">
<rect width="91" height="28" fill="#555"/>
<rect x="91" width="51.5" height="28" fill="#dfb317"/>
<rect x="91" width="51.5" height="28" fill="#97ca00"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="100">
<text fill="#fff" x="455" y="175" transform="scale(.1)" textLength="670">COVERAGE</text>
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">77%</text>
<text fill="#fff" x="1167.5" y="175" font-weight="bold" transform="scale(.1)" textLength="275">96%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 739 B

After

Width:  |  Height:  |  Size: 739 B

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 77%">
<title>coverage: 77%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="coverage: 96%">
<title>coverage: 96%</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
@ -12,14 +12,14 @@
</clipPath>
<g clip-path="url(#r)">
<rect width="61" height="18" fill="#555"/>
<rect x="61" width="35" height="18" fill="#dfb317"/>
<rect x="61" width="35" height="18" fill="#97ca00"/>
<rect width="96" height="18" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="315" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">coverage</text>
<text x="315" y="130" transform="scale(.1)" fill="#fff" textLength="510">coverage</text>
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">77%</text>
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">77%</text>
<text aria-hidden="true" x="775" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">96%</text>
<text x="775" y="130" transform="scale(.1)" fill="#fff" textLength="250">96%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,6 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 77%">
<title>Coverage: 77%</title>
xmlns:xlink="http://www.w3.org/1999/xlink" width="99" height="20" role="img" aria-label="Coverage: 96%">
<title>Coverage: 96%</title>
<style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style>
<linearGradient id="a" x2="0" y2="100%">
<stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/>
@ -20,8 +20,8 @@
<rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="61" height="19" rx="2"/>
<text aria-hidden="true" x="305" y="150" fill="#fff" transform="scale(.1)" textLength="510">Coverage</text>
<text x="305" y="140" transform="scale(.1)" textLength="510">Coverage</text>
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">77%</text>
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">77%</text>
<text aria-hidden="true" x="825" y="150" fill="#fff" transform="scale(.1)" textLength="230">96%</text>
<text id="rlink" x="825" y="140" transform="scale(.1)" textLength="230">96%</text>
</g>
<script xmlns=""/>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -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::<Craft>::new()));
for route in phase1_routes {
@ -371,3 +371,183 @@ pub fn find_safe_route(routes: &Option<Vec<SolverResult>>) -> 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");
}
}