Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Nov 14, 2024
1 parent 97e7808 commit 2ce356d
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion src/core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::encodings::Idx;
use crate::manifest::{Manifest, Record};
use crate::prelude::*;
use crate::storage::{FSStorage, InnerStorage, MemStorage, SigStore, ZipStorage};
use crate::{Error, Result};
use crate::{Error, Result, ScaledType};

#[cfg(feature = "parallel")]
use rayon::prelude::*;
Expand Down Expand Up @@ -52,6 +52,11 @@ impl TryFrom<Collection> for CollectionSet {
return Ok(Self { collection });
};

let (min_scaled, max_scaled) = collection.min_max_scaled().expect("empty collection!?");
if min_scaled != max_scaled {
return Err(Error::MismatchScaled);
}

collection
.manifest
.iter()
Expand Down Expand Up @@ -219,6 +224,17 @@ impl Collection {
pub fn intersect_manifest(&mut self, mf: &Manifest) {
self.manifest = self.manifest.intersect_manifest(mf);
}

// CTB: question, should we do something about num here?
pub fn min_max_scaled(&self) -> Option<(&ScaledType, &ScaledType)> {
self.manifest.first().map(|first| {

Check warning on line 230 in src/core/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/collection.rs#L229-L230

Added lines #L229 - L230 were not covered by tests
self.manifest
.iter()
.fold((first.scaled(), first.scaled()), |f, r| {

Check warning on line 233 in src/core/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/collection.rs#L233

Added line #L233 was not covered by tests
(f.0.min(r.scaled()), f.1.max(r.scaled()))
})
})
}
}

impl Select for Collection {
Expand Down Expand Up @@ -483,6 +499,50 @@ mod test {
}
}

#[test]
fn collection_from_collectionset() -> () {
use crate::collection::CollectionSet;

let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let test_sigs = vec![PathBuf::from("../../tests/test-data/prot/all.zip")];

let full_paths: Vec<PathBuf> = test_sigs
.into_iter()
.map(|sig| base_path.join(sig))
.collect();

let collection = Collection::from_zipfile(&full_paths[0]).unwrap();

let mut selection = Selection::default();
selection.set_moltype(HashFunctions::Murmur64Protein);
selection.set_scaled(200);

let collection = collection.select(&selection).expect("should pass");
let (min_scaled, max_scaled) = collection.min_max_scaled().expect("not empty");
assert_eq!(*min_scaled, *max_scaled);
assert_eq!(*min_scaled, 200);
let _cs: CollectionSet = collection.try_into().expect("should pass");
}

#[test]
#[should_panic]
fn collection_from_collectionset_fail() -> () {
use crate::collection::CollectionSet;

let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let test_sigs = vec![PathBuf::from("../../tests/test-data/prot/all.zip")];

let full_paths: Vec<PathBuf> = test_sigs
.into_iter()
.map(|sig| base_path.join(sig))
.collect();

let collection = Collection::from_zipfile(&full_paths[0]).unwrap();
let _cs: CollectionSet = collection.try_into().expect("should fail");
}

#[test]
#[cfg(all(feature = "branchwater", not(target_arch = "wasm32")))]
fn collection_from_rocksdb_storage() -> Result<()> {
Expand Down

0 comments on commit 2ce356d

Please sign in to comment.