Skip to content

Commit

Permalink
rename error type; test specific error type
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Oct 11, 2024
1 parent a0b93eb commit 79e7b7d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum SourmashError {
Internal { message: String },

#[error("new scaled smaller than previous; cannot upsample")]
CannotUpsample,
CannotUpsampleScaled,

#[error("must have same num: {n1} != {n2}")]
MismatchNum { n1: u32, n2: u32 },
Expand Down Expand Up @@ -107,7 +107,7 @@ pub enum SourmashErrorCode {
NonEmptyMinHash = 1_06,
MismatchNum = 1_07,
NeedsAbundanceTracking = 1_08,
CannotUpsample = 1_09,
CannotUpsampleScaled = 1_09,
// Input sequence errors
InvalidDNA = 11_01,
InvalidProt = 11_02,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl SourmashErrorCode {
match error {
SourmashError::Internal { .. } => SourmashErrorCode::Internal,
SourmashError::Panic { .. } => SourmashErrorCode::Panic,
SourmashError::CannotUpsample { .. } => SourmashErrorCode::CannotUpsample,
SourmashError::CannotUpsampleScaled { .. } => SourmashErrorCode::CannotUpsampleScaled,
SourmashError::MismatchNum { .. } => SourmashErrorCode::MismatchNum,
SourmashError::NeedsAbundanceTracking { .. } => {
SourmashErrorCode::NeedsAbundanceTracking
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/sketch/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl KmerMinHash {

// create a downsampled copy of self
pub fn downsample_max_hash(self, max_hash: u64) -> Result<KmerMinHash, Error> {
if self.max_hash == 0 {
if self.max_hash == 0 { // does this make sense? @CTB
Ok(self)
} else {
let scaled = scaled_for_max_hash(max_hash);
Expand Down Expand Up @@ -777,7 +777,7 @@ impl KmerMinHash {
if self.scaled() == scaled || self.scaled() == 0 {
Ok(self)
} else if self.scaled() > scaled {
Err(Error::CannotUpsample)
Err(Error::CannotUpsampleScaled)
} else {
let mut new_mh = KmerMinHash::new(
scaled,
Expand Down Expand Up @@ -1554,7 +1554,7 @@ impl KmerMinHashBTree {
if self.scaled() == scaled || self.scaled() == 0 {
Ok(self)
} else if self.scaled() > scaled {
Err(Error::CannotUpsample)
Err(Error::CannotUpsampleScaled)
} else {
let mut new_mh = KmerMinHashBTree::new(
scaled,
Expand Down
3 changes: 2 additions & 1 deletion src/core/tests/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,5 +901,6 @@ fn test_scaled_downsampling() {
assert_eq!(new_mh.scaled(), 100);

// upsampling not ok
assert!(mh.clone().downsample_scaled(1).is_err());
let e = mh.clone().downsample_scaled(1).unwrap_err();
assert!(matches!(e, sourmash::Error::CannotUpsampleScaled));
}

0 comments on commit 79e7b7d

Please sign in to comment.