Refactor to make test segmenter more accessible
This commit is contained in:
parent
f329176ed9
commit
14b00e6417
|
@ -2,12 +2,15 @@
|
||||||
|
|
||||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||||
|
|
||||||
|
use instant_segment::test_data::{crate_data_dir, segmenter};
|
||||||
|
use instant_segment::Search;
|
||||||
|
|
||||||
benchmark_group!(benches, short);
|
benchmark_group!(benches, short);
|
||||||
benchmark_main!(benches);
|
benchmark_main!(benches);
|
||||||
|
|
||||||
fn short(bench: &mut Bencher) {
|
fn short(bench: &mut Bencher) {
|
||||||
let segmenter = instant_segment::test_data::segmenter();
|
let segmenter = segmenter(crate_data_dir());
|
||||||
let mut search = instant_segment::Search::default();
|
let mut search = Search::default();
|
||||||
bench.iter(|| {
|
bench.iter(|| {
|
||||||
let _ = segmenter.segment("thisisatest", &mut search);
|
let _ = segmenter.segment("thisisatest", &mut search);
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,11 +9,10 @@ use super::{HashMap, Segmenter};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_data() {
|
fn test_data() {
|
||||||
crate::test_cases::run(&segmenter());
|
crate::test_cases::run(&segmenter(crate_data_dir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn segmenter() -> Segmenter {
|
pub fn segmenter(dir: PathBuf) -> Segmenter {
|
||||||
let dir = PathBuf::from(format!("{}/../data", env!("CARGO_MANIFEST_DIR")));
|
|
||||||
let mut ln = String::new();
|
let mut ln = String::new();
|
||||||
|
|
||||||
let uni_file = dir.join("en-unigrams.txt");
|
let uni_file = dir.join("en-unigrams.txt");
|
||||||
|
@ -59,3 +58,7 @@ pub fn segmenter() -> Segmenter {
|
||||||
|
|
||||||
Segmenter::from_maps(unigrams, bigrams)
|
Segmenter::from_maps(unigrams, bigrams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn crate_data_dir() -> PathBuf {
|
||||||
|
PathBuf::from(format!("{}/../data", env!("CARGO_MANIFEST_DIR")))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue