No longer need a macro for testing
This commit is contained in:
parent
912e6477e3
commit
f26793379b
|
@ -4,28 +4,19 @@ use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use word_segmenters::Segmenter;
|
use word_segmenters::Segmenter;
|
||||||
|
|
||||||
macro_rules! assert_segments {
|
|
||||||
($list:expr) => {
|
|
||||||
let mut out = Vec::new();
|
|
||||||
SEGMENTER.segment(&$list.join(""), &mut out);
|
|
||||||
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
|
|
||||||
assert_eq!(cmp, $list);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_0() {
|
fn test_segment_0() {
|
||||||
assert_segments!(&["choose", "spain"]);
|
assert_segments(&["choose", "spain"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_1() {
|
fn test_segment_1() {
|
||||||
assert_segments!(&["this", "is", "a", "test"]);
|
assert_segments(&["this", "is", "a", "test"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_2() {
|
fn test_segment_2() {
|
||||||
assert_segments!(&[
|
assert_segments(&[
|
||||||
"when",
|
"when",
|
||||||
"in",
|
"in",
|
||||||
"the",
|
"the",
|
||||||
|
@ -41,32 +32,32 @@ fn test_segment_2() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_3() {
|
fn test_segment_3() {
|
||||||
assert_segments!(&["who", "represents"]);
|
assert_segments(&["who", "represents"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_4() {
|
fn test_segment_4() {
|
||||||
assert_segments!(&["experts", "exchange"]);
|
assert_segments(&["experts", "exchange"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_5() {
|
fn test_segment_5() {
|
||||||
assert_segments!(&["speed", "of", "art"]);
|
assert_segments(&["speed", "of", "art"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_6() {
|
fn test_segment_6() {
|
||||||
assert_segments!(&["now", "is", "the", "time", "for", "all", "good"]);
|
assert_segments(&["now", "is", "the", "time", "for", "all", "good"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_7() {
|
fn test_segment_7() {
|
||||||
assert_segments!(&["it", "is", "a", "truth", "universally", "acknowledged"]);
|
assert_segments(&["it", "is", "a", "truth", "universally", "acknowledged"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_8() {
|
fn test_segment_8() {
|
||||||
assert_segments!(&[
|
assert_segments(&[
|
||||||
"it", "was", "a", "bright", "cold", "day", "in", "april", "and", "the", "clocks", "were",
|
"it", "was", "a", "bright", "cold", "day", "in", "april", "and", "the", "clocks", "were",
|
||||||
"striking", "thirteen",
|
"striking", "thirteen",
|
||||||
]);
|
]);
|
||||||
|
@ -74,7 +65,7 @@ fn test_segment_8() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_9() {
|
fn test_segment_9() {
|
||||||
assert_segments!(&[
|
assert_segments(&[
|
||||||
"it",
|
"it",
|
||||||
"was",
|
"was",
|
||||||
"the",
|
"the",
|
||||||
|
@ -104,7 +95,7 @@ fn test_segment_9() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_10() {
|
fn test_segment_10() {
|
||||||
assert_segments!(&[
|
assert_segments(&[
|
||||||
"as",
|
"as",
|
||||||
"gregor",
|
"gregor",
|
||||||
"samsa",
|
"samsa",
|
||||||
|
@ -130,18 +121,18 @@ fn test_segment_10() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_11() {
|
fn test_segment_11() {
|
||||||
assert_segments!(vec![
|
assert_segments(&[
|
||||||
"in", "a", "hole", "in", "the", "ground", "there", "lived", "a", "hobbit", "not", "a",
|
"in", "a", "hole", "in", "the", "ground", "there", "lived", "a", "hobbit", "not", "a",
|
||||||
"nasty", "dirty", "wet", "hole", "filled", "with", "the", "ends", "of", "worms", "and",
|
"nasty", "dirty", "wet", "hole", "filled", "with", "the", "ends", "of", "worms", "and",
|
||||||
"an", "oozy", "smell", "nor", "yet", "a", "dry", "bare", "sandy", "hole", "with",
|
"an", "oozy", "smell", "nor", "yet", "a", "dry", "bare", "sandy", "hole", "with",
|
||||||
"nothing", "in", "it", "to", "sit", "down", "on", "or", "to", "eat", "it", "was", "a",
|
"nothing", "in", "it", "to", "sit", "down", "on", "or", "to", "eat", "it", "was", "a",
|
||||||
"hobbit", "hole", "and", "that", "means", "comfort"
|
"hobbit", "hole", "and", "that", "means", "comfort",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_segment_12() {
|
fn test_segment_12() {
|
||||||
assert_segments!(&[
|
assert_segments(&[
|
||||||
"far",
|
"far",
|
||||||
"out",
|
"out",
|
||||||
"in",
|
"in",
|
||||||
|
@ -170,4 +161,11 @@ fn test_segment_12() {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn assert_segments(s: &[&str]) {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
SEGMENTER.segment(&s.join(""), &mut out);
|
||||||
|
let cmp = out.iter().map(|s| &*s).collect::<Vec<_>>();
|
||||||
|
assert_eq!(cmp, s);
|
||||||
|
}
|
||||||
|
|
||||||
static SEGMENTER: Lazy<Segmenter> = Lazy::new(word_segmenters::test_data::segmenter);
|
static SEGMENTER: Lazy<Segmenter> = Lazy::new(word_segmenters::test_data::segmenter);
|
||||||
|
|
Loading…
Reference in New Issue