Решение на Сметки с ДНК от Димитър Михайлов

Обратно към всички решения

Към профила на Димитър Михайлов

Резултати

  • 17 точки от тестове
  • 0 бонус точки
  • 17 точки общо
  • 10 успешни тест(а)
  • 2 неуспешни тест(а)

Код

pub struct NucleotideCounter {
pub a: usize,
pub c: usize,
pub g: usize,
pub t: usize,
}
pub fn counts(dna: &[char]) -> NucleotideCounter {
let mut res = NucleotideCounter { a: 0, c: 0, g: 0, t: 0};
for c in dna {
match c {
'A' => res.a += 1,
'C' => res.c += 1,
'G' => res.g += 1,
'T' => res.t += 1,
_ => {panic!("Грешка, грешка, обърках вратата")}
}
}
return res;
}
pub fn dna_complement(dna: &[char]) -> Vec<char> {
let mut res = Vec::new();
for c in dna {
match c {
'A' => res.push('T'),
'T' => res.push('A'),
'G' => res.push('C'),
'C' => res.push('G'),
_ => {panic!("Грешка, грешка, обърках вратата")}
}
}
return res;
}
pub fn reverse_rna_complement(dna: &[char]) -> Vec<char> {
let mut res = Vec::new();
for c in dna {
match c {
'A' => res.push('U'),
'U' => res.push('A'),
'G' => res.push('C'),
'C' => res.push('G'),
_ => {panic!("Грешка, грешка, обърках вратата")}
}
}
res.reverse();
return res;
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20220112-2706256-1s08t8/solution)
    Finished test [unoptimized + debuginfo] target(s) in 5.79s
     Running tests/solution_test.rs (target/debug/deps/solution_test-4c880d3f0adaac34)

running 12 tests
test solution_test::test_counts_basic ... ok
test solution_test::test_counts_big ... ok
test solution_test::test_counts_panic1 - should panic ... ok
test solution_test::test_counts_panic2 - should panic ... ok
test solution_test::test_counts_zero ... ok
test solution_test::test_dna_complement_big ... ok
test solution_test::test_dna_complement_empty ... ok
test solution_test::test_dna_complement_panic - should panic ... ok
test solution_test::test_reverse_rna_complement_big ... FAILED
test solution_test::test_reverse_rna_complement_empty ... ok
test solution_test::test_reverse_rna_complement_panic1 - should panic ... ok
test solution_test::test_reverse_rna_complement_panic2 - should panic ... FAILED

failures:

---- solution_test::test_reverse_rna_complement_big stdout ----
thread 'main' panicked at 'Грешка, грешка, обърках вратата', src/lib.rs:46:19

---- solution_test::test_reverse_rna_complement_panic2 stdout ----
note: test did not panic as expected

failures:
    solution_test::test_reverse_rna_complement_big
    solution_test::test_reverse_rna_complement_panic2

test result: FAILED. 10 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--test solution_test'

История (1 версия и 1 коментар)

Димитър качи първо решение на 19.10.2021 18:35 (преди почти 4 години)

Добро, просто решение, отвъд проблема с валидацията на "U"/"T" :). Имай предвид, че не е нужно да обвиваш panic!(...) в къдрави скоби, _ => panic!("Грешка, грешка, обърках вратата") си работи just fine.