Skip to content

Commit

Permalink
Avoid unneeded allocations in tests (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it authored Feb 20, 2024
1 parent af77485 commit efbb9e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/bitkmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ mod tests {

#[test]
fn test_bitmer_to_bytes() {
assert_eq!(bitmer_to_bytes((1 as BitKmerSeq, 1)), b"C".to_vec());
assert_eq!(bitmer_to_bytes((60 as BitKmerSeq, 3)), b"TTA".to_vec());
assert_eq!(bitmer_to_bytes((0 as BitKmerSeq, 3)), b"AAA".to_vec());
assert_eq!(bitmer_to_bytes((1 as BitKmerSeq, 1)), b"C");
assert_eq!(bitmer_to_bytes((60 as BitKmerSeq, 3)), b"TTA");
assert_eq!(bitmer_to_bytes((0 as BitKmerSeq, 3)), b"AAA");
}

pub fn bytes_to_bitmer(kmer: &[u8]) -> BitKmer {
Expand Down
38 changes: 25 additions & 13 deletions src/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,32 @@ mod tests {

#[test]
fn test_normalize() {
assert_eq!(normalize(b"ACGTU", false), Some(b"ACGTT".to_vec()));
assert_eq!(normalize(b"acgtu", false), Some(b"ACGTT".to_vec()));
assert_eq!(
normalize(b"ACGTU", false).as_deref(),
Some(b"ACGTT".as_slice())
);
assert_eq!(
normalize(b"acgtu", false).as_deref(),
Some(b"ACGTT".as_slice())
);

assert_eq!(normalize(b"N.N-N~N N", false), Some(b"N-N-N-NN".to_vec()));
assert_eq!(
normalize(b"N.N-N~N N", false).as_deref(),
Some(b"N-N-N-NN".as_slice())
);

assert_eq!(normalize(b"BDHVRYSWKM", true), None);
assert_eq!(normalize(b"bdhvryswkm", true), Some(b"BDHVRYSWKM".to_vec()));
assert_eq!(
normalize(b"BDHVRYSWKM", false),
Some(b"NNNNNNNNNN".to_vec())
normalize(b"bdhvryswkm", true).as_deref(),
Some(b"BDHVRYSWKM".as_slice())
);
assert_eq!(
normalize(b"BDHVRYSWKM", false).as_deref(),
Some(b"NNNNNNNNNN".as_slice())
);
assert_eq!(
normalize(b"bdhvryswkm", false),
Some(b"NNNNNNNNNN".to_vec())
normalize(b"bdhvryswkm", false).as_deref(),
Some(b"NNNNNNNNNN".as_slice())
);
}

Expand All @@ -353,11 +365,11 @@ mod tests {

#[test]
fn can_canonicalize() {
assert_eq!(canonical(b"A"), Cow::Borrowed(b"A"));
assert_eq!(canonical(b"T"), Cow::Owned::<[u8]>(b"A".to_vec()));
assert_eq!(canonical(b"AAGT"), Cow::Borrowed(b"AAGT"));
assert_eq!(canonical(b"ACTT"), Cow::Owned::<[u8]>(b"AAGT".to_vec()));
assert_eq!(canonical(b"GC"), Cow::Borrowed(b"GC"));
assert_eq!(canonical(b"A").as_ref(), b"A");
assert_eq!(canonical(b"T").as_ref(), b"A");
assert_eq!(canonical(b"AAGT").as_ref(), b"AAGT");
assert_eq!(canonical(b"ACTT").as_ref(), b"AAGT");
assert_eq!(canonical(b"GC").as_ref(), b"GC");
}

#[test]
Expand Down

0 comments on commit efbb9e1

Please sign in to comment.