use super::*;
fn no_media(len: usize) -> Vec<Option<u64>> {
vec![None; len]
}
fn not_superseded(len: usize) -> Vec<bool> {
vec![false; len]
}
#[test]
fn test_find_duplicates_exact_marks_second_occurrence() {
let verdicts = find_duplicates(
&["a fact", "other", "a fact"],
true,
&no_media(3),
¬_superseded(3),
);
assert!(verdicts[0].is_none());
assert!(verdicts[1].is_none());
let dup = verdicts[2].expect("third entry duplicates the first");
assert_eq!(dup.kind, DupKind::Exact);
assert_eq!(dup.kept_seq, 0);
}
#[test]
fn test_find_duplicates_near_matches_case_and_spacing() {
let verdicts = find_duplicates(
&["The Server restarts.", "the server restarts."],
true,
&no_media(2),
¬_superseded(2),
);
let dup = verdicts[1].expect("second entry near-duplicates the first");
assert_eq!(dup.kind, DupKind::Near);
assert_eq!(dup.kept_seq, 0);
}
#[test]
fn test_find_duplicates_near_detection_can_be_disabled() {
let verdicts = find_duplicates(
&["The Server restarts.", "the server restarts."],
false,
&no_media(2),
¬_superseded(2),
);
assert!(verdicts[1].is_none(), "near detection was disabled");
}
#[test]
fn test_find_duplicates_exact_still_found_when_near_disabled() {
let verdicts = find_duplicates(&["same", "same"], false, &no_media(2), ¬_superseded(2));
assert_eq!(verdicts[1].expect("exact duplicate").kind, DupKind::Exact);
}
#[test]
fn test_find_duplicates_distinct_contents_are_all_kept() {
let verdicts = find_duplicates(
&["alpha", "beta", "gamma"],
true,
&no_media(3),
¬_superseded(3),
);
assert!(verdicts.iter().all(Option::is_none));
}
#[test]
fn test_find_duplicates_exact_copy_of_a_near_duplicate_reports_exact() {
let verdicts = find_duplicates(
&["Hello World", "hello world", "hello world"],
true,
&no_media(3),
¬_superseded(3),
);
let dup = verdicts[2].expect("third entry duplicates the second");
assert_eq!(
dup.kind,
DupKind::Exact,
"a byte-identical copy must be recorded as an exact duplicate"
);
assert_eq!(
dup.kept_seq, 1,
"the byte-identical twin is #1, not the near-duplicate root #0"
);
}
#[test]
fn test_find_duplicates_near_dup_still_anchors_the_near_chain_at_the_root() {
let verdicts = find_duplicates(
&["Hello World", "hello world", "hello world", "HELLO WORLD"],
true,
&no_media(4),
¬_superseded(4),
);
assert_eq!(verdicts[3].expect("near dup").kept_seq, 0);
}
#[test]
fn test_find_duplicates_chain_points_to_first_occurrence() {
let verdicts = find_duplicates(&["x", "x", "x"], true, &no_media(3), ¬_superseded(3));
assert_eq!(verdicts[1].expect("dup").kept_seq, 0);
assert_eq!(verdicts[2].expect("dup").kept_seq, 0);
}
#[test]
fn test_find_duplicates_media_with_identical_raw_hash_is_exact_duplicate() {
let media = vec![Some(42_u64), Some(42_u64)];
let verdicts = find_duplicates(&["", ""], true, &media, ¬_superseded(2));
let dup = verdicts[1].expect("same raw hash duplicates the first");
assert_eq!(dup.kind, DupKind::Exact);
assert_eq!(dup.kept_seq, 0);
}
#[test]
fn test_find_duplicates_media_with_different_raw_hash_is_not_a_duplicate() {
let media = vec![Some(1_u64), Some(2_u64)];
let verdicts = find_duplicates(
&["same caption", "same caption"],
true,
&media,
¬_superseded(2),
);
assert!(
verdicts[1].is_none(),
"different images must never dedup on caption text alone"
);
}
#[test]
fn test_find_duplicates_media_fragments_with_blank_captions_never_false_positive_dedup() {
let media = vec![Some(111_u64), Some(222_u64)];
let verdicts = find_duplicates(&["", ""], true, &media, ¬_superseded(2));
assert!(verdicts[1].is_none());
}
#[test]
fn test_find_duplicates_media_never_marked_near_duplicate() {
let media = vec![Some(7_u64), Some(7_u64)];
let verdicts = find_duplicates(
&["Hello World", "hello world"],
true,
&media,
¬_superseded(2),
);
assert_eq!(verdicts[1].expect("dup").kind, DupKind::Exact);
}
#[test]
fn test_find_duplicates_media_fragment_does_not_pollute_text_dedup_of_others() {
let media = vec![Some(999_u64), None];
let verdicts = find_duplicates(&["", ""], true, &media, ¬_superseded(2));
assert!(
verdicts[1].is_none(),
"a plain-text empty fragment must not dedup against a media fragment's blank caption"
);
}
#[test]
fn test_find_duplicates_media_and_text_dedup_use_independent_namespaces() {
let media = vec![None, Some(1_u64)];
let verdicts = find_duplicates(&["shared", "shared"], true, &media, ¬_superseded(2));
assert!(verdicts[1].is_none());
}
#[test]
fn test_find_duplicates_media_chain_points_to_first_occurrence() {
let media = vec![Some(5_u64), Some(5_u64), Some(5_u64)];
let verdicts = find_duplicates(&["", "", ""], true, &media, ¬_superseded(3));
assert_eq!(verdicts[1].expect("dup").kept_seq, 0);
assert_eq!(verdicts[2].expect("dup").kept_seq, 0);
}