parent
33914eaba3
commit
55552f7349
@ -0,0 +1,11 @@ |
|||||||
|
@echo off |
||||||
|
set RUSTFLAGS=-Zinstrument-coverage |
||||||
|
set LLVM_PROFILE_FILE=tests-%m.profraw |
||||||
|
cargo clean |
||||||
|
cargo test --tests |
||||||
|
cargo profdata -- merge -sparse tests-*.profraw -o tests.profdata |
||||||
|
cargo cov -- report --use-color --ignore-filename-regex="(registry|toolchains)" --instr-profile=tests.profdata target\debug\deps\trustpilot_challenge_rust.exe target\debug\deps\trustpilot_challenge_rust-16a5f5b3dcaa6625.exe target\debug\deps\trustpilot_challenge_rust-ad09af9137a4ac83.exe target\debug\deps\hash_computer_test-e97eaa049af7d579.exe target\debug\deps\solver_tests-5c0a8c7757425eff.exe | more |
||||||
|
cargo cov -- show --use-color --ignore-filename-regex="(registry|toolchains)" --instr-profile=tests.profdata target\debug\deps\trustpilot_challenge_rust.exe target\debug\deps\trustpilot_challenge_rust-16a5f5b3dcaa6625.exe target\debug\deps\trustpilot_challenge_rust-ad09af9137a4ac83.exe target\debug\deps\hash_computer_test-e97eaa049af7d579.exe target\debug\deps\solver_tests-5c0a8c7757425eff.exe --show-instantiations --show-line-counts-or-regions --Xdemangler=rustfilt | more |
||||||
|
cargo clean |
||||||
|
del *.profraw |
||||||
|
del *.profdata |
@ -1,2 +1,48 @@ |
|||||||
|
use rayon::iter::ParallelIterator; |
||||||
|
|
||||||
extern crate trustpilot_challenge_rust; |
extern crate trustpilot_challenge_rust; |
||||||
use trustpilot_challenge_rust::hash_computer; |
use trustpilot_challenge_rust::solver::Solver; |
||||||
|
/* |
||||||
|
const WORDS: Vec<String> = vec!["a", "b", "aa", "bb", "ab", "ba", "aaa", "bbb", "abc", "c", "ccc", "d", "dddd"]; |
||||||
|
const HASHES: [String; _] = [ |
||||||
|
"b2ef629aeb4deac769c3b476387c7e9f", // a b c ab c dddd
|
||||||
|
"17fd9c64127f42baeff12fba8038a7f0", // ab c dddd abc
|
||||||
|
"73b50bfa6b3b941a53f7e3ac0d99c8a5", // c ba ba c dddd
|
||||||
|
"c475a98ce0cdfcf5640f981b98d427c3", // c c ab ba dddd
|
||||||
|
"96f824d59eea869e02f0dbfa23f5676d", // dddd abc abc
|
||||||
|
]; |
||||||
|
*/ |
||||||
|
|
||||||
|
fn check_solutions(max_number_of_words: usize, expected: &[&str]) -> () { |
||||||
|
let solver = Solver::create_from_input_data( |
||||||
|
["a", "b", "aa", "bb", "ab", "ba", "aaa", "bbb", "abc", "c", "ccc", "d", "dddd"].iter() |
||||||
|
.map(|&s| s.to_owned()).collect(), |
||||||
|
[ |
||||||
|
"b2ef629aeb4deac769c3b476387c7e9f", // a b c ab c dddd
|
||||||
|
"17fd9c64127f42baeff12fba8038a7f0", // ab c dddd abc
|
||||||
|
"73b50bfa6b3b941a53f7e3ac0d99c8a5", // c ba ba c dddd
|
||||||
|
"c475a98ce0cdfcf5640f981b98d427c3", // c c ab ba dddd
|
||||||
|
"96f824d59eea869e02f0dbfa23f5676d", // dddd abc abc
|
||||||
|
].iter().map(|&s| s.to_owned()).collect(), |
||||||
|
max_number_of_words, |
||||||
|
"abcdd cbadd" |
||||||
|
); |
||||||
|
let mut result: Vec<_> = solver.find_solutions() |
||||||
|
.map(|solution| solution.anagram_string) |
||||||
|
.collect(); |
||||||
|
|
||||||
|
result.sort(); |
||||||
|
result.dedup(); |
||||||
|
|
||||||
|
assert_eq!(result, expected); |
||||||
|
} |
||||||
|
|
||||||
|
#[test] |
||||||
|
fn it_solves() { |
||||||
|
check_solutions(1, &[]); |
||||||
|
check_solutions(2, &[]); |
||||||
|
check_solutions(3, &["dddd abc abc"]); |
||||||
|
check_solutions(4, &["ab c dddd abc", "dddd abc abc"]); |
||||||
|
check_solutions(5, &["ab c dddd abc", "c ba ba c dddd", "c c ab ba dddd", "dddd abc abc"]); |
||||||
|
check_solutions(6, &["a b c ab c dddd", "ab c dddd abc", "c ba ba c dddd", "c c ab ba dddd", "dddd abc abc"]); |
||||||
|
} |
||||||
|
Loading…
Reference in new issue