Add more tests

This commit is contained in:
Clément Renault 2023-06-27 15:42:17 +02:00
parent 9a13b72f25
commit b951830461
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -396,6 +396,8 @@ impl fmt::Debug for FacetDistribution<'_> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::iter;
use big_s::S; use big_s::S;
use maplit::hashset; use maplit::hashset;
@ -426,14 +428,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.execute() .execute()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2, "RED": 1}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2, "RED": 1}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates([0, 1, 2].iter().copied().collect()) .candidates([0, 1, 2].iter().copied().collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -441,7 +443,7 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2, "RED": 1}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2, "RED": 1}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates([1, 2].iter().copied().collect()) .candidates([1, 2].iter().copied().collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -452,7 +454,7 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {" blue": 1, "RED": 1}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {" blue": 1, "RED": 1}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates([2].iter().copied().collect()) .candidates([2].iter().copied().collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -460,13 +462,22 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"RED": 1}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"RED": 1}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates([0, 1, 2].iter().copied().collect()) .candidates([0, 1, 2].iter().copied().collect())
.max_values_per_facet(1) .max_values_per_facet(1)
.execute() .execute()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 1}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 1}}"###);
let map = FacetDistribution::new(&txn, &index)
.facets(iter::once(("colour", OrderBy::Count)))
.candidates([0, 1, 2].iter().copied().collect())
.max_values_per_facet(1)
.execute()
.unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2}}"###);
} }
#[test] #[test]
@ -498,14 +509,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.execute() .execute()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000, "Red": 6000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000, "Red": 6000}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.max_values_per_facet(1) .max_values_per_facet(1)
.execute() .execute()
.unwrap(); .unwrap();
@ -513,7 +524,7 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..10_000).collect()) .candidates((0..10_000).collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -521,7 +532,7 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000, "Red": 6000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 4000, "Red": 6000}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..5_000).collect()) .candidates((0..5_000).collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -529,7 +540,7 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000, "Red": 3000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000, "Red": 3000}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..5_000).collect()) .candidates((0..5_000).collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -537,13 +548,22 @@ mod tests {
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000, "Red": 3000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000, "Red": 3000}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..5_000).collect()) .candidates((0..5_000).collect())
.max_values_per_facet(1) .max_values_per_facet(1)
.execute() .execute()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000}}"###); milli_snap!(format!("{map:?}"), @r###"{"colour": {"Blue": 2000}}"###);
let map = FacetDistribution::new(&txn, &index)
.facets(iter::once(("colour", OrderBy::Count)))
.candidates((0..5_000).collect())
.max_values_per_facet(1)
.execute()
.unwrap();
milli_snap!(format!("{map:?}"), @r###"{"colour": {"Red": 3000}}"###);
} }
#[test] #[test]
@ -575,14 +595,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.execute() .execute()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), "no_candidates", @"ac9229ed5964d893af96a7076e2f8af5"); milli_snap!(format!("{map:?}"), "no_candidates", @"ac9229ed5964d893af96a7076e2f8af5");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.max_values_per_facet(2) .max_values_per_facet(2)
.execute() .execute()
.unwrap(); .unwrap();
@ -590,7 +610,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "no_candidates_with_max_2", @r###"{"colour": {"0": 10, "1": 10}}"###); milli_snap!(format!("{map:?}"), "no_candidates_with_max_2", @r###"{"colour": {"0": 10, "1": 10}}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..10_000).collect()) .candidates((0..10_000).collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -598,7 +618,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "candidates_0_10_000", @"ac9229ed5964d893af96a7076e2f8af5"); milli_snap!(format!("{map:?}"), "candidates_0_10_000", @"ac9229ed5964d893af96a7076e2f8af5");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..5_000).collect()) .candidates((0..5_000).collect())
.execute() .execute()
.unwrap(); .unwrap();
@ -635,14 +655,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), "no_candidates", @"{}"); milli_snap!(format!("{map:?}"), "no_candidates", @"{}");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..1000).collect()) .candidates((0..1000).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -650,7 +670,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 999.0)}"###); milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 999.0)}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((217..777).collect()) .candidates((217..777).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -687,14 +707,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), "no_candidates", @"{}"); milli_snap!(format!("{map:?}"), "no_candidates", @"{}");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..1000).collect()) .candidates((0..1000).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -702,7 +722,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 1999.0)}"###); milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 1999.0)}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((217..777).collect()) .candidates((217..777).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -739,14 +759,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), "no_candidates", @"{}"); milli_snap!(format!("{map:?}"), "no_candidates", @"{}");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..1000).collect()) .candidates((0..1000).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -754,7 +774,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 999.0)}"###); milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 999.0)}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((217..777).collect()) .candidates((217..777).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -795,14 +815,14 @@ mod tests {
let txn = index.read_txn().unwrap(); let txn = index.read_txn().unwrap();
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
milli_snap!(format!("{map:?}"), "no_candidates", @"{}"); milli_snap!(format!("{map:?}"), "no_candidates", @"{}");
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((0..1000).collect()) .candidates((0..1000).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();
@ -810,7 +830,7 @@ mod tests {
milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 1998.0)}"###); milli_snap!(format!("{map:?}"), "candidates_0_1000", @r###"{"colour": (0.0, 1998.0)}"###);
let map = FacetDistribution::new(&txn, &index) let map = FacetDistribution::new(&txn, &index)
.facets(std::iter::once(("colour", OrderBy::default()))) .facets(iter::once(("colour", OrderBy::default())))
.candidates((217..777).collect()) .candidates((217..777).collect())
.compute_stats() .compute_stats()
.unwrap(); .unwrap();