From 6df8f62022910dc6c8f0bac035da7ebde00fd3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 20 May 2019 11:19:25 +0200 Subject: [PATCH] test: Add more test to some criteria --- meilidb-core/src/criterion/exact.rs | 22 +++++++++++++++++++ .../src/criterion/sum_of_words_attribute.rs | 22 +++++++++++++++++++ .../src/criterion/sum_of_words_position.rs | 22 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/meilidb-core/src/criterion/exact.rs b/meilidb-core/src/criterion/exact.rs index b038b9076..bde3ca733 100644 --- a/meilidb-core/src/criterion/exact.rs +++ b/meilidb-core/src/criterion/exact.rs @@ -41,3 +41,25 @@ impl Criterion for Exact { "Exact" } } + +#[cfg(test)] +mod tests { + use super::*; + + // typing: "soulier" + // + // doc0: "Soulier bleu" + // doc1: "souliereres rouge" + #[test] + fn easy_case() { + let query_index0 = &[0]; + let is_exact0 = &[true]; + + let query_index1 = &[0]; + let is_exact1 = &[false]; + + let doc0 = number_exact_matches(query_index0, is_exact0); + let doc1 = number_exact_matches(query_index1, is_exact1); + assert_eq!(doc0.cmp(&doc1).reverse(), Ordering::Less); + } +} diff --git a/meilidb-core/src/criterion/sum_of_words_attribute.rs b/meilidb-core/src/criterion/sum_of_words_attribute.rs index f5a3c3576..d5787ef3a 100644 --- a/meilidb-core/src/criterion/sum_of_words_attribute.rs +++ b/meilidb-core/src/criterion/sum_of_words_attribute.rs @@ -40,3 +40,25 @@ impl Criterion for SumOfWordsAttribute { "SumOfWordsAttribute" } } + +#[cfg(test)] +mod tests { + use super::*; + + // typing: "soulier" + // + // doc0: { 0. "Soulier bleu", 1. "bla bla bla" } + // doc1: { 0. "Botte rouge", 1. "Soulier en cuir" } + #[test] + fn title_vs_description() { + let query_index0 = &[0]; + let attribute0 = &[0]; + + let query_index1 = &[0]; + let attribute1 = &[1]; + + let doc0 = sum_matches_attributes(query_index0, attribute0); + let doc1 = sum_matches_attributes(query_index1, attribute1); + assert_eq!(doc0.cmp(&doc1), Ordering::Less); + } +} diff --git a/meilidb-core/src/criterion/sum_of_words_position.rs b/meilidb-core/src/criterion/sum_of_words_position.rs index e365aef3b..13f26774c 100644 --- a/meilidb-core/src/criterion/sum_of_words_position.rs +++ b/meilidb-core/src/criterion/sum_of_words_position.rs @@ -40,3 +40,25 @@ impl Criterion for SumOfWordsPosition { "SumOfWordsPosition" } } + +#[cfg(test)] +mod tests { + use super::*; + + // typing: "soulier" + // + // doc0: "Soulier bleu" + // doc1: "Botte rouge et soulier noir" + #[test] + fn easy_case() { + let query_index0 = &[0]; + let word_index0 = &[0]; + + let query_index1 = &[0]; + let word_index1 = &[3]; + + let doc0 = sum_matches_attribute_index(query_index0, word_index0); + let doc1 = sum_matches_attribute_index(query_index1, word_index1); + assert_eq!(doc0.cmp(&doc1), Ordering::Less); + } +}